Skip to content

Commit

Permalink
Extract event name and category more accurately (#1695)
Browse files Browse the repository at this point in the history
* Extract event name and category more accurately, and show it in UI

* Simplify method

Co-authored-by: Jan-Erik Rediger <jrediger@mozilla.com>

* Change the order of name and category to match the new return value

---------

Co-authored-by: Jan-Erik Rediger <jrediger@mozilla.com>
  • Loading branch information
Iinh and badboy authored May 5, 2023
1 parent 7e7a814 commit b1270fd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
8 changes: 7 additions & 1 deletion etl/glean_etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .glean import GleanApp
from .looker import get_looker_explore_metadata_for_metric, get_looker_explore_metadata_for_ping
from .search import create_metrics_search_js
from .utils import dump_json
from .utils import dump_json, get_event_name_and_category

# Various additional sources of metadata
ANNOTATIONS_URL = os.getenv(
Expand Down Expand Up @@ -374,6 +374,12 @@ def write_glean_metadata(output_dir, functions_dir, app_names=None):
app_tags_for_objects,
)

if metric.definition["type"] == "event":
app_metrics[metric.identifier]["event_info"] = {
"name": get_event_name_and_category(metric.identifier)[1],
"category": get_event_name_and_category(metric.identifier)[0],
}

# sort "send in pings" alphanumerically, except that `metrics`
# should always be first if present and `deletion-request`
# should be last
Expand Down
4 changes: 3 additions & 1 deletion etl/looker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import stringcase
from furl import furl

from etl.utils import get_event_name_and_category

from .bigquery import get_bigquery_column_name, get_bigquery_ping_table_name
from .glean import GLEAN_DISTRIBUTION_TYPES

Expand Down Expand Up @@ -115,7 +117,7 @@ def get_looker_explore_metadata_for_metric(
if not app.app.get("deprecated") and base_looker_explore:
looker_metric_link = None
if metric_type == "event":
(metric_category, metric_name) = metric.identifier.split(".", 1)
(metric_category, metric_name) = get_event_name_and_category(metric.identifier)
if base_looker_explore["name"] == "glean_event_counts":
looker_metric_link = furl(base_looker_explore["url"]).add(
{
Expand Down
16 changes: 16 additions & 0 deletions etl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ def dump_json(data):
2. We dump the data without spaces (since we want things as small as possible)
"""
return json.dumps(data, separators=(",", ":"), default=_serialize_sets)


def get_event_name_and_category(event_identifier: str):
"""Get the event name and category from an event identifier.
Event names cannot contain dots, only the category, so
splitting at the right most '.' will extract the category
and name, i.e. the name is the last part of the event
identifier, and the event category is everything before the
event name.
e.g. "newtab.search.ad.click_metric" ->
category = "newtab.search.ad"
name = "click_metric"
"""
return event_identifier.rsplit(".", maxsplit=1)
20 changes: 16 additions & 4 deletions src/pages/MetricDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@
const STMO_GLEAN_EVENT_QUERY_URL =
"https://sql.telemetry.mozilla.org/queries/91780/source";
const getSTMOQueryURL = (type, columnName, eventName, table) => {
const getSTMOQueryURL = (type, columnName, eventInfo, table) => {
if (type === "event") {
const [category, name] = eventName ? eventName.split(".") : [];
return `${STMO_GLEAN_EVENT_QUERY_URL}?p_event_category=${category}&p_event_name=${name}&p_table=${table}`;
return `${STMO_GLEAN_EVENT_QUERY_URL}?p_event_category=${eventInfo.category}&p_event_name=${eventInfo.name}&p_table=${table}`;
}
return `${STMO_GLEAN_QUERY_URL}?p_metric%20location=${columnName}&p_table=${table}`;
};
Expand Down Expand Up @@ -154,6 +153,13 @@
ping{metric.send_in_pings.length > 1 ? "s" : ""}.
</p>

{#if metric.type === "event"}
<p>
The event category is <code>{metric.event_info.category}</code> and event
name is <code>{metric.event_info.name}.</code>
</p>
{/if}

<MetadataTable
appName={params.app}
item={metric}
Expand Down Expand Up @@ -324,6 +330,12 @@
<CopyButton
textToCopy={selectedAppVariant.etl.bigquery_column_name}
/>
{:else}
(event.category=<code>{metric.event_info.category}</code>
<CopyButton textToCopy={metric.event_info.category} /> and event.name=<code
>{metric.event_info.name}</code
>
<CopyButton textToCopy={metric.event_info.name} />)
{/if}
</div>
</td>
Expand All @@ -343,7 +355,7 @@
href={getSTMOQueryURL(
metric.type,
selectedAppVariant.etl.bigquery_column_name,
pingData.looker.metric.name,
metric.event_info,
pingData.bigquery_table
)}>STMO</a
>
Expand Down

0 comments on commit b1270fd

Please sign in to comment.