Skip to content

Commit efc87f3

Browse files
author
Tristan Sloughter
authored
Merge pull request #614 from albertored/fix-histo-buckets
Histogram buckets should be 1 more than boundaries
2 parents 3581046 + 04effcc commit efc87f3

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- [Add `instrument_unit` to view criteria](https://github.com/open-telemetry/opentelemetry-erlang/pull/604)
2626
- [Validate instrument name](https://github.com/open-telemetry/opentelemetry-erlang/pull/604)
2727

28+
### Changes
29+
30+
- [Align histogram default boundaries with specification](https://github.com/open-telemetry/opentelemetry-erlang/pull/614)
31+
32+
### Fixes
33+
34+
- [Correctly record histogram values greater than last boundary](https://github.com/open-telemetry/opentelemetry-erlang/pull/614)
35+
2836
## SDK 1.3.1 - 2023-08-15
2937

3038
### Added

apps/opentelemetry_experimental/src/otel_aggregation_histogram_explicit.erl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
-export_type([t/0]).
3434

35-
-define(DEFAULT_BOUNDARIES, [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0]).
35+
-define(DEFAULT_BOUNDARIES, [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0]).
3636

3737
-include_lib("stdlib/include/ms_transform.hrl").
3838

@@ -280,8 +280,6 @@ find_bucket(Boundaries, Value) ->
280280

281281
find_bucket([X | _Rest], Value, Pos) when Value =< X ->
282282
Pos;
283-
find_bucket([_X], _Value, Pos) ->
284-
Pos;
285283
find_bucket([_X | Rest], Value, Pos) ->
286284
find_bucket(Rest, Value, Pos+1);
287285
find_bucket(_, _, Pos) ->
@@ -290,12 +288,12 @@ find_bucket(_, _, Pos) ->
290288
get_buckets(BucketCounts, Boundaries) ->
291289
lists:foldl(fun(Idx, Acc) ->
292290
Acc ++ [counters_get(BucketCounts, Idx)]
293-
end, [], lists:seq(1, length(Boundaries))).
291+
end, [], lists:seq(1, length(Boundaries) + 1)).
294292

295293
counters_get(undefined, _) ->
296294
0;
297295
counters_get(Counter, Idx) ->
298296
counters:get(Counter, Idx).
299297

300298
new_bucket_counts(Boundaries) ->
301-
counters:new(length(Boundaries), [write_concurrency]).
299+
counters:new(length(Boundaries) + 1, [write_concurrency]).

apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ float_histogram(_Config) ->
311311
min=Min,
312312
max=Max,
313313
sum=Sum} <- Datapoints],
314-
?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,1,1,2,0,0,0,0,0,0], 5, 10.3, 31.1}]
314+
?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0], 5, 10.3, 31.1}]
315315
-- AttributeBuckets, AttributeBuckets)
316316
after
317317
5000 ->
@@ -514,11 +514,11 @@ explicit_histograms(_Config) ->
514514

515515
otel_meter_server:add_view(#{instrument_name => a_histogram}, #{}),
516516

517-
518517
?assertEqual(ok, otel_histogram:record(Histogram, 20, #{<<"c">> => <<"b">>})),
519518
?assertEqual(ok, otel_histogram:record(Histogram, 30, #{<<"a">> => <<"b">>, <<"d">> => <<"e">>})),
520519
?assertEqual(ok, otel_histogram:record(Histogram, 44, #{<<"c">> => <<"b">>})),
521520
?assertEqual(ok, otel_histogram:record(Histogram, 100, #{<<"c">> => <<"b">>})),
521+
?assertEqual(ok, otel_histogram:record(Histogram, 20000, #{<<"c">> => <<"b">>})),
522522

523523
otel_meter_server:force_flush(),
524524

@@ -531,8 +531,8 @@ explicit_histograms(_Config) ->
531531
min=Min,
532532
max=Max,
533533
sum=Sum} <- Datapoints]),
534-
?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,1,1,0,1,0,0,0], 20, 100, 164},
535-
{#{<<"a">> => <<"b">>, <<"d">> => <<"e">>}, [0,0,0,0,1,0,0,0,0,0], 30, 30, 30}]
534+
?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,1], 20, 20000, 20164},
535+
{#{<<"a">> => <<"b">>, <<"d">> => <<"e">>}, [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0], 30, 30, 30}]
536536
-- AttributeBuckets, AttributeBuckets)
537537
after
538538
5000 ->
@@ -580,8 +580,8 @@ delta_explicit_histograms(_Config) ->
580580
min=Min,
581581
max=Max,
582582
sum=Sum} <- Datapoints]),
583-
?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,1,1,0,1,0,0,0], 20, 100, 164},
584-
{#{<<"a">> => <<"b">>, <<"d">> => <<"e">>}, [0,0,0,0,1,0,0,0,0,0], 30, 30, 30}]
583+
?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0], 20, 100, 164},
584+
{#{<<"a">> => <<"b">>, <<"d">> => <<"e">>}, [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0], 30, 30, 30}]
585585
-- AttributeBuckets, AttributeBuckets)
586586
after
587587
5000 ->
@@ -601,9 +601,9 @@ delta_explicit_histograms(_Config) ->
601601
min=Min,
602602
max=Max,
603603
sum=Sum} <- Datapoints1],
604-
?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,0,0,0,1,0,0,0], 88, 88, 88},
604+
?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0], 88, 88, 88},
605605
{#{<<"a">> => <<"b">>,<<"d">> => <<"e">>},
606-
[0,0,0,0,0,0,0,0,0,0],
606+
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
607607
infinity,-9.223372036854776e18,0}
608608
]
609609
-- AttributeBuckets1, AttributeBuckets1)

0 commit comments

Comments
 (0)