Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(summary): summary "sum" metric must also be sent as delta #101

Merged
merged 3 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions internal/integration/telemetry_sdk_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,17 @@ func (te *TelemetryEmitter) emitSummary(metric Metric, timestamp time.Time) erro
return fmt.Errorf("unknown summary metric type for %q: %T", metric.name, metric.value)
}

te.harvester.RecordMetric(telemetry.Summary{
Name: metric.name + "_sum",
Attributes: metric.attributes,
Count: 1,
Sum: summary.GetSampleSum(),
Min: math.NaN(),
Max: math.NaN(),
Timestamp: timestamp,
})
if sumCount, ok := te.deltaCalculator.CountMetric(metric.name+"_sum", metric.attributes, float64(summary.GetSampleSum()), timestamp); ok {
te.harvester.RecordMetric(telemetry.Summary{
Name: metric.name + "_sum",
Attributes: metric.attributes,
Count: 1,
Sum: sumCount.Value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would thought that this value already come in the original prometheus metric and we just need it to send it as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In prometheus it comes as a counter and so in order for us to be able to calculate the average (_sum/_count) we also need to send it as a delta, like we do for the _count

Min: math.NaN(),
Max: math.NaN(),
Timestamp: timestamp,
})
}

if count, ok := te.deltaCalculator.CountMetric(metric.name+"_count", metric.attributes, float64(summary.GetSampleCount()), timestamp); ok {
te.harvester.RecordMetric(count)
Expand Down
11 changes: 9 additions & 2 deletions internal/integration/telemetry_sdk_emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ func TestTelemetryEmitterEmit(t *testing.T) {
assert.NoError(t, e.Emit(metrics))
e.harvester.HarvestNow(context.Background())

// Set new summary values so counts will be non-zero.
summary2, err := newSummary(4, 15, []*quantile{{0.5, 10}, {0.999, 100}})
if err != nil {
t.Fatal(err)
}
*summary = *summary2

// Set new histogram values so counts will be non-zero.
hist2, err := newHistogram([]int64{1, 2, 10})
if err != nil {
Expand Down Expand Up @@ -306,7 +313,7 @@ func TestTelemetryEmitterEmit(t *testing.T) {
"name": "summary-1_sum",
"type": "summary",
"value": map[string]interface{}{
"sum": float64(10),
"sum": float64(5),
"count": float64(1),
"min": nil,
"max": nil,
Expand All @@ -316,7 +323,7 @@ func TestTelemetryEmitterEmit(t *testing.T) {
"attributes": map[string]interface{}{},
"name": "summary-1_count",
"type": "count",
"value": float64(0),
"value": float64(1),
},
map[string]interface{}{
"attributes": map[string]interface{}{
Expand Down