From 1053036067188666116df9c1643554b388ab9798 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Wed, 28 Jun 2023 11:51:44 +0200 Subject: [PATCH] Allow metadata to configure precise timestamps --- glean_parser/pings.py | 2 ++ glean_parser/schemas/pings.2-0-0.schema.yaml | 9 +++++++++ glean_parser/templates/rust.jinja2 | 2 +- glean_parser/templates/swift.jinja2 | 1 + glean_parser/util.py | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/glean_parser/pings.py b/glean_parser/pings.py index cb5f2487b..3099fa1d1 100644 --- a/glean_parser/pings.py +++ b/glean_parser/pings.py @@ -44,6 +44,7 @@ def __init__( if metadata is None: metadata = {} self.metadata = metadata + self.precise_timestamps = self.metadata.get("precise_timestamps", True) if data_reviews is None: data_reviews = [] self.data_reviews = data_reviews @@ -88,6 +89,7 @@ def serialize(self) -> Dict[str, util.JSONType]: def _serialize_input(self) -> Dict[str, util.JSONType]: d = self.serialize() modified_dict = util.remove_output_params(d, "defined_in") + modified_dict = util.remove_output_params(modified_dict, "precise_timestamps") return modified_dict def identifier(self) -> str: diff --git a/glean_parser/schemas/pings.2-0-0.schema.yaml b/glean_parser/schemas/pings.2-0-0.schema.yaml index fb0f9c191..2f25405d4 100644 --- a/glean_parser/schemas/pings.2-0-0.schema.yaml +++ b/glean_parser/schemas/pings.2-0-0.schema.yaml @@ -76,6 +76,15 @@ additionalProperties: items: type: string maxLength: 80 + precise_timestamps: + title: Precise Timestamps + description: | + When `true` Glean uses millisecond-precise timestamps for + the ping's start/end time (the default). + When `false` Glean uses minute-precise timestamps for + the ping's start/end time. + type: boolean + default: {} include_client_id: diff --git a/glean_parser/templates/rust.jinja2 b/glean_parser/templates/rust.jinja2 index 083dcdbb0..51e458cdd 100644 --- a/glean_parser/templates/rust.jinja2 +++ b/glean_parser/templates/rust.jinja2 @@ -44,7 +44,7 @@ impl ExtraKeys for {{ obj.name|Camelize }}{{ suffix }} { /// {{ obj.description|wordwrap() | replace('\n', '\n/// ') }} #[rustfmt::skip] pub static {{ obj.name|snake_case }}: ::glean::private::__export::Lazy<::glean::private::PingType> = - ::glean::private::__export::Lazy::new(|| ::glean::private::PingType::new("{{ obj.name }}", {{ obj.include_client_id|rust }}, {{ obj.send_if_empty|rust }}, {{ obj.reason_codes|rust }})); + ::glean::private::__export::Lazy::new(|| ::glean::private::PingType::new("{{ obj.name }}", {{ obj.include_client_id|rust }}, {{ obj.send_if_empty|rust }}, {{ obj.precise_timestamps|rust }}, {{ obj.reason_codes|rust }})); {% endfor %} {% else %} pub mod {{ category.name|snake_case }} { diff --git a/glean_parser/templates/swift.jinja2 b/glean_parser/templates/swift.jinja2 index 10e2f6100..82ad37bf2 100644 --- a/glean_parser/templates/swift.jinja2 +++ b/glean_parser/templates/swift.jinja2 @@ -95,6 +95,7 @@ extension {{ namespace }} { name: {{ obj.name|swift }}, includeClientId: {{obj.include_client_id|swift}}, sendIfEmpty: {{obj.send_if_empty|swift}}, + preciseTimestamps: {{obj.precise_timestamps|swift}}, reasonCodes: {{obj.reason_codes|swift}} ) diff --git a/glean_parser/util.py b/glean_parser/util.py index 3b8b24cd7..a3926980e 100644 --- a/glean_parser/util.py +++ b/glean_parser/util.py @@ -552,6 +552,7 @@ def remove_output_params(d, output_params): "name", "include_client_id", "send_if_empty", + "precise_timestamps", "reason_codes", ]