Closed Bug 1540844 Opened 7 years ago Closed 7 years ago

[glean] The `metrics.*` API is technically public, but isn't intended as such

Categories

(Toolkit :: Telemetry, defect, P1)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: mdroettboom, Assigned: mdroettboom)

Details

(Whiteboard: [telemetry:mobilesdk:m7])

Attachments

(4 files)

The various *MetricType classes are technically public so that they can be used from the code that glean_parser generates from the metrics.yaml, since it exists in the applications package namespace.

We've already seen some unintended use of these classes in the wild.

This bug is to investigate alternatives and remediations to this problem.

(1) Improve the docs

(2) Use a naming convention that makes their intended use more clear

(3) Some clever way to make them private, but still accessible from the generated code. (Does using inheritance rather than instantiation help?)

(In reply to Michael Droettboom [:mdroettboom] from comment #0)

The various *MetricType classes are technically public so that they can be used from the code that glean_parser generates from the metrics.yaml, since it exists in the applications package namespace.

We've already seen some unintended use of these classes in the wild.

One of them being this: https://github.com/mozilla-mobile/fenix/blob/cf0d1355b5844665085687761037a28645530b41/app/src/main/java/org/mozilla/fenix/components/metrics/GleanMetricsService.kt#L7

This bug is to investigate alternatives and remediations to this problem.

(1) Improve the docs

(2) Use a naming convention that makes their intended use more clear

I think the above are proper solution we could enable in the short term.

(3) Some clever way to make them private, but still accessible from the generated code. (Does using inheritance rather than instantiation help?)

This might be a rabbit hole :( We could probably break this bug in 2: handling (1) and (2) here, having the investigation for (3) in a follow-up. I feel like (1)/(2) are important enough to deal with them before other people start relying on internals.

Priority: -- → P1
Whiteboard: [telemetry:mobilesdk:m?] → [telemetry:mobilesdk:m7]
Assignee: nobody → mdroettboom

Great. The plan of attack here is to submit and merge a PR against Fenix to remove this unintended usage. Once we aren't at risk of breaking Fenix, we can attack the changes to the naming convention.

The changes to Fenix have been merged, so we're free to monkey around with this "not-so-public" API.

So, brainstorm time.

The docs part should be obvious -- we just need to add a section to the metrics docs somewhere.

As for any changes in the code: We could move the glean.metrics namespace to glean.PRIVATE?

There's perhaps more complex things we could do, but they might be high risk and effort and low reward. Let's just brainstorm low-hanging fruit things for now...

Flags: needinfo?(tlong)
Flags: needinfo?(alessio.placitelli)

(In reply to Michael Droettboom [:mdroettboom] from comment #5)

As for any changes in the code: We could move the glean.metrics namespace to glean.PRIVATE?

I think either glean.PRIVATE or glean.INTERNALS should be ok (all lowercase). I don't have a strong opinion on which one :)

There's perhaps more complex things we could do, but they might be high risk and effort and low reward. Let's just brainstorm low-hanging fruit things for now...

I agree with you, doesn't make much sense to go hardcore on this right now. One other thing we could do, to be more explicit, is to use annotations. We could tag the metrics with some special "DoNotUseThisIsInternalEvenIfPublic" and suppress that in glean_parsers. What do you think?

Flags: needinfo?(alessio.placitelli)

@RestrictTo.LIBRARY Seems to be a good candidate for annotations, but as we just learned, it does't do more than "suggest" against usage in the IDE and is not enforced by the compiler.

I'm good with the package shuffling idea, for either private or internals

Flags: needinfo?(tlong)

(In reply to Travis Long from comment #7)

@RestrictTo.LIBRARY Seems to be a good candidate for annotations, but as we just learned, it does't do more than "suggest" against usage in the IDE and is not enforced by the compiler.

Good! I like this one. As long as we show some warning it's fine for me

Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: