From be9194eaa26a53cc2e304aeb2c0a1aeb63e6a3ce Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Sun, 27 Aug 2023 14:45:00 +0200 Subject: [PATCH] Histogram buckets should be 1 more than boundaries Adpat default boundaries to last version of the specs --- .../src/otel_aggregation_histogram_explicit.erl | 8 +++----- .../test/otel_metrics_SUITE.erl | 16 ++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/opentelemetry_experimental/src/otel_aggregation_histogram_explicit.erl b/apps/opentelemetry_experimental/src/otel_aggregation_histogram_explicit.erl index 03b7bd1b..7981e556 100644 --- a/apps/opentelemetry_experimental/src/otel_aggregation_histogram_explicit.erl +++ b/apps/opentelemetry_experimental/src/otel_aggregation_histogram_explicit.erl @@ -32,7 +32,7 @@ -export_type([t/0]). --define(DEFAULT_BOUNDARIES, [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0]). +-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]). -include_lib("stdlib/include/ms_transform.hrl"). @@ -280,8 +280,6 @@ find_bucket(Boundaries, Value) -> find_bucket([X | _Rest], Value, Pos) when Value =< X -> Pos; -find_bucket([_X], _Value, Pos) -> - Pos; find_bucket([_X | Rest], Value, Pos) -> find_bucket(Rest, Value, Pos+1); find_bucket(_, _, Pos) -> @@ -290,7 +288,7 @@ find_bucket(_, _, Pos) -> get_buckets(BucketCounts, Boundaries) -> lists:foldl(fun(Idx, Acc) -> Acc ++ [counters_get(BucketCounts, Idx)] - end, [], lists:seq(1, length(Boundaries))). + end, [], lists:seq(1, length(Boundaries) + 1)). counters_get(undefined, _) -> 0; @@ -298,4 +296,4 @@ counters_get(Counter, Idx) -> counters:get(Counter, Idx). new_bucket_counts(Boundaries) -> - counters:new(length(Boundaries), [write_concurrency]). + counters:new(length(Boundaries) + 1, [write_concurrency]). diff --git a/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl b/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl index aee14b3c..06f7f30b 100644 --- a/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl +++ b/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl @@ -311,7 +311,7 @@ float_histogram(_Config) -> min=Min, max=Max, sum=Sum} <- Datapoints], - ?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,1,1,2,0,0,0,0,0,0], 5, 10.3, 31.1}] + ?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0], 5, 10.3, 31.1}] -- AttributeBuckets, AttributeBuckets) after 5000 -> @@ -514,11 +514,11 @@ explicit_histograms(_Config) -> otel_meter_server:add_view(#{instrument_name => a_histogram}, #{}), - ?assertEqual(ok, otel_histogram:record(Histogram, 20, #{<<"c">> => <<"b">>})), ?assertEqual(ok, otel_histogram:record(Histogram, 30, #{<<"a">> => <<"b">>, <<"d">> => <<"e">>})), ?assertEqual(ok, otel_histogram:record(Histogram, 44, #{<<"c">> => <<"b">>})), ?assertEqual(ok, otel_histogram:record(Histogram, 100, #{<<"c">> => <<"b">>})), + ?assertEqual(ok, otel_histogram:record(Histogram, 20000, #{<<"c">> => <<"b">>})), otel_meter_server:force_flush(), @@ -531,8 +531,8 @@ explicit_histograms(_Config) -> min=Min, max=Max, sum=Sum} <- Datapoints]), - ?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,1,1,0,1,0,0,0], 20, 100, 164}, - {#{<<"a">> => <<"b">>, <<"d">> => <<"e">>}, [0,0,0,0,1,0,0,0,0,0], 30, 30, 30}] + ?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,1], 20, 20000, 20164}, + {#{<<"a">> => <<"b">>, <<"d">> => <<"e">>}, [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0], 30, 30, 30}] -- AttributeBuckets, AttributeBuckets) after 5000 -> @@ -580,8 +580,8 @@ delta_explicit_histograms(_Config) -> min=Min, max=Max, sum=Sum} <- Datapoints]), - ?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,1,1,0,1,0,0,0], 20, 100, 164}, - {#{<<"a">> => <<"b">>, <<"d">> => <<"e">>}, [0,0,0,0,1,0,0,0,0,0], 30, 30, 30}] + ?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0], 20, 100, 164}, + {#{<<"a">> => <<"b">>, <<"d">> => <<"e">>}, [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0], 30, 30, 30}] -- AttributeBuckets, AttributeBuckets) after 5000 -> @@ -601,9 +601,9 @@ delta_explicit_histograms(_Config) -> min=Min, max=Max, sum=Sum} <- Datapoints1], - ?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,0,0,0,1,0,0,0], 88, 88, 88}, + ?assertEqual([], [{#{<<"c">> => <<"b">>}, [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0], 88, 88, 88}, {#{<<"a">> => <<"b">>,<<"d">> => <<"e">>}, - [0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], infinity,-9.223372036854776e18,0} ] -- AttributeBuckets1, AttributeBuckets1)