Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a link to GLAM for the selected metric #306

Merged
merged 4 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions scripts/build-glean-metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
import re

import glean
import stringcase
Expand All @@ -15,6 +16,31 @@ def _serialize_sets(obj):
return obj


# ETL specific snakecase taken from:
# https://github.com/mozilla/bigquery-etl/blob/master/bigquery_etl/util/common.py
#
# Search for all camelCase situations in reverse with arbitrary lookaheads.
REV_WORD_BOUND_PAT = re.compile(
r"""
\b # standard word boundary
|(?<=[a-z][A-Z])(?=\d*[A-Z]) # A7Aa -> A7|Aa boundary
|(?<=[a-z][A-Z])(?=\d*[a-z]) # a7Aa -> a7|Aa boundary
|(?<=[A-Z])(?=\d*[a-z]) # a7A -> a7|A boundary
""",
re.VERBOSE,
)


def etl_snake_case(line: str) -> str:
"""Convert a string into a snake_cased string."""
# replace non-alphanumeric characters with spaces in the reversed line
subbed = re.sub(r"[^\w]|_", " ", line[::-1])
# apply the regex on the reversed string
words = REV_WORD_BOUND_PAT.split(subbed)
# filter spaces between words and snake_case and reverse again
return "_".join([w.lower() for w in words if w.strip()])[::-1]


# First, get the apps we're using
apps = [app for app in glean.GleanApp.get_apps()]

Expand Down Expand Up @@ -78,6 +104,7 @@ def _serialize_sets(obj):
stable_ping_table_names=stable_ping_table_names,
metric_type=metric_type,
metric_table_name=f"metrics.{metric_type}.{metric_name_snakecase}",
glam_etl_name=etl_snake_case(metric.identifier),
)

open(os.path.join(app_metrics_dir, f"{metric.identifier}.json"), "w").write(
Expand Down
37 changes: 37 additions & 0 deletions src/pages/MetricDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@

const metricDataPromise = getMetricData(params.app, metricName);

function getGlamUrlTemplate(app) {
const map = {
fenix: {
product: "fenix",
app_id: "",
},
"firefox-android-beta": {
product: "fenix",
app_id: "beta",
},
"firefox-android-release": {
product: "fenix",
app_id: "release",
},
};
if (Object.keys(map).includes(app)) {
const p = map[app];
return function makeGlamUrl(metric) {
return `https://glam.telemetry.mozilla.org/${p.product}/probe/${metric}/explore?app_id=${p.app_id}`;
};
}

// The app isn't one GLAM supports so return nothing.
return undefined;
}

const glamUrl = getGlamUrlTemplate(params.app);

function getMetricDocumentationURI(type) {
const sourceDocs = "https://mozilla.github.io/glean/book/user/metrics/";
const links = {
Expand Down Expand Up @@ -209,6 +237,15 @@
{/each}
</td>
</tr>
{#if glamUrl && metric.bigquery_names.metric_type !== 'event'}
<tr>
<td>GLAM</td>
robhudson marked this conversation as resolved.
Show resolved Hide resolved
<td>
<a
href={glamUrl(metric.bigquery_names.glam_etl_name)}>{metric.bigquery_names.glam_etl_name}</a>
</td>
</tr>
{/if}
</table>
{:catch}
<NotFound pageName={metricName} itemType="metric" />
Expand Down