Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(otel_metrics): use opentelemetry:timestamp/0 #644

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apps/opentelemetry_experimental/include/otel_metrics.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
{
%% TODO: attributes should be a tuple of just the values, sorted by attribute name
key :: key_match_spec() | undefined | {element, 2, '$_'},
start_time_unix_nano :: match_spec(integer()) | undefined,
last_start_time_unix_nano :: match_spec(integer()) | undefined,
start_time :: match_spec(integer()) | undefined,
last_start_time :: match_spec(integer()) | undefined,
checkpoint :: match_spec(number()) | undefined | {'+', '$2', '$3'} | {'+', '$3', '$4'},
previous_checkpoint :: match_spec(number()) | undefined | {'+', '$5', '$6'},
int_value :: match_spec(number()) | undefined | {'+', '$3', {const, number()}},
Expand All @@ -42,8 +42,8 @@
key :: key_match_spec() | undefined,
checkpoint :: match_spec(number()) | undefined,
value :: match_spec(number()) | undefined,
start_time_unix_nano :: match_spec(integer()) | undefined,
last_start_time_unix_nano :: match_spec(integer()) | undefined
start_time :: match_spec(integer()) | undefined,
last_start_time :: match_spec(integer()) | undefined
}).


Expand All @@ -53,14 +53,14 @@
min :: match_spec(number()) | undefined,
max :: match_spec(number()) | undefined,
sum :: match_spec(number()) | undefined,
start_time_unix_nano :: match_spec(number()) | undefined
start_time :: match_spec(number()) | undefined
}).

-record(explicit_histogram_aggregation,
{
%% TODO: attributes should be a tuple of just the values, sorted by attribute name
key :: key_match_spec() | undefined,
start_time_unix_nano :: match_spec(integer()) | undefined,
start_time :: match_spec(integer()) | 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]
explicit_bucket_boundaries :: match_spec([float()]) | undefined,
Expand All @@ -75,8 +75,8 @@
-record(datapoint,
{
attributes :: opentelemetry:attributes_map(),
start_time_unix_nano :: integer(),
time_unix_nano :: integer(),
start_time :: integer(),
time :: integer(),
value :: number(),
exemplars :: list() | undefined,
flags :: integer() %% uint32
Expand All @@ -97,8 +97,8 @@
-record(histogram_datapoint,
{
attributes :: opentelemetry:attributes_map(),
start_time_unix_nano :: match_spec(integer()) | {const, eqwalizer:dynamic()} | undefined,
time_unix_nano :: integer(),
start_time :: match_spec(integer()) | {const, eqwalizer:dynamic()} | undefined,
time :: integer(),
count :: number(),
sum :: float() | match_spec(integer()) | undefined,
bucket_counts :: list(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ init(#view_aggregation{name=Name,
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),
start_time=opentelemetry:timestamp(),
explicit_bucket_boundaries=ExplicitBucketBoundaries,
bucket_counts=new_bucket_counts(ExplicitBucketBoundaries),
checkpoint=undefined,
Expand Down Expand Up @@ -177,9 +177,9 @@ aggregate(Table, #view_aggregation{name=Name,

checkpoint(Tab, #view_aggregation{name=Name,
reader=ReaderId,
temporality=?TEMPORALITY_DELTA}, CollectionStartNano) ->
temporality=?TEMPORALITY_DELTA}, CollectionStartTime) ->
MS = [{#explicit_histogram_aggregation{key={Name, '$1', ReaderId},
start_time_unix_nano='$9',
start_time='$9',
explicit_bucket_boundaries='$2',
record_min_max='$3',
checkpoint='_',
Expand All @@ -190,22 +190,22 @@ checkpoint(Tab, #view_aggregation{name=Name,
},
[],
[{#explicit_histogram_aggregation{key={{{const, Name}, '$1', {const, ReaderId}}},
start_time_unix_nano={const, CollectionStartNano},
start_time={const, CollectionStartTime},
explicit_bucket_boundaries='$2',
record_min_max='$3',
checkpoint={#explicit_histogram_checkpoint{bucket_counts='$5',
min='$6',
max='$7',
sum='$8',
start_time_unix_nano='$9'}},
start_time='$9'}},
bucket_counts={const, undefined},
min=infinity,
max=?MIN_DOUBLE,
sum=0}}]}],
_ = ets:select_replace(Tab, MS),

ok;
checkpoint(_Tab, _, _CollectionStartNano) ->
checkpoint(_Tab, _, _CollectionStartTime) ->
%% no good way to checkpoint the `counters' without being out of sync with
%% min/max/sum, so may as well just collect them in `collect', which will
%% also be out of sync, but best we can do right now
Expand All @@ -216,7 +216,7 @@ collect(Tab, #view_aggregation{name=Name,
reader=ReaderId,
temporality=Temporality}, CollectionStartTime) ->
Select = [{#explicit_histogram_aggregation{key={Name, '$1', ReaderId},
start_time_unix_nano='$2',
start_time='$2',
explicit_bucket_boundaries='$3',
record_min_max='$4',
checkpoint='$5',
Expand All @@ -230,10 +230,10 @@ collect(Tab, #view_aggregation{name=Name,

%%

datapoint(CollectionStartNano, #explicit_histogram_aggregation{
datapoint(CollectionStartTime, #explicit_histogram_aggregation{
key={_, Attributes, _},
explicit_bucket_boundaries=Boundaries,
start_time_unix_nano=StartTimeUnixNano,
start_time=StartTime,
checkpoint=undefined,
bucket_counts=BucketCounts,
min=Min,
Expand All @@ -243,8 +243,8 @@ datapoint(CollectionStartNano, #explicit_histogram_aggregation{
Buckets = get_buckets(BucketCounts, Boundaries),
#histogram_datapoint{
attributes=Attributes,
start_time_unix_nano=StartTimeUnixNano,
time_unix_nano=CollectionStartNano,
start_time=StartTime,
time=CollectionStartTime,
count=lists:sum(Buckets),
sum=Sum,
bucket_counts=Buckets,
Expand All @@ -254,20 +254,20 @@ datapoint(CollectionStartNano, #explicit_histogram_aggregation{
min=Min,
max=Max
};
datapoint(CollectionStartNano, #explicit_histogram_aggregation{
datapoint(CollectionStartTime, #explicit_histogram_aggregation{
key={_, Attributes, _},
explicit_bucket_boundaries=Boundaries,
checkpoint=#explicit_histogram_checkpoint{bucket_counts=BucketCounts,
min=Min,
max=Max,
sum=Sum,
start_time_unix_nano=StartTimeUnixNano}
start_time=StartTime}
}) ->
Buckets = get_buckets(BucketCounts, Boundaries),
#histogram_datapoint{
attributes=Attributes,
start_time_unix_nano=StartTimeUnixNano,
time_unix_nano=CollectionStartNano,
start_time=StartTime,
time=CollectionStartTime,
count=lists:sum(Buckets),
sum=Sum,
bucket_counts=Buckets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ init(#view_aggregation{name=Name,
aggregation_options=_Options}, Attributes) ->
Key = {Name, Attributes, ReaderId},
#last_value_aggregation{key=Key,
start_time_unix_nano=erlang:system_time(nanosecond),
start_time=opentelemetry:timestamp(),
value=undefined}.

aggregate(Tab, ViewAggregation=#view_aggregation{name=Name,
Expand All @@ -55,32 +55,32 @@ aggregate(Tab, ViewAggregation=#view_aggregation{name=Name,

checkpoint(Tab, #view_aggregation{name=Name,
reader=ReaderId,
temporality=?TEMPORALITY_DELTA}, CollectionStartNano) ->
temporality=?TEMPORALITY_DELTA}, CollectionStartTime) ->
MS = [{#last_value_aggregation{key={Name, '$1', ReaderId},
start_time_unix_nano='$3',
last_start_time_unix_nano='_',
start_time='$3',
last_start_time='_',
checkpoint='_',
value='$2'},
[],
[{#last_value_aggregation{key={{Name, '$1', {const, ReaderId}}},
start_time_unix_nano={const, CollectionStartNano},
last_start_time_unix_nano='$3',
start_time={const, CollectionStartTime},
last_start_time='$3',
checkpoint='$2',
value='$2'}}]}],
_ = ets:select_replace(Tab, MS),

ok;
checkpoint(Tab, #view_aggregation{name=Name,
reader=ReaderId}, _CollectionStartNano) ->
reader=ReaderId}, _CollectionStartTime) ->
MS = [{#last_value_aggregation{key={Name, '$1', ReaderId},
start_time_unix_nano='$3',
last_start_time_unix_nano='_',
start_time='$3',
last_start_time='_',
checkpoint='_',
value='$2'},
[],
[{#last_value_aggregation{key={{{const, Name}, '$1', {const, ReaderId}}},
start_time_unix_nano='$3',
last_start_time_unix_nano='$3',
start_time='$3',
last_start_time='$3',
checkpoint='$2',
value='$2'}}]}],
_ = ets:select_replace(Tab, MS),
Expand All @@ -93,23 +93,23 @@ collect(Tab, #view_aggregation{name=Name,
Select = [{#last_value_aggregation{key={Name, '$1', ReaderId},
checkpoint='$2',
value='$3',
start_time_unix_nano='$4',
last_start_time_unix_nano='$5'}, [], ['$_']}],
start_time='$4',
last_start_time='$5'}, [], ['$_']}],
AttributesAggregation = ets:select(Tab, Select),
#gauge{datapoints=[datapoint(CollectionStartTime, LastValueAgg) ||
LastValueAgg <- AttributesAggregation]}.

%%

datapoint(CollectionStartNano, #last_value_aggregation{key={_, Attributes, _},
last_start_time_unix_nano=StartTimeUnixNano,
datapoint(CollectionStartTime, #last_value_aggregation{key={_, Attributes, _},
last_start_time=StartTime,
checkpoint=Checkpoint}) ->
#datapoint{attributes=Attributes,
%% `start_time_unix_nano' being set to `last_start_time_unix_nano' causes complaints
%% because `last_start_time_unix_nano' has matchspec values in its typespec
%% `start_time' being set to `last_start_time' causes complaints
%% because `last_start_time' has matchspec values in its typespec
%% eqwalizer:ignore see above
start_time_unix_nano=StartTimeUnixNano,
time_unix_nano=CollectionStartNano,
start_time=StartTime,
time=CollectionStartTime,
%% eqwalizer:ignore more matchspec fun
value=Checkpoint,
exemplars=[],
Expand Down
Loading
Loading