Skip to content

Commit

Permalink
feat: add instance log for latency calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss authored and cgrinds committed Apr 1, 2024
1 parent c09e1a1 commit f2ce095
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/matrix/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,13 @@ func (m *Matrix) Delta(metricKey string, prevMat *Matrix, logger *logging.Logger
if ppaOk || cpaOk {
curMetric.record[currIndex] = false
skips++
labels := currInstance.GetLabels()
logger.Debug().
Str("metric", curMetric.GetName()).
Float64("currentRaw", curRaw).
Float64("previousRaw", prevRaw[prevIndex]).
Bool("prevPartial", ppaOk).
Bool("curPartial", cpaOk).
Interface("instanceLabels", labels).
Interface("instanceLabels", currInstance.GetLabels()).
Str("instKey", key).
Msg("Partial Aggregation")
}
Expand All @@ -392,6 +391,7 @@ func (m *Matrix) Delta(metricKey string, prevMat *Matrix, logger *logging.Logger
Str("metric", curMetric.GetName()).
Float64("currentRaw", curRaw).
Float64("previousRaw", prevRaw[prevIndex]).
Interface("instanceLabels", currInstance.GetLabels()).
Str("instKey", key).
Msg("Delta calculation skipped")
}
Expand All @@ -401,6 +401,7 @@ func (m *Matrix) Delta(metricKey string, prevMat *Matrix, logger *logging.Logger
logger.Trace().
Str("metric", curMetric.GetName()).
Float64("currentRaw", curRaw).
Interface("instanceLabels", currInstance.GetLabels()).
Str("instKey", key).
Msg("New instance added")
}
Expand All @@ -417,7 +418,8 @@ func (m *Matrix) Divide(metricKey string, baseKey string, logger *logging.Logger
if len(metric.values) != len(sValues) {
return 0, errs.New(ErrUnequalVectors, fmt.Sprintf("numerator=%d, denominator=%d", len(metric.values), len(sValues)))
}
for i := range len(metric.values) {
for key, instance := range m.GetInstances() {
i := instance.index
if metric.record[i] && sRecord[i] {
if sValues[i] != 0 {
// Don't pass along the value if the numerator or denominator is < 0
Expand All @@ -430,6 +432,8 @@ func (m *Matrix) Divide(metricKey string, baseKey string, logger *logging.Logger
Str("key", metricKey).
Float64("numerator", metric.values[i]).
Float64("denominator", sValues[i]).
Interface("instanceLabels", instance.GetLabels()).
Str("instKey", key).
Msg("Divide calculation skipped")
}
metric.values[i] /= sValues[i]
Expand All @@ -444,6 +448,8 @@ func (m *Matrix) Divide(metricKey string, baseKey string, logger *logging.Logger
Str("key", metricKey).
Float64("numerator", metric.values[i]).
Float64("denominator", sValues[i]).
Interface("instanceLabels", instance.GetLabels()).
Str("instKey", key).
Msg("Divide calculation skipped")
}
}
Expand All @@ -470,7 +476,8 @@ func (m *Matrix) DivideWithThreshold(metricKey string, baseKey string, threshold
if len(metric.values) != len(sValues) || len(sValues) != len(tValues) {
return 0, errs.New(ErrUnequalVectors, fmt.Sprintf("numerator=%d, denominator=%d, time=%d", len(metric.values), len(sValues), len(tValues)))
}
for i := range len(metric.values) {
for key, instance := range m.GetInstances() {
i := instance.index
v := metric.values[i]
// Don't pass along the value if the numerator or denominator is < 0
// It is important to check sValues[i] < 0 and allow a zero so pass=true and m.values[i] remains unchanged
Expand All @@ -482,6 +489,8 @@ func (m *Matrix) DivideWithThreshold(metricKey string, baseKey string, threshold
Str("key", metricKey).
Float64("numerator", v).
Float64("denominator", sValues[i]).
Interface("instanceLabels", instance.GetLabels()).
Str("instKey", key).
Msg("Negative values")
} else if metric.record[i] && sRecord[i] {
// For a latency counter, ensure that the base counter has sufficient operations for accurate calculation.
Expand All @@ -505,6 +514,8 @@ func (m *Matrix) DivideWithThreshold(metricKey string, baseKey string, threshold
Float64("current_raw_latency", curRawMetric.values[i]).
Float64("prev_raw_base", prevBaseRawMetric.values[i]).
Float64("current_raw_base", curBaseRawMetric.values[i]).
Interface("instanceLabels", instance.GetLabels()).
Str("instKey", key).
Msg("Detected high latency value in the metric")
}
}
Expand All @@ -519,6 +530,8 @@ func (m *Matrix) DivideWithThreshold(metricKey string, baseKey string, threshold
Str("key", metricKey).
Float64("numerator", metric.values[i]).
Float64("denominator", sValues[i]).
Interface("instanceLabels", instance.GetLabels()).
Str("instKey", key).
Msg("Divide threshold calculation skipped")
}
}
Expand Down

0 comments on commit f2ce095

Please sign in to comment.