Skip to content

Commit

Permalink
Rename boundaries to explicit_bucket_boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
albertored committed Oct 2, 2023
1 parent 046d97c commit 5e48148
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/opentelemetry_experimental/include/otel_metrics.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
start_time_unix_nano :: integer() | {const, eqwalizer:dynamic()} | '$9' | '$2' | undefined,
%% instrument_temporality :: otel_aggregation:temporality(),
%% default: [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0]
boundaries :: [float()] | match_spec([float()]),
explicit_bucket_boundaries :: [float()] | match_spec([float()]),
record_min_max :: boolean() | match_spec(boolean()),
checkpoint :: #explicit_histogram_checkpoint{} | match_spec(#explicit_histogram_checkpoint{}) | {#explicit_histogram_checkpoint{}},
bucket_counts :: counters:counters_ref() | match_spec(undefined),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ init(#view_aggregation{name=Name,
reader=ReaderId,
aggregation_options=Options}, Attributes) ->
Key = {Name, Attributes, ReaderId},
Boundaries = maps:get(boundaries, Options, ?DEFAULT_BOUNDARIES),
ExplicitBucketBoundaries = maps:get(explicit_bucket_boundaries, Options, ?DEFAULT_BOUNDARIES),
RecordMinMax = maps:get(record_min_max, Options, true),
#explicit_histogram_aggregation{key=Key,
start_time_unix_nano=erlang:system_time(nanosecond),
boundaries=Boundaries,
bucket_counts=new_bucket_counts(Boundaries),
explicit_bucket_boundaries=ExplicitBucketBoundaries,
bucket_counts=new_bucket_counts(ExplicitBucketBoundaries),
checkpoint=undefined,
record_min_max=RecordMinMax,
min=infinity, %% works because any atom is > any integer
Expand All @@ -153,17 +153,17 @@ aggregate(Table, #view_aggregation{name=Name,
reader=ReaderId,
aggregation_options=Options}, Value, Attributes) ->
Key = {Name, Attributes, ReaderId},
Boundaries = maps:get(boundaries, Options, ?DEFAULT_BOUNDARIES),
ExplicitBucketBoundaries = maps:get(explicit_bucket_boundaries, Options, ?DEFAULT_BOUNDARIES),
try ets:lookup_element(Table, Key, #explicit_histogram_aggregation.bucket_counts) of
BucketCounts0 ->
BucketCounts = case BucketCounts0 of
undefined ->
new_bucket_counts(Boundaries);
new_bucket_counts(ExplicitBucketBoundaries);
_ ->
BucketCounts0
end,

BucketIdx = find_bucket(Boundaries, Value),
BucketIdx = find_bucket(ExplicitBucketBoundaries, Value),
counters:add(BucketCounts, BucketIdx, 1),

MS = ?AGGREATE_MATCH_SPEC(Key, Value, BucketCounts),
Expand All @@ -181,7 +181,7 @@ checkpoint(Tab, #view_aggregation{name=Name,
temporality=?TEMPORALITY_DELTA}, CollectionStartNano) ->
MS = [{#explicit_histogram_aggregation{key='$1',
start_time_unix_nano='$9',
boundaries='$2',
explicit_bucket_boundaries='$2',
record_min_max='$3',
checkpoint='_',
bucket_counts='$5',
Expand All @@ -193,7 +193,7 @@ checkpoint(Tab, #view_aggregation{name=Name,
{'=:=', {element, 3, '$1'}, {const, ReaderId}}],
[{#explicit_histogram_aggregation{key='$1',
start_time_unix_nano={const, CollectionStartNano},
boundaries='$2',
explicit_bucket_boundaries='$2',
record_min_max='$3',
checkpoint={#explicit_histogram_checkpoint{bucket_counts='$5',
min='$6',
Expand Down Expand Up @@ -229,7 +229,7 @@ collect(Tab, #view_aggregation{name=Name,

datapoint(CollectionStartNano, #explicit_histogram_aggregation{
key={_, Attributes, _},
boundaries=Boundaries,
explicit_bucket_boundaries=Boundaries,
start_time_unix_nano=StartTimeUnixNano,
checkpoint=undefined,
bucket_counts=BucketCounts,
Expand All @@ -253,7 +253,7 @@ datapoint(CollectionStartNano, #explicit_histogram_aggregation{
};
datapoint(CollectionStartNano, #explicit_histogram_aggregation{
key={_, Attributes, _},
boundaries=Boundaries,
explicit_bucket_boundaries=Boundaries,
checkpoint=#explicit_histogram_checkpoint{bucket_counts=BucketCounts,
min=Min,
max=Max,
Expand Down
4 changes: 2 additions & 2 deletions apps/opentelemetry_experimental/src/otel_view.erl
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ match_instrument_to_views(Instrument=#instrument{name=InstrumentName,

%%

aggragation_options(#{boundaries := _} = AggregationOptions, _AdvisoryParams) ->
aggragation_options(#{explicit_bucket_boundaries := _} = AggregationOptions, _AdvisoryParams) ->
AggregationOptions;
aggragation_options(AggregationOptions, #{explicit_bucket_boundaries := Boundaries}) ->
maps:put(boundaries, Boundaries, AggregationOptions);
maps:put(explicit_bucket_boundaries, Boundaries, AggregationOptions);
aggragation_options(AggregationOptions, _AdvisoryParams) ->
AggregationOptions.

Expand Down
6 changes: 3 additions & 3 deletions apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,10 @@ advisory_params(_Config) ->
ct:fail(histogram_receive_timeout)
end,

% boundaries from view have precedence
% explicit_bucket_boundaries from view have precedence
?assert(otel_meter_server:add_view(view, #{instrument_name => b_histogram}, #{
aggregation_module => otel_aggregation_histogram_explicit,
aggregation_options => #{boundaries => [10, 100]}})),
aggregation_options => #{explicit_bucket_boundaries => [10, 100]}})),

HistogramB = otel_histogram:create(Meter, b_histogram,
#{advisory_params => #{explicit_bucket_boundaries => [10, 20, 30]}}),
Expand Down Expand Up @@ -1223,7 +1223,7 @@ histogram_aggregation_options(_Config) ->

?assert(otel_meter_server:add_view(view, #{instrument_name => histogram}, #{
aggregation_module => otel_aggregation_histogram_explicit,
aggregation_options => #{boundaries => [10, 100]}})),
aggregation_options => #{explicit_bucket_boundaries => [10, 100]}})),

Histogram = otel_histogram:create(Meter, histogram, #{}),

Expand Down

0 comments on commit 5e48148

Please sign in to comment.