Skip to content

Commit

Permalink
[processor/servicegraph] Fixes the number of bucket counts (open-tele…
Browse files Browse the repository at this point in the history
…metry#16025)

* Fixes the number of explicit bucket counts.

Signed-off-by: Jared Tan <[email protected]>

* add changelog

Signed-off-by: Jared Tan <[email protected]>

* fix UT.

Signed-off-by: Jared Tan <[email protected]>

* add UT

Signed-off-by: Jared Tan <[email protected]>

* polish

Signed-off-by: Jared Tan <[email protected]>

* fix ut

Signed-off-by: Jared Tan <[email protected]>

Signed-off-by: Jared Tan <[email protected]>
  • Loading branch information
JaredTan95 authored and shalper2 committed Dec 6, 2022
1 parent 849cd38 commit de0d7dd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .chloggen/unreleased/fixes_the_number_of_bucket_counts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: servicegraphprocessor

# A brief description of the change
note: Fixes the number of bucket counts.

# One or more tracking issues related to the change
issues: [16000]
2 changes: 1 addition & 1 deletion processor/servicegraphprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (p *processor) updateErrorMetrics(key string) { p.reqFailedTotal[key]++ }
func (p *processor) updateDurationMetrics(key string, duration float64) {
index := sort.SearchFloat64s(p.reqDurationBounds, duration) // Search bucket index
if _, ok := p.reqDurationSecondsBucketCounts[key]; !ok {
p.reqDurationSecondsBucketCounts[key] = make([]uint64, len(p.reqDurationBounds))
p.reqDurationSecondsBucketCounts[key] = make([]uint64, len(p.reqDurationBounds)+1)
}
p.reqDurationSecondsSum[key] += duration
p.reqDurationSecondsCount[key]++
Expand Down
40 changes: 40 additions & 0 deletions processor/servicegraphprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,43 @@ func (m *mockMetricsExporter) Capabilities() consumer.Capabilities { return cons
func (m *mockMetricsExporter) ConsumeMetrics(_ context.Context, md pmetric.Metrics) error {
return m.verify(md)
}

func TestUpdateDurationMetrics(t *testing.T) {
p := processor{
reqTotal: make(map[string]int64),
reqFailedTotal: make(map[string]int64),
reqDurationSecondsSum: make(map[string]float64),
reqDurationSecondsCount: make(map[string]uint64),
reqDurationBounds: defaultLatencyHistogramBucketsMs,
reqDurationSecondsBucketCounts: make(map[string][]uint64),
keyToMetric: make(map[string]metricSeries),
config: &Config{
Dimensions: []string{},
},
}
metricKey := p.buildMetricKey("foo", "bar", "", map[string]string{})

testCases := []struct {
caseStr string
duration float64
}{

{
caseStr: "index 0 latency",
duration: 0,
},
{
caseStr: "out-of-range latency 1",
duration: 25_000,
},
{
caseStr: "out-of-range latency 2",
duration: 125_000,
},
}
for _, tc := range testCases {
t.Run(tc.caseStr, func(t *testing.T) {
p.updateDurationMetrics(metricKey, tc.duration)
})
}
}

0 comments on commit de0d7dd

Please sign in to comment.