-
Notifications
You must be signed in to change notification settings - Fork 34
Bug 1701578 (Part 1) - Remove some circular dependencies #165
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
08503db
Move the `Metric` definition to its own file
Dexterp37 608ef35
Break a few more circular dependencies
Dexterp37 1e4a4a7
Do not depend on the Glean singleton in `EventsDatabase`
Dexterp37 593efda
Remove the duplicated 'Metrics' interface definition
Dexterp37 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import { JSONValue } from "../utils.js"; | ||
|
|
||
| /** | ||
| * The Metric class describes the shared behaviour amongst concrete metrics. | ||
| * | ||
| * A concrete metric will always have two possible representations: | ||
| * | ||
| * - `InternalRepresentation` | ||
| * - Is the format in which this metric will be stored in memory. | ||
| * - This format may contain extra metadata, in order to allow deserializing of this data for testing purposes. | ||
| * - `PayloadRepresentation` | ||
| * - Is the format in which this metric will be represented in the ping payload. | ||
| * - This format must be the exact same as described in [the Glean schema](https://github.com/mozilla-services/mozilla-pipeline-schemas/blob/master/schemas/glean/glean/glean.1.schema.json). | ||
| */ | ||
|
|
||
| export abstract class Metric< | ||
| InternalRepresentation extends JSONValue, | ||
| PayloadRepresentation extends JSONValue | ||
| > { | ||
| protected _inner: InternalRepresentation; | ||
|
|
||
| constructor(v: unknown) { | ||
| if (!this.validate(v)) { | ||
| throw new Error("Unable to create new Metric instance, values is in unexpected format."); | ||
| } | ||
|
|
||
| this._inner = v; | ||
| } | ||
|
|
||
| /** | ||
| * Gets this metrics value in its internal representation. | ||
| * | ||
| * @returns The metric value. | ||
| */ | ||
| get(): InternalRepresentation { | ||
| return this._inner; | ||
| } | ||
|
|
||
| /** | ||
| * Sets this metrics value. | ||
| * | ||
| * @param v The value to set, must be in the exact internal representation of this metric. | ||
| * | ||
| * @throws In case the metric is not in the expected format. | ||
| */ | ||
| set(v: unknown): void { | ||
| if (!this.validate(v)) { | ||
| console.error(`Unable to set metric to ${JSON.stringify(v)}. Value is in unexpected format. Ignoring.`); | ||
| return; | ||
| } | ||
|
|
||
| this._inner = v; | ||
| } | ||
|
|
||
| /** | ||
| * Validates that a given value is in the correct format for this metrics internal representation. | ||
| * | ||
| * @param v The value to verify. | ||
| * | ||
| * @returns A special Typescript value (which compiles down to a boolean) | ||
| * stating whether `v` is of the correct type. | ||
| */ | ||
| abstract validate(v: unknown): v is InternalRepresentation; | ||
|
|
||
| /** | ||
| * Gets this metrics value in its payload representation. | ||
| * | ||
| * @returns The metric value. | ||
| */ | ||
| abstract payload(): PayloadRepresentation; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import { JSONValue } from "../utils.js"; | ||
|
|
||
| export interface Metrics { | ||
| [aMetricType: string]: { | ||
| [aMetricIdentifier: string]: JSONValue; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import { Metrics } from "../metrics/metrics_interface.js"; | ||
| import { JSONObject, JSONArray } from "../utils.js"; | ||
|
|
||
| export interface PingInfo extends JSONObject { | ||
| seq: number, | ||
| start_time: string, | ||
| end_time: string, | ||
| reason?: string, | ||
| } | ||
|
|
||
| export interface ClientInfo extends JSONObject { | ||
| client_id?: string, | ||
| locale?: string, | ||
| device_model?: string, | ||
| device_manufacturer?: string, | ||
| app_channel?: string, | ||
| // Even though all the next fields are required by the schema | ||
| // we can't guarantee that they will be present. | ||
| // Active discussion about this is happening on Bug 1685705. | ||
| app_build?: string, | ||
| app_display_version?: string, | ||
| architecture?: string, | ||
| first_run_date?: string, | ||
| os?: string, | ||
| os_version?: string, | ||
| telemetry_sdk_build: string | ||
| } | ||
|
|
||
| /** | ||
| * This definition must be in sync with | ||
| * the Glean ping [schema](https://github.com/mozilla-services/mozilla-pipeline-schemas/blob/master/schemas/glean/glean/glean.1.schema.json) | ||
| */ | ||
| export interface PingPayload extends JSONObject { | ||
| ping_info: PingInfo, | ||
| client_info: ClientInfo, | ||
| metrics?: Metrics, | ||
| events?: JSONArray, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen multiple projects that have a
types/folder with all the types. Not for this PR, but I wonder if we could benefit form that. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it might make sense :)