Skip to content

Commit b51f206

Browse files
author
Tristan Sloughter
authored
Merge pull request #644 from SergeTupchiy/fix-metrics-timestamp
fix(otel_metrics): use `opentelemetry:timestamp/0`
2 parents 363d277 + d3ab7c1 commit b51f206

File tree

9 files changed

+110
-110
lines changed

9 files changed

+110
-110
lines changed

apps/opentelemetry_experimental/include/otel_metrics.hrl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
{
2929
%% TODO: attributes should be a tuple of just the values, sorted by attribute name
3030
key :: key_match_spec() | undefined | {element, 2, '$_'},
31-
start_time_unix_nano :: match_spec(integer()) | undefined,
32-
last_start_time_unix_nano :: match_spec(integer()) | undefined,
31+
start_time :: match_spec(integer()) | undefined,
32+
last_start_time :: match_spec(integer()) | undefined,
3333
checkpoint :: match_spec(number()) | undefined | {'+', '$2', '$3'} | {'+', '$3', '$4'},
3434
previous_checkpoint :: match_spec(number()) | undefined | {'+', '$5', '$6'},
3535
int_value :: match_spec(number()) | undefined | {'+', '$3', {const, number()}},
@@ -42,8 +42,8 @@
4242
key :: key_match_spec() | undefined,
4343
checkpoint :: match_spec(number()) | undefined,
4444
value :: match_spec(number()) | undefined,
45-
start_time_unix_nano :: match_spec(integer()) | undefined,
46-
last_start_time_unix_nano :: match_spec(integer()) | undefined
45+
start_time :: match_spec(integer()) | undefined,
46+
last_start_time :: match_spec(integer()) | undefined
4747
}).
4848

4949

@@ -53,14 +53,14 @@
5353
min :: match_spec(number()) | undefined,
5454
max :: match_spec(number()) | undefined,
5555
sum :: match_spec(number()) | undefined,
56-
start_time_unix_nano :: match_spec(number()) | undefined
56+
start_time :: match_spec(number()) | undefined
5757
}).
5858

5959
-record(explicit_histogram_aggregation,
6060
{
6161
%% TODO: attributes should be a tuple of just the values, sorted by attribute name
6262
key :: key_match_spec() | undefined,
63-
start_time_unix_nano :: match_spec(integer()) | undefined,
63+
start_time :: match_spec(integer()) | undefined,
6464
%% instrument_temporality :: otel_aggregation:temporality(),
6565
%% default: [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0]
6666
explicit_bucket_boundaries :: match_spec([float()]) | undefined,
@@ -75,8 +75,8 @@
7575
-record(datapoint,
7676
{
7777
attributes :: opentelemetry:attributes_map(),
78-
start_time_unix_nano :: integer(),
79-
time_unix_nano :: integer(),
78+
start_time :: integer(),
79+
time :: integer(),
8080
value :: number(),
8181
exemplars :: list() | undefined,
8282
flags :: integer() %% uint32
@@ -97,8 +97,8 @@
9797
-record(histogram_datapoint,
9898
{
9999
attributes :: opentelemetry:attributes_map(),
100-
start_time_unix_nano :: match_spec(integer()) | {const, eqwalizer:dynamic()} | undefined,
101-
time_unix_nano :: integer(),
100+
start_time :: match_spec(integer()) | {const, eqwalizer:dynamic()} | undefined,
101+
time :: integer(),
102102
count :: number(),
103103
sum :: float() | match_spec(integer()) | undefined,
104104
bucket_counts :: list(),

apps/opentelemetry_experimental/src/otel_aggregation_histogram_explicit.erl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ init(#view_aggregation{name=Name,
139139
ExplicitBucketBoundaries = maps:get(explicit_bucket_boundaries, Options, ?DEFAULT_BOUNDARIES),
140140
RecordMinMax = maps:get(record_min_max, Options, true),
141141
#explicit_histogram_aggregation{key=Key,
142-
start_time_unix_nano=erlang:system_time(nanosecond),
142+
start_time=opentelemetry:timestamp(),
143143
explicit_bucket_boundaries=ExplicitBucketBoundaries,
144144
bucket_counts=new_bucket_counts(ExplicitBucketBoundaries),
145145
checkpoint=undefined,
@@ -177,9 +177,9 @@ aggregate(Table, #view_aggregation{name=Name,
177177

178178
checkpoint(Tab, #view_aggregation{name=Name,
179179
reader=ReaderId,
180-
temporality=?TEMPORALITY_DELTA}, CollectionStartNano) ->
180+
temporality=?TEMPORALITY_DELTA}, CollectionStartTime) ->
181181
MS = [{#explicit_histogram_aggregation{key={Name, '$1', ReaderId},
182-
start_time_unix_nano='$9',
182+
start_time='$9',
183183
explicit_bucket_boundaries='$2',
184184
record_min_max='$3',
185185
checkpoint='_',
@@ -190,22 +190,22 @@ checkpoint(Tab, #view_aggregation{name=Name,
190190
},
191191
[],
192192
[{#explicit_histogram_aggregation{key={{{const, Name}, '$1', {const, ReaderId}}},
193-
start_time_unix_nano={const, CollectionStartNano},
193+
start_time={const, CollectionStartTime},
194194
explicit_bucket_boundaries='$2',
195195
record_min_max='$3',
196196
checkpoint={#explicit_histogram_checkpoint{bucket_counts='$5',
197197
min='$6',
198198
max='$7',
199199
sum='$8',
200-
start_time_unix_nano='$9'}},
200+
start_time='$9'}},
201201
bucket_counts={const, undefined},
202202
min=infinity,
203203
max=?MIN_DOUBLE,
204204
sum=0}}]}],
205205
_ = ets:select_replace(Tab, MS),
206206

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

231231
%%
232232

233-
datapoint(CollectionStartNano, #explicit_histogram_aggregation{
233+
datapoint(CollectionStartTime, #explicit_histogram_aggregation{
234234
key={_, Attributes, _},
235235
explicit_bucket_boundaries=Boundaries,
236-
start_time_unix_nano=StartTimeUnixNano,
236+
start_time=StartTime,
237237
checkpoint=undefined,
238238
bucket_counts=BucketCounts,
239239
min=Min,
@@ -243,8 +243,8 @@ datapoint(CollectionStartNano, #explicit_histogram_aggregation{
243243
Buckets = get_buckets(BucketCounts, Boundaries),
244244
#histogram_datapoint{
245245
attributes=Attributes,
246-
start_time_unix_nano=StartTimeUnixNano,
247-
time_unix_nano=CollectionStartNano,
246+
start_time=StartTime,
247+
time=CollectionStartTime,
248248
count=lists:sum(Buckets),
249249
sum=Sum,
250250
bucket_counts=Buckets,
@@ -254,20 +254,20 @@ datapoint(CollectionStartNano, #explicit_histogram_aggregation{
254254
min=Min,
255255
max=Max
256256
};
257-
datapoint(CollectionStartNano, #explicit_histogram_aggregation{
257+
datapoint(CollectionStartTime, #explicit_histogram_aggregation{
258258
key={_, Attributes, _},
259259
explicit_bucket_boundaries=Boundaries,
260260
checkpoint=#explicit_histogram_checkpoint{bucket_counts=BucketCounts,
261261
min=Min,
262262
max=Max,
263263
sum=Sum,
264-
start_time_unix_nano=StartTimeUnixNano}
264+
start_time=StartTime}
265265
}) ->
266266
Buckets = get_buckets(BucketCounts, Boundaries),
267267
#histogram_datapoint{
268268
attributes=Attributes,
269-
start_time_unix_nano=StartTimeUnixNano,
270-
time_unix_nano=CollectionStartNano,
269+
start_time=StartTime,
270+
time=CollectionStartTime,
271271
count=lists:sum(Buckets),
272272
sum=Sum,
273273
bucket_counts=Buckets,

apps/opentelemetry_experimental/src/otel_aggregation_last_value.erl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ init(#view_aggregation{name=Name,
3939
aggregation_options=_Options}, Attributes) ->
4040
Key = {Name, Attributes, ReaderId},
4141
#last_value_aggregation{key=Key,
42-
start_time_unix_nano=erlang:system_time(nanosecond),
42+
start_time=opentelemetry:timestamp(),
4343
value=undefined}.
4444

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

5656
checkpoint(Tab, #view_aggregation{name=Name,
5757
reader=ReaderId,
58-
temporality=?TEMPORALITY_DELTA}, CollectionStartNano) ->
58+
temporality=?TEMPORALITY_DELTA}, CollectionStartTime) ->
5959
MS = [{#last_value_aggregation{key={Name, '$1', ReaderId},
60-
start_time_unix_nano='$3',
61-
last_start_time_unix_nano='_',
60+
start_time='$3',
61+
last_start_time='_',
6262
checkpoint='_',
6363
value='$2'},
6464
[],
6565
[{#last_value_aggregation{key={{Name, '$1', {const, ReaderId}}},
66-
start_time_unix_nano={const, CollectionStartNano},
67-
last_start_time_unix_nano='$3',
66+
start_time={const, CollectionStartTime},
67+
last_start_time='$3',
6868
checkpoint='$2',
6969
value='$2'}}]}],
7070
_ = ets:select_replace(Tab, MS),
7171

7272
ok;
7373
checkpoint(Tab, #view_aggregation{name=Name,
74-
reader=ReaderId}, _CollectionStartNano) ->
74+
reader=ReaderId}, _CollectionStartTime) ->
7575
MS = [{#last_value_aggregation{key={Name, '$1', ReaderId},
76-
start_time_unix_nano='$3',
77-
last_start_time_unix_nano='_',
76+
start_time='$3',
77+
last_start_time='_',
7878
checkpoint='_',
7979
value='$2'},
8080
[],
8181
[{#last_value_aggregation{key={{{const, Name}, '$1', {const, ReaderId}}},
82-
start_time_unix_nano='$3',
83-
last_start_time_unix_nano='$3',
82+
start_time='$3',
83+
last_start_time='$3',
8484
checkpoint='$2',
8585
value='$2'}}]}],
8686
_ = ets:select_replace(Tab, MS),
@@ -93,23 +93,23 @@ collect(Tab, #view_aggregation{name=Name,
9393
Select = [{#last_value_aggregation{key={Name, '$1', ReaderId},
9494
checkpoint='$2',
9595
value='$3',
96-
start_time_unix_nano='$4',
97-
last_start_time_unix_nano='$5'}, [], ['$_']}],
96+
start_time='$4',
97+
last_start_time='$5'}, [], ['$_']}],
9898
AttributesAggregation = ets:select(Tab, Select),
9999
#gauge{datapoints=[datapoint(CollectionStartTime, LastValueAgg) ||
100100
LastValueAgg <- AttributesAggregation]}.
101101

102102
%%
103103

104-
datapoint(CollectionStartNano, #last_value_aggregation{key={_, Attributes, _},
105-
last_start_time_unix_nano=StartTimeUnixNano,
104+
datapoint(CollectionStartTime, #last_value_aggregation{key={_, Attributes, _},
105+
last_start_time=StartTime,
106106
checkpoint=Checkpoint}) ->
107107
#datapoint{attributes=Attributes,
108-
%% `start_time_unix_nano' being set to `last_start_time_unix_nano' causes complaints
109-
%% because `last_start_time_unix_nano' has matchspec values in its typespec
108+
%% `start_time' being set to `last_start_time' causes complaints
109+
%% because `last_start_time' has matchspec values in its typespec
110110
%% eqwalizer:ignore see above
111-
start_time_unix_nano=StartTimeUnixNano,
112-
time_unix_nano=CollectionStartNano,
111+
start_time=StartTime,
112+
time=CollectionStartTime,
113113
%% eqwalizer:ignore more matchspec fun
114114
value=Checkpoint,
115115
exemplars=[],

0 commit comments

Comments
 (0)