Skip to content

Commit 6ba4b80

Browse files
committed
Fix classic histogram definition
1 parent 4eceaf3 commit 6ba4b80

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed

test/histograms/histograms_to_cw_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,49 +151,49 @@ func (t *OtlpHistogramTestRunner) validateHistogramMetric(metricName string) []s
151151
},
152152
{
153153
stat: types.StatisticMaximum,
154-
value: 2,
154+
value: 4,
155155
},
156156
{
157157
stat: types.StatisticSum,
158-
value: 24,
158+
value: 36,
159159
},
160160
{
161161
stat: types.StatisticAverage,
162-
value: 2,
162+
value: 1.5,
163163
},
164164
{
165165
stat: types.StatisticSampleCount,
166-
value: 12,
166+
value: 24,
167167
},
168168
{
169169
stat: "p90",
170-
value: 2.0,
170+
value: 3.9,
171171
},
172172
},
173173
"my.cumulative.histogram": {
174174
{
175175
stat: types.StatisticMinimum,
176-
value: 0,
176+
value: 0.5,
177177
},
178178
{
179179
stat: types.StatisticMaximum,
180180
value: 2,
181181
},
182182
{
183183
stat: types.StatisticSum,
184-
value: 24,
184+
value: 12,
185185
},
186186
{
187187
stat: types.StatisticAverage,
188-
value: 2,
188+
value: 1,
189189
},
190190
{
191191
stat: types.StatisticSampleCount,
192192
value: 12,
193193
},
194194
{
195195
stat: "p90",
196-
value: 2.0,
196+
value: 1.3,
197197
},
198198
},
199199
"my.delta.exponential.histogram": {

test/histograms/histograms_to_emf_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ func TestOTLPMetrics(t *testing.T) {
6464
},
6565
{
6666
stat: types.StatisticMaximum,
67-
value: 2,
67+
value: 4,
6868
},
6969
{
7070
stat: types.StatisticSum,
71-
value: 12, // we send Sum=2 six times in one minute
71+
value: 36, // we send Sum=2 six times in one minute
7272
},
7373
{
7474
stat: types.StatisticAverage,
@@ -110,7 +110,7 @@ func TestOTLPMetrics(t *testing.T) {
110110
},
111111
{
112112
stat: types.StatisticSum,
113-
value: 12, // we send Sum=2 six times in one minute
113+
value: 36, // we send Sum=2 six times in one minute
114114
},
115115
{
116116
stat: types.StatisticAverage,
@@ -216,12 +216,12 @@ func TestOTLPMetrics(t *testing.T) {
216216
for _, e := range m.expected {
217217
values, err := fetcher.Fetch(namespace, m.name, m.dimensions, e.stat, metric.MinuteStatPeriod)
218218
require.NoError(t, err)
219-
require.GreaterOrEqual(t, len(values), 3, "Not enough metrics retrieved for namespace {%s} metric Name {%s} stat {%s}", namespace, m.name, e.stat)
219+
assert.GreaterOrEqual(t, len(values), 3, "Not enough metrics retrieved for namespace {%s} metric Name {%s} stat {%s}", namespace, m.name, e.stat)
220220

221221
// omit first/last metric as the 1m collection intervals may be missing data points from when the agent was started/stopped
222222
middleValues := values[1 : len(values)-1]
223223
err = metric.IsAllValuesGreaterThanOrEqualToExpectedValueWithError(m.name, middleValues, e.value)
224-
require.NoError(t, err)
224+
assert.NoError(t, err)
225225
}
226226
})
227227
}

test/histograms/resources/otlp_emf_metrics.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
{
3737
"startTimeUnixNano": METRIC_TIME,
3838
"timeUnixNano": METRIC_TIME,
39-
"count": 2,
40-
"sum": 2,
41-
"bucketCounts": [0,2],
42-
"explicitBounds": [1,2],
39+
"count": 4,
40+
"sum": 6,
41+
"bucketCounts": [1,2,1],
42+
"explicitBounds": [0.5,2],
4343
"min": 0,
44-
"max": 2,
44+
"max": 4,
4545
"attributes": [
4646
{
4747
"key": "my.delta.histogram.attr",
@@ -72,10 +72,10 @@
7272
"timeUnixNano": METRIC_TIME,
7373
"count": CUMULATIVE_HIST_COUNT,
7474
"sum": CUMULATIVE_HIST_SUM,
75-
"bucketCounts": [0,CUMULATIVE_HIST_COUNT],
76-
"explicitBounds": [1, 2],
75+
"bucketCounts": [1,CUMULATIVE_HIST_COUNT,1],
76+
"explicitBounds": [0.5,2],
7777
"min": 0,
78-
"max": 2,
78+
"max": 4,
7979
"attributes": [
8080
{
8181
"key": "my.cumulative.histogram.attr",

test/histograms/resources/otlp_emf_pusher.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ fi
77
echo "Starting with INSTANCE_ID: $INSTANCE_ID"
88

99
INITIAL_METRIC_TIME=$(date +%s%N)
10-
COUNT=0
10+
COUNT=2
1111

1212
# Initialize the file
1313
cat ./resources/otlp_emf_metrics.json | sed -e "s/INITIAL_METRIC_TIME/$INITIAL_METRIC_TIME/" \
1414
-e "s/\$INSTANCE_ID/$INSTANCE_ID/g" > ./resources/otlp_emf_metrics_initial.json
1515

1616
while true; do
1717
METRIC_TIME=$(date +%s%N)
18+
19+
# Simulating a histogram with datapoints 0 and 4, and then adding 2 counts of value 1 for each iteration
1820
COUNT=$((COUNT + 2))
19-
SUM=$((COUNT))
21+
SUM=$((COUNT+4))
2022

2123
cat ./resources/otlp_emf_metrics_initial.json | \
2224
sed -e "s/METRIC_TIME/$METRIC_TIME/" \

test/histograms/resources/otlp_metrics.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@
105105
{
106106
"startTimeUnixNano": INITIAL_METRIC_TIME,
107107
"timeUnixNano": METRIC_TIME,
108-
"count": 2,
109-
"sum": 2,
110-
"bucketCounts": [0,2],
111-
"explicitBounds": [1,2],
108+
"count": 4,
109+
"sum": 6,
110+
"bucketCounts": [1,2,1],
111+
"explicitBounds": [0.5,2],
112112
"min": 0,
113-
"max": 2,
113+
"max": 4,
114114
"attributes": [
115115
{
116116
"key": "my.delta.histogram.attr",
@@ -135,10 +135,10 @@
135135
"timeUnixNano": METRIC_TIME,
136136
"count": CUMULATIVE_HIST_COUNT,
137137
"sum": CUMULATIVE_HIST_SUM,
138-
"bucketCounts": [0,CUMULATIVE_HIST_COUNT],
139-
"explicitBounds": [1, 2],
138+
"bucketCounts": [1,CUMULATIVE_HIST_COUNT,1],
139+
"explicitBounds": [0.5,2],
140140
"min": 0,
141-
"max": 2,
141+
"max": 3,
142142
"attributes": [
143143
{
144144
"key": "my.cumulative.histogram.attr",

test/histograms/resources/otlp_pusher.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
INITIAL_METRIC_TIME=$(date +%s%N)
2-
COUNT=0
2+
COUNT=2
33

44
# Initialize the file
55
cat ./resources/otlp_metrics.json | sed -e "s/INITIAL_METRIC_TIME/$INITIAL_METRIC_TIME/" > ./resources/otlp_metrics_initial.json;
66

77
while true; do
88
METRIC_TIME=$(date +%s%N)
9-
COUNT=$((COUNT + 2)) # Increment count by 2 each iteration
10-
SUM=$((COUNT))
9+
10+
# Simulating a histogram with datapoints 0 and 3, and then adding 2 counts of value 1 for each iteration
11+
COUNT=$((COUNT + 2))
12+
SUM=$((COUNT+4))
1113

1214
cat ./resources/otlp_metrics_initial.json | sed -e "s/METRIC_TIME/$METRIC_TIME/" > otlp_metrics.json;
1315
sed -i -e "s/CUMULATIVE_HIST_COUNT/$COUNT/" otlp_metrics.json;

0 commit comments

Comments
 (0)