From f31535f28c15e00f688be75e2c2066a453270501 Mon Sep 17 00:00:00 2001 From: Arkadiusz Komarzewski Date: Fri, 26 Jul 2024 17:57:24 +0200 Subject: [PATCH] Stringify event extra values in server JS template --- CHANGELOG.md | 2 ++ glean_parser/templates/javascript_server.jinja2 | 2 +- glean_parser/templates/ruby_server.jinja2 | 2 +- tests/data/server_events_compare.rb | 6 ++++-- tests/data/server_metrics_with_event.yaml | 5 +++++ tests/test-py/test.py | 1 + tests/test_javascript_server.py | 1 + tests/test_ruby_server.py | 1 + 8 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aa712a3..e22734b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix JS and Ruby server templates to correctly send event extra values as strings ([DENG-4405](https://mozilla-hub.atlassian.net/browse/DENG-4405)) + ## 14.3.0 - Add the `module_spec` option to the javascript_server outputter ([#726](https://github.com/mozilla/glean_parser/pull/726)) diff --git a/glean_parser/templates/javascript_server.jinja2 b/glean_parser/templates/javascript_server.jinja2 index 83881879..ee7b2adb 100644 --- a/glean_parser/templates/javascript_server.jinja2 +++ b/glean_parser/templates/javascript_server.jinja2 @@ -234,7 +234,7 @@ class {{ ping|event_class_name(metrics_by_type) }} { {% if event.extra_keys %} extra: { {% for extra, metadata in event.extra_keys.items() %} - {{ extra }}: {{ extra }}, + {{ extra }}: String({{ extra }}), {% endfor %} }, {% endif %} diff --git a/glean_parser/templates/ruby_server.jinja2 b/glean_parser/templates/ruby_server.jinja2 index d5c4f30c..af85b70b 100644 --- a/glean_parser/templates/ruby_server.jinja2 +++ b/glean_parser/templates/ruby_server.jinja2 @@ -155,7 +155,7 @@ module Glean 'timestamp' => (Time.now.utc.to_f * 1000).to_i, 'extra' => [ {% for extra, metadata in event.extra_keys.items() %} - ['{{ extra }}', {{ extra }}], + ['{{ extra }}', {{ extra }}.to_s], {% endfor %} ].to_h, }, diff --git a/tests/data/server_events_compare.rb b/tests/data/server_events_compare.rb index 11dc2a12..314acdde 100644 --- a/tests/data/server_events_compare.rb +++ b/tests/data/server_events_compare.rb @@ -103,6 +103,7 @@ def record( # extras to pass into event detail object_type:, object_state:, + linking:, # The user's FxA account ID, if available. identifiers_fxa_account_id:, # full user_agent value from controller context @@ -116,8 +117,9 @@ def record( 'name' => 'object_update', 'timestamp' => (Time.now.utc.to_f * 1000).to_i, 'extra' => [ - ['object_type', object_type], - ['object_state', object_state], + ['object_type', object_type.to_s], + ['object_state', object_state.to_s], + ['linking', linking.to_s], ].to_h, }}, ] diff --git a/tests/data/server_metrics_with_event.yaml b/tests/data/server_metrics_with_event.yaml index 26fbea0a..ea9e3492 100644 --- a/tests/data/server_metrics_with_event.yaml +++ b/tests/data/server_metrics_with_event.yaml @@ -48,3 +48,8 @@ backend: description: > A JSON representation of the latest state of the object. type: string + linking: + description: > + Indicates the initial linking of the Mozilla account and + the third-party account. + type: boolean diff --git a/tests/test-py/test.py b/tests/test-py/test.py index 831e55ef..ca880df4 100644 --- a/tests/test-py/test.py +++ b/tests/test-py/test.py @@ -13,4 +13,5 @@ identifiers_fxa_account_id="test-py-project", object_type="some_object_type", object_state="some_object_state", + linking=True, ) diff --git a/tests/test_javascript_server.py b/tests/test_javascript_server.py index 6685baee..59d3b203 100644 --- a/tests/test_javascript_server.py +++ b/tests/test_javascript_server.py @@ -161,6 +161,7 @@ def test_logging_events_ping_with_event_metrics(tmp_path): identifiers_fxa_account_id: 'abc', object_type: 'unknown', object_state: 'great', + linking: true, }); """ diff --git a/tests/test_ruby_server.py b/tests/test_ruby_server.py index 1e892cdb..c4000e89 100644 --- a/tests/test_ruby_server.py +++ b/tests/test_ruby_server.py @@ -133,6 +133,7 @@ def test_run_logging(tmp_path): events.backend_object_update.record( object_type: "type", object_state: "state", + linking: true, identifiers_fxa_account_id: nil, user_agent: "glean-test/1.0", ip_address: "127.0.0.1"