Skip to content

Commit ee48e7e

Browse files
committed
migrate from explicit buckets to "native" exponential histograms
1 parent a513bc3 commit ee48e7e

File tree

10 files changed

+49
-68
lines changed

10 files changed

+49
-68
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ jobs:
6464
env:
6565
OTEL_EXPORTER_OTLP_PROTOCOL: 'http/protobuf'
6666
ACTIONS_STEP_DEBUG: 'true'
67+
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION: 'base2_exponential_bucket_histogram'

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 9 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__snapshots__/metrics-submitter.test.ts.snap

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,39 @@ exports[`MetricsSubmitter should configures histogram with explicit buckets 1`]
3131
"value": {
3232
"buckets": {
3333
"boundaries": [
34-
0.1,
35-
0.5,
36-
1,
34+
0,
3735
5,
3836
10,
37+
25,
38+
50,
39+
75,
40+
100,
41+
250,
42+
500,
43+
750,
44+
1000,
45+
2500,
46+
5000,
47+
7500,
48+
10000,
3949
],
4050
"counts": [
41-
0,
4251
0,
4352
1,
4453
0,
4554
0,
4655
0,
56+
0,
57+
0,
58+
0,
59+
0,
60+
0,
61+
0,
62+
0,
63+
0,
64+
0,
65+
0,
66+
0,
4767
],
4868
},
4969
"count": 1,
@@ -54,15 +74,7 @@ exports[`MetricsSubmitter should configures histogram with explicit buckets 1`]
5474
},
5575
],
5676
"descriptor": {
57-
"advice": {
58-
"explicitBucketBoundaries": [
59-
0.1,
60-
0.5,
61-
1,
62-
5,
63-
10,
64-
],
65-
},
77+
"advice": {},
6678
"description": "Test metric",
6779
"name": "test-namespace.v1.test.duration",
6880
"type": "HISTOGRAM",

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
ATTR_SERVICE_NAMESPACE
2020
} from '@opentelemetry/semantic-conventions/incubating'
2121

22-
const DEFAULT_EXPORT_INTERVAL_MS = 1000
22+
const DEFAULT_EXPORT_INTERVAL_MS = 15000
2323
const DEFAULT_TIMEOUT_MS = 30000
2424
import {
2525
DiagConsoleLogger,
@@ -94,7 +94,7 @@ export async function run(): Promise<void> {
9494

9595
const metricsNamespace = core.getInput('metrics-namespace') || 'cae'
9696

97-
const metricsVersion = core.getInput('metrics-version') || 'v1'
97+
const metricsVersion = core.getInput('metrics-version') || 'v2'
9898

9999
const config: TMetricsConfig = {
100100
serviceName,

src/metrics-generator.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,8 @@ describe('generateMetrics', () => {
124124
(m) => m.metricName === 'test.suite.duration'
125125
)
126126

127-
expect(testDuration?.buckets).toEqual([
128-
0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30, 100
129-
])
130-
expect(suiteDuration?.buckets).toEqual([
131-
0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30, 100
132-
])
127+
expect(testDuration).toBeDefined()
128+
expect(suiteDuration).toBeDefined()
133129
})
134130

135131
it('generates metrics for all test statuses', () => {

src/metrics-generator.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export interface TMetricDataPoint {
1818
readonly attributes: Readonly<Record<string, string>>
1919
readonly description: string
2020
readonly unit: string | undefined
21-
readonly buckets: readonly number[] | undefined
2221
}
2322

2423
export const generateMetrics = (
@@ -53,8 +52,7 @@ const generateSuiteMetrics = (
5352
value: suite.totals.time,
5453
attributes: suiteAttributes,
5554
description: 'Test suite execution time (from XML time attribute)',
56-
unit: 's',
57-
buckets: [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30, 100]
55+
unit: 's'
5856
})
5957

6058
metrics.push({
@@ -63,8 +61,7 @@ const generateSuiteMetrics = (
6361
value: suite.totals.cumulativeTime,
6462
attributes: suiteAttributes,
6563
description: 'Test suite cumulative time (calculated from child elements)',
66-
unit: 's',
67-
buckets: [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30, 100]
64+
unit: 's'
6865
})
6966

7067
const statusCounts = [
@@ -85,8 +82,7 @@ const generateSuiteMetrics = (
8582
'test.status': status
8683
},
8784
description: 'Current test count per suite by status',
88-
unit: '{test}',
89-
buckets: undefined
85+
unit: '{test}'
9086
})
9187
}
9288
}
@@ -123,8 +119,7 @@ const generateTestCaseMetrics = (
123119
value: testCase.time,
124120
attributes: testAttributes,
125121
description: 'Individual test execution time',
126-
unit: 's',
127-
buckets: [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30, 100]
122+
unit: 's'
128123
})
129124

130125
metrics.push({
@@ -133,8 +128,7 @@ const generateTestCaseMetrics = (
133128
value: 1,
134129
attributes: testAttributes,
135130
description: 'Test execution count by status',
136-
unit: '{test}',
137-
buckets: undefined
131+
unit: '{test}'
138132
})
139133

140134
switch (testCase.result.status) {
@@ -149,8 +143,7 @@ const generateTestCaseMetrics = (
149143
'failure.type': testCase.result.type
150144
},
151145
description: 'Test failures by type',
152-
unit: '{failure}',
153-
buckets: undefined
146+
unit: '{failure}'
154147
})
155148
}
156149
break
@@ -166,8 +159,7 @@ const generateTestCaseMetrics = (
166159
'error.type': testCase.result.type
167160
},
168161
description: 'Test errors by type',
169-
unit: '{error}',
170-
buckets: undefined
162+
unit: '{error}'
171163
})
172164
}
173165
break

src/metrics-submitter.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ describe('MetricsSubmitter', () => {
9494
attributes: { 'test.name': 'example' },
9595
description: 'Test metric',
9696
unit: '{test}',
97-
buckets: undefined,
9897
...overrides
9998
})
10099

@@ -150,8 +149,7 @@ describe('MetricsSubmitter', () => {
150149
metrics: [
151150
createDataPoint({
152151
metricName: 'test.duration',
153-
metricType: 'histogram',
154-
buckets: [0.1, 0.5, 1, 5, 10]
152+
metricType: 'histogram'
155153
})
156154
]
157155
},

src/metrics-submitter.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ export class MetricsSubmitter {
7272
unit: dataPoint.unit
7373
}
7474

75-
if (dataPoint.buckets) {
76-
options.advice = {
77-
explicitBucketBoundaries: dataPoint.buckets.concat()
78-
}
79-
}
80-
8175
return options
8276
}
8377

0 commit comments

Comments
 (0)