From a2e65f4b4cc406f6e40795e1c2a0407bc90c9390 Mon Sep 17 00:00:00 2001 From: Anna Scholtz Date: Wed, 20 Mar 2024 13:01:31 -0700 Subject: [PATCH] Support minimal Glean pings (#923) Co-authored-by: wil stuckey --- generator/views/glean_ping_view.py | 53 ++++++++++++++++++------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/generator/views/glean_ping_view.py b/generator/views/glean_ping_view.py index 2a42492..bf6365e 100644 --- a/generator/views/glean_ping_view.py +++ b/generator/views/glean_ping_view.py @@ -101,6 +101,26 @@ class GleanPingView(PingView): view_label = f"{category} - {name}" metric_hidden = "no" if metric.is_in_source() else "yes" + measures = [ + { + "name": "count", + "type": "sum", + "sql": "${value}", + "hidden": metric_hidden, + } + ] + + if client_id_field is not None: + # client_id field is missing for pings with minimal Glean schema + measures.append( + { + "name": "client_count", + "type": "count_distinct", + "sql": f"case when ${{value}} > 0 then ${{{self.name}.{client_id_field}}} end", + "hidden": metric_hidden, + } + ) + join_view = { "name": view_name, "label": view_label, @@ -136,20 +156,7 @@ class GleanPingView(PingView): "hidden": "yes", }, ], - "measures": [ - { - "name": "count", - "type": "sum", - "sql": "${value}", - "hidden": metric_hidden, - }, - { - "name": "client_count", - "type": "count_distinct", - "sql": f"case when ${{value}} > 0 then ${{{self.name}.{client_id_field}}} end", - "hidden": metric_hidden, - }, - ], + "measures": measures, } suggest_view = { "name": suggest_name, @@ -410,15 +417,19 @@ class GleanPingView(PingView): "sql": f"${{{dimension_name}}}", "links": self._get_links(dimension), }, - { - "name": f"{name}_client_count", - "type": "count_distinct", - "filters": [{dimension_name: ">0"}], - "sql": f"${{{client_id_field}}}", - "links": self._get_links(dimension), - }, ] + if client_id_field is not None: + measures += [ + { + "name": f"{name}_client_count", + "type": "count_distinct", + "filters": [{dimension_name: ">0"}], + "sql": f"${{{client_id_field}}}", + "links": self._get_links(dimension), + }, + ] + # check if there are any duplicate values names = [measure["name"] for measure in measures] duplicates = [k for k, v in Counter(names).items() if v > 1]