Skip to content

Commit 8efbe64

Browse files
committed
Merge branch 'release-v0.13.0' into release
2 parents f56b6fb + 28974b4 commit 8efbe64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5617
-6849
lines changed

.circleci/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ jobs:
1212
- image: cimg/node:16.1.0
1313
steps:
1414
- checkout
15+
- run:
16+
name: Check that package-lock.json is updated as needed
17+
command: |
18+
npm install --prefix ./glean --package-lock-only
19+
if ! git diff --exit-code HEAD -- glean/package-lock.json; then
20+
echo "=================================================="
21+
echo "The committed package-lock.json is out-dated."
22+
echo "Please regenerate package-lock.json using"
23+
echo " npm i --package-lock-only"
24+
echo "Commit the modified file and push."
25+
echo "=================================================="
26+
exit 1
27+
fi
1528
- run:
1629
name: Install Javascript dependencies
1730
command: npm --prefix ./glean install

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Unreleased changes
22

3-
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.12.0...main)
3+
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.13.0...main)
4+
5+
# v0.13.0 (2021-05-18)
6+
7+
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.12.0...v0.13.0)
8+
9+
* [#313](https://github.com/mozilla/glean.js/pull/313): Implement error recording mechanism and error checking testing API.
10+
* [#319](https://github.com/mozilla/glean.js/pull/319): BUGFIX: Do not allow recording floats with the quantity and counter metric types.
411

512
# v0.12.0 (2021-05-11)
613

glean/package-lock.json

Lines changed: 679 additions & 464 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glean/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mozilla/glean",
3-
"version": "0.12.0",
3+
"version": "0.13.0",
44
"description": "An implementation of the Glean SDK, a modern cross-platform telemetry client, for Javascript environments.",
55
"type": "module",
66
"exports": {
@@ -81,7 +81,7 @@
8181
"eslint-plugin-json": "^3.0.0",
8282
"eslint-plugin-mocha": "^8.0.0",
8383
"eslint-plugin-notice": "^0.9.10",
84-
"geckodriver": "^1.22.1",
84+
"geckodriver": "^2.0.0",
8585
"gh-pages": "^3.1.0",
8686
"jsdom": "16.5.3",
8787
"jsdom-global": "3.0.2",

glean/src/cli.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ function getSystemPythonBinName(): string {
8181
* Note that this directory changes depending on the host OS.
8282
*
8383
* @param venvRoot the root path of the virtual environment.
84-
*
8584
* @returns the full path to the directory containing the python
8685
* binaries in the virtual environment.
8786
*/
@@ -97,7 +96,6 @@ function getPythonVenvBinariesPath(venvRoot: string): string {
9796
* Checks if a Python virtual environment is available.
9897
*
9998
* @param venvPath the Python virtual environment directory.
100-
*
10199
* @returns `true` if the Python virtual environment exists and
102100
* is accessible, `false` otherwise.
103101
*/
@@ -123,7 +121,6 @@ async function checkPythonVenvExists(venvPath: string): Promise<boolean> {
123121
* Uses the system's Python interpreter to create a Python3 virtual environment.
124122
*
125123
* @param venvPath the directory in which to create the virtual environment.
126-
*
127124
* @returns `true` if the environment was correctly created, `false` otherwise.
128125
*/
129126
async function createPythonVenv(venvPath: string): Promise<boolean> {

glean/src/core/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const GLEAN_SCHEMA_VERSION = 1;
88
//
99
// PACKAGE_VERSION is defined as a global by webpack,
1010
// we need a default here for testing when the app is not build with webpack.
11-
export const GLEAN_VERSION = "0.12.0";
11+
export const GLEAN_VERSION = "0.13.0";
1212

1313
// The name of a "ping" that will include Glean ping_info metrics,
1414
// such as ping sequence numbers.

glean/src/core/context.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Dispatcher from "./dispatcher.js";
77
import type MetricsDatabase from "./metrics/database";
88
import type EventsDatabase from "./metrics/events_database";
99
import type PingsDatabase from "./pings/database";
10+
import type ErrorManager from "./error";
1011

1112
/**
1213
* This class holds all of the Glean singleton's state and internal dependencies.
@@ -29,6 +30,10 @@ export class Context {
2930
private _metricsDatabase!: MetricsDatabase;
3031
private _eventsDatabase!: EventsDatabase;
3132
private _pingsDatabase!: PingsDatabase;
33+
// The reason this was added to the Context,
34+
// is to avoid a circular dependency between
35+
// the ErrorManager's module and the CounterMetricType module.
36+
private _errorManager!: ErrorManager;
3237

3338
private _applicationId!: string;
3439
private _initialized: boolean;
@@ -48,7 +53,7 @@ export class Context {
4853
}
4954

5055
/**
51-
* **Test-only API**
56+
* Test-only API**
5257
*
5358
* Resets the Context to an uninitialized state.
5459
*/
@@ -113,6 +118,14 @@ export class Context {
113118
Context.instance._pingsDatabase = db;
114119
}
115120

121+
static get errorManager(): ErrorManager {
122+
return Context.instance._errorManager;
123+
}
124+
125+
static set errorManager(db: ErrorManager) {
126+
Context.instance._errorManager = db;
127+
}
128+
116129
static get applicationId(): string {
117130
return Context.instance._applicationId;
118131
}

glean/src/core/dispatcher.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ class Dispatcher {
164164
* @param command The command to enqueue.
165165
* @param priorityTask Whether or not this task is a priority task
166166
* and should be enqueued at the front of the queue.
167-
*
168167
* @returns Wheter or not the task was queued.
169168
*/
170169
private launchInternal(command: Command, priorityTask = false): boolean {
@@ -272,7 +271,7 @@ class Dispatcher {
272271
}
273272

274273
/**
275-
* **Test-Only API**
274+
* Test-Only API**
276275
*
277276
* Returns a promise that resolves once the current task execution in finished.
278277
*
@@ -286,7 +285,7 @@ class Dispatcher {
286285
}
287286

288287
/**
289-
* **Test-Only API**
288+
* Test-Only API**
290289
*
291290
* Returns the dispatcher back to an uninitialized state.
292291
*
@@ -316,7 +315,6 @@ class Dispatcher {
316315
* This is important in order not to hang forever in case the dispatcher is stopped.
317316
*
318317
* @param task The task to launch.
319-
*
320318
* @returns A promise which only resolves once the task is done being executed
321319
* or is guaranteed to not be executed ever i.e. if the queue gets cleared.
322320
*/

glean/src/core/error/error_type.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
/**
6+
* The possible error types for metric recording.
7+
*/
8+
export enum ErrorType {
9+
// For when the value to be recorded does not match the metric-specific restrictions
10+
InvalidValue = "invalid_value",
11+
// For when the label of a labeled metric does not match the restrictions
12+
InvalidLabel = "invalid_label",
13+
// For when the metric caught an invalid state while recording
14+
InvalidState = "invalid_state",
15+
// For when the value to be recorded overflows the metric-specific upper range
16+
InvalidOverflow = "invalid_overflow",
17+
}

glean/src/core/error/index.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import type { MetricType } from "../metrics";
6+
import type { ErrorType } from "./error_type.js";
7+
import CounterMetricType from "../metrics/types/counter.js";
8+
import { combineIdentifierAndLabel, stripLabel } from "../metrics/types/labeled.js";
9+
10+
/**
11+
* For a given metric, get the metric in which to record errors.
12+
*
13+
* # Important
14+
*
15+
* Errors do not adhere to the usual "maximum label" restriction.
16+
*
17+
* @param metric The metric to record an error for.
18+
* @param error The error type to record.
19+
* @returns The metric to record to.
20+
*/
21+
function getErrorMetricForMetric(metric: MetricType, error: ErrorType): CounterMetricType {
22+
const identifier = metric.baseIdentifier();
23+
const name = stripLabel(identifier);
24+
25+
// We don't use the labeled metric type here,
26+
// because we want to bypass the max number of allowed labels.
27+
return new CounterMetricType({
28+
name: combineIdentifierAndLabel(error, name),
29+
category: "glean.error",
30+
lifetime: "ping",
31+
// TODO: Also add the metric ping to the list. Depends on Bug 1710838.
32+
sendInPings: metric.sendInPings,
33+
disabled: false,
34+
});
35+
}
36+
37+
export default class ErrorManager {
38+
/**
39+
* Records an error into Glean.
40+
*
41+
* Errors are recorded as labeled counters in the `glean.error` category.
42+
*
43+
* @param metric The metric to record an error for.
44+
* @param error The error type to record.
45+
* @param message The message to log. This message is not sent with the ping.
46+
* It does not need to include the metric id, as that is automatically
47+
* prepended to the message.
48+
* @param numErrors The number of errors of the same type to report.
49+
*/
50+
async record (
51+
metric: MetricType,
52+
error: ErrorType,
53+
message: string,
54+
numErrors = 1
55+
): Promise<void> {
56+
const errorMetric = getErrorMetricForMetric(metric, error);
57+
console.warn(`${metric.baseIdentifier()}: ${message}`);
58+
if (numErrors > 0) {
59+
await CounterMetricType._private_addUndispatched(errorMetric, numErrors);
60+
} else {
61+
// TODO: Throw error only when in test mode. Depends on Bug 1682771.
62+
}
63+
}
64+
65+
/**
66+
* Gets the number of recorded errors for the given metric and error type.
67+
*
68+
* @param metric The metric to get the number of errors for.
69+
* @param error The error type to get count of.
70+
* @param ping The ping from which we want to retrieve the number of recorded errors.
71+
* Defaults to the first value in `sendInPings`.
72+
* @returns The number of errors reported.
73+
*/
74+
async testGetNumRecordedErrors (
75+
metric: MetricType,
76+
error: ErrorType,
77+
ping?: string
78+
): Promise<number> {
79+
const errorMetric = getErrorMetricForMetric(metric, error);
80+
const numErrors = await errorMetric.testGetValue(ping);
81+
return numErrors || 0;
82+
}
83+
}
84+

0 commit comments

Comments
 (0)