Skip to content

Commit e3b84a4

Browse files
committed
feat: [#1403] rename field update_at to recorded_at in metrics Sample
The new name is more common in the context of metrics and time-series data packages like Prometheus.
1 parent 5099e90 commit e3b84a4

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

packages/metrics/src/metric_collection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ mod tests {
374374
"samples":[
375375
{
376376
"value":1,
377-
"update_at":"2025-04-02T00:00:00+00:00",
377+
"recorded_at":"2025-04-02T00:00:00+00:00",
378378
"labels":[
379379
{
380380
"name":"server_binding_ip",
@@ -398,7 +398,7 @@ mod tests {
398398
"samples":[
399399
{
400400
"value":1.0,
401-
"update_at":"2025-04-02T00:00:00+00:00",
401+
"recorded_at":"2025-04-02T00:00:00+00:00",
402402
"labels":[
403403
{
404404
"name":"server_binding_ip",

packages/metrics/src/sample.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub struct Sample<T> {
1818

1919
impl<T> Sample<T> {
2020
#[must_use]
21-
pub fn new(value: T, update_at: DurationSinceUnixEpoch, label_set: LabelSet) -> Self {
22-
let data = Measurement { value, update_at };
21+
pub fn new(value: T, recorded_at: DurationSinceUnixEpoch, label_set: LabelSet) -> Self {
22+
let data = Measurement { value, recorded_at };
2323

2424
Self {
2525
measurement: data,
@@ -38,8 +38,8 @@ impl<T> Sample<T> {
3838
}
3939

4040
#[must_use]
41-
pub fn update_at(&self) -> DurationSinceUnixEpoch {
42-
self.measurement.update_at
41+
pub fn recorded_at(&self) -> DurationSinceUnixEpoch {
42+
self.measurement.recorded_at
4343
}
4444

4545
#[must_use]
@@ -73,13 +73,13 @@ pub struct Measurement<T> {
7373

7474
/// The time when the sample was last updated.
7575
#[serde(serialize_with = "serialize_duration", deserialize_with = "deserialize_duration")]
76-
update_at: DurationSinceUnixEpoch,
76+
recorded_at: DurationSinceUnixEpoch,
7777
}
7878

7979
impl<T> Measurement<T> {
8080
#[must_use]
81-
pub fn new(value: T, update_at: DurationSinceUnixEpoch) -> Self {
82-
Self { value, update_at }
81+
pub fn new(value: T, recorded_at: DurationSinceUnixEpoch) -> Self {
82+
Self { value, recorded_at }
8383
}
8484

8585
#[must_use]
@@ -88,12 +88,12 @@ impl<T> Measurement<T> {
8888
}
8989

9090
#[must_use]
91-
pub fn update_at(&self) -> DurationSinceUnixEpoch {
92-
self.update_at
91+
pub fn recorded_at(&self) -> DurationSinceUnixEpoch {
92+
self.recorded_at
9393
}
9494

95-
fn set_update_at(&mut self, time: DurationSinceUnixEpoch) {
96-
self.update_at = time;
95+
fn set_recorded_at(&mut self, time: DurationSinceUnixEpoch) {
96+
self.recorded_at = time;
9797
}
9898
}
9999

@@ -112,18 +112,18 @@ impl<T: PrometheusSerializable> PrometheusSerializable for Measurement<T> {
112112
impl Measurement<Counter> {
113113
pub fn increment(&mut self, time: DurationSinceUnixEpoch) {
114114
self.value.increment(1);
115-
self.set_update_at(time);
115+
self.set_recorded_at(time);
116116
}
117117
}
118118

119119
impl Measurement<Gauge> {
120120
pub fn set(&mut self, value: f64, time: DurationSinceUnixEpoch) {
121121
self.value.set(value);
122-
self.set_update_at(time);
122+
self.set_recorded_at(time);
123123
}
124124
}
125125

126-
/// Serializes the `update_at` field as a string in ISO 8601 format (RFC 3339).
126+
/// Serializes the `recorded_at` field as a string in ISO 8601 format (RFC 3339).
127127
///
128128
/// # Errors
129129
///
@@ -189,7 +189,7 @@ mod tests {
189189
LabelSet::from(vec![("test", "label")]),
190190
);
191191

192-
assert_eq!(sample.update_at(), updated_at_time());
192+
assert_eq!(sample.recorded_at(), updated_at_time());
193193
}
194194

195195
#[test]
@@ -239,7 +239,7 @@ mod tests {
239239

240240
sample.increment(time);
241241

242-
assert_eq!(sample.update_at(), time);
242+
assert_eq!(sample.recorded_at(), time);
243243
}
244244

245245
#[test]
@@ -289,7 +289,7 @@ mod tests {
289289

290290
sample.set(1.0, time);
291291

292-
assert_eq!(sample.update_at(), time);
292+
assert_eq!(sample.recorded_at(), time);
293293
}
294294

295295
#[test]
@@ -321,7 +321,7 @@ mod tests {
321321
let deserialized: Sample<i32> = serde_json::from_str(&json).unwrap();
322322

323323
assert_eq!(original.measurement.value, deserialized.measurement.value);
324-
assert_eq!(original.measurement.update_at, deserialized.measurement.update_at);
324+
assert_eq!(original.measurement.recorded_at, deserialized.measurement.recorded_at);
325325
assert_eq!(original.label_set, deserialized.label_set);
326326
}
327327

@@ -338,7 +338,7 @@ mod tests {
338338
let expected_json = r#"
339339
{
340340
"value": 42,
341-
"update_at": "2025-04-02T00:00:00.000000100+00:00",
341+
"recorded_at": "2025-04-02T00:00:00.000000100+00:00",
342342
"labels": [
343343
{
344344
"name": "label_name",
@@ -372,7 +372,7 @@ mod tests {
372372
r#"
373373
{
374374
"value": 42,
375-
"update_at": "1-1-2023T25:00:00Z",
375+
"recorded_at": "1-1-2023T25:00:00Z",
376376
"labels": [
377377
{
378378
"name": "label_name",

packages/metrics/src/sample_collection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<T: Serialize> Serialize for SampleCollection<T> {
8989
let mut samples: Vec<Sample<&T>> = vec![];
9090

9191
for (label_set, sample_data) in &self.samples {
92-
samples.push(Sample::new(sample_data.value(), sample_data.update_at(), label_set.clone()));
92+
samples.push(Sample::new(sample_data.value(), sample_data.recorded_at(), label_set.clone()));
9393
}
9494

9595
samples.serialize(serializer)
@@ -317,7 +317,7 @@ mod tests {
317317
collection.increment(&label_set, new_time);
318318

319319
let sample = collection.get(&label_set).unwrap();
320-
assert_eq!(sample.update_at(), new_time);
320+
assert_eq!(sample.recorded_at(), new_time);
321321
assert_eq!(*sample.value(), Counter::new(2));
322322
}
323323

@@ -392,7 +392,7 @@ mod tests {
392392
collection.set(&label_set, 2.0, new_time);
393393

394394
let sample = collection.get(&label_set).unwrap();
395-
assert_eq!(sample.update_at(), new_time);
395+
assert_eq!(sample.recorded_at(), new_time);
396396
assert_eq!(*sample.value(), Gauge::new(2.0));
397397
}
398398

0 commit comments

Comments
 (0)