Skip to content
New issue

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

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

Already on GitHub? # to your account

Bug 1913129 - Remove Geckoview Streaming helper code #743

Merged
merged 1 commit into from
Aug 14, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- **Breaking change:** Updating Kotlin template import statement as part of removing `service-glean` from Android Components. ([bug 1906941](https://bugzilla.mozilla.org/show_bug.cgi?id=1906941))
- **Breaking change:** Do not generate Geckoview Streaming helper code ([#743](https://github.com/mozilla/glean_parser/pull/743))

## 14.5.2

Expand Down
105 changes: 0 additions & 105 deletions glean_parser/kotlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Outputter to generate Kotlin code for metrics.
"""

from collections import OrderedDict
import enum
import json
from pathlib import Path
Expand All @@ -17,9 +16,7 @@
from . import __version__
from . import metrics
from . import pings
from . import tags
from . import util
from .util import DictWrapper


def kotlin_datatypes_filter(value: util.JSONType) -> str:
Expand Down Expand Up @@ -179,105 +176,6 @@ def generate_build_date(date: Optional[str]) -> str:
return f'Calendar.getInstance(TimeZone.getTimeZone("GMT+0")).also {{ cal -> cal.set({components}) }}' # noqa


def output_gecko_lookup(
objs: metrics.ObjectTree, output_dir: Path, options: Optional[Dict[str, Any]] = None
) -> None:
"""
Given a tree of objects, generate a Kotlin map between Gecko histograms and
Glean SDK metric types.

:param objects: A tree of objects (metrics and pings) as returned from
`parser.parse_objects`.
:param output_dir: Path to an output directory to write to.
:param options: options dictionary, with the following optional keys:

- `namespace`: The package namespace to declare at the top of the
generated files. Defaults to `GleanMetrics`.
- `glean_namespace`: The package namespace of the glean library itself.
This is where glean objects will be imported from in the generated
code.
"""
if options is None:
options = {}

template = util.get_jinja2_template(
"kotlin.geckoview.jinja2",
filters=(
("kotlin", kotlin_datatypes_filter),
("type_name", type_name),
("class_name", class_name),
),
)

namespace = options.get("namespace", "GleanMetrics")
glean_namespace = options.get("glean_namespace", "mozilla.components.service.glean")

# Build a dictionary that contains data for metrics that are
# histogram-like/scalar-like and contain a gecko_datapoint, with this format:
#
# {
# "histograms": {
# "category": [
# {"gecko_datapoint": "the-datapoint", "name": "the-metric-name"},
# ...
# ],
# ...
# },
# "other-type": {}
# }
gecko_metrics: Dict[str, Dict[str, List[Dict[str, str]]]] = DictWrapper()

# Define scalar-like types.
SCALAR_LIKE_TYPES = ["boolean", "string", "quantity"]

for category_key, category_val in objs.items():
# Support exfiltration of Gecko metrics from products using both the
# Glean SDK and GeckoView. See bug 1566356 for more context.
for metric in category_val.values():
# This is not a Gecko metric, skip it.
if (
isinstance(metric, pings.Ping)
or isinstance(metric, tags.Tag)
or not getattr(metric, "gecko_datapoint", False)
):
continue

# Put scalars in their own categories, histogram-like in "histograms" and
# categorical histograms in "categoricals".
type_category = "histograms"
if metric.type in SCALAR_LIKE_TYPES:
type_category = metric.type
elif metric.type == "labeled_counter":
# Labeled counters with a 'gecko_datapoint' property
# are categorical histograms.
type_category = "categoricals"

gecko_metrics.setdefault(type_category, OrderedDict())
gecko_metrics[type_category].setdefault(category_key, [])

gecko_metrics[type_category][category_key].append(
{"gecko_datapoint": metric.gecko_datapoint, "name": metric.name}
)

if not gecko_metrics:
# Bail out and don't create a file if no gecko metrics
# are found.
return

filepath = output_dir / "GleanGeckoMetricsMapping.kt"
with filepath.open("w", encoding="utf-8") as fd:
fd.write(
template.render(
parser_version=__version__,
gecko_metrics=gecko_metrics,
namespace=namespace,
glean_namespace=glean_namespace,
)
)
# Jinja2 squashes the final newline, so we explicitly add it
fd.write("\n")


def output_kotlin(
objs: metrics.ObjectTree, output_dir: Path, options: Optional[Dict[str, Any]] = None
) -> None:
Expand Down Expand Up @@ -376,6 +274,3 @@ def output_kotlin(
)
# Jinja2 squashes the final newline, so we explicitly add it
fd.write("\n")

# TODO: Maybe this should just be a separate outputter?
output_gecko_lookup(objs, output_dir, options)
124 changes: 0 additions & 124 deletions glean_parser/templates/kotlin.geckoview.jinja2

This file was deleted.

133 changes: 0 additions & 133 deletions tests/data/gecko.yaml

This file was deleted.

Loading