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 labeled metric types #97

Merged
merged 5 commits into from
Mar 15, 2021
Merged

Add labeled metric types #97

merged 5 commits into from
Mar 15, 2021

Conversation

Dexterp37
Copy link
Contributor

@Dexterp37 Dexterp37 commented Mar 9, 2021

This introduces the labelled metric types for string, boolean and counter types. The implementation closely follows what's in the Glean SDK, with no major deviation.

Note that this required adding a couple more functions to the database.

TODO:

  • Port test coverage.
  • Enable dynamic labels.
  • Add documentation.
  • Enforce label limits.
  • Enable different labelled metric types (instead of hardcoding)

glean/src/core/metrics/types/labeled.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/utils.ts Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Outdated Show resolved Hide resolved
@Dexterp37 Dexterp37 force-pushed the labeled branch 5 times, most recently from 264eb36 to 5b35e84 Compare March 12, 2021 14:08
@Dexterp37 Dexterp37 self-assigned this Mar 12, 2021
@Dexterp37 Dexterp37 marked this pull request as ready for review March 12, 2021 14:20
Copy link
Contributor

@brizental brizental left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is Friday EOD and I probably missing something in this review. Please consider this a "first pass" and I'll take a closer look on Monday 🧇

glean/src/core/metrics/index.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/index.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/index.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Outdated Show resolved Hide resolved
* whatever is stored internally, without performing any specific
* validation.
*/
export class PassthroughMetric extends Metric<JSONValue, JSONValue> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: PassThroughMetric?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to self: I don't understand why we need the PassthorughMetric at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I get it now. I was wrong when I assumed Labeled metrics did not need a Metric declaration. Even though we don't care about their internal representation, they need a Metric representation for generating the ping payload. I am sorry for the back and forth here, but I would prefer if instead of PassthrougMetric you made this LabeledMetric.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh, too bad :) Now, I could do that and move it back to the labeled metric implementation file. Unfortunately doing so will trigger a circular dependency that breaks the TS build :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, come on TS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if you move this line to somewhere after you define the Metric abstract class the error goes away.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this as requested and added a better comment.

glean/tests/core/metrics/labeled.spec.ts Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
glean/src/core/metrics/database.ts Show resolved Hide resolved
glean/src/core/metrics/database.ts Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Outdated Show resolved Hide resolved
glean/src/core/metrics/types/labeled.ts Show resolved Hide resolved
glean/tests/core/metrics/labeled.spec.ts Outdated Show resolved Hide resolved
This internally changes the id getter on the
`MetricType` to read from the store in case
of dyanmic labels, as done in the Glean SDK.
This is required in order to attempt recording to
Glean metrics before it gets initialized.
This supports string, boolean and counter labeled
types and ports over tests from the Kotlin implementation
in the SDK and the glean-core internals.
Copy link
Contributor

@brizental brizental left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go, assuming the PassthroughMetric comments are addressed.

@@ -10,6 +10,7 @@
* [#101](https://github.com/mozilla/glean.js/pull/101): BUGFIX: Only validate Debug View Tag and Source Tags when they are present.
* [#101](https://github.com/mozilla/glean.js/pull/101): BUGFIX: Only validate Debug View Tag and Source Tags when they are present.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have two entries here... Whathever, can be fixed when we make the next release.

@Dexterp37 Dexterp37 merged commit 647c5ad into mozilla:main Mar 15, 2021
@Dexterp37 Dexterp37 deleted the labeled branch March 15, 2021 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants