Skip to content

Commit eb1d808

Browse files
committed
Address review comments
1 parent a70deda commit eb1d808

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* [#101](https://github.com/mozilla/glean.js/pull/101): BUGFIX: Only validate Debug View Tag and Source Tags when they are present.
66
* [#102](https://github.com/mozilla/glean.js/pull/102): BUGFIX: Include a Glean User-Agent header in all pings.
7-
* [#97](https://github.com/mozilla/glean.js/pull/97): Add support for labelled metric types (string, boolean and counter).
7+
* [#97](https://github.com/mozilla/glean.js/pull/97): Add support for labeled metric types (string, boolean and counter).
88

99
# v0.4.0 (2021-03-10)
1010

glean/src/core/metrics/database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class MetricsDatabase {
133133
}
134134

135135
const store = this._chooseStore(metric.lifetime);
136-
const storageKey = await metric.getAsyncIdentifier();
136+
const storageKey = await metric.identifier();
137137
for (const ping of metric.sendInPings) {
138138
const finalTransformFn = (v?: JSONValue): JSONValue => transformFn(v).get();
139139
await store.update([ping, metric.type, storageKey], finalTransformFn);
@@ -205,7 +205,7 @@ class MetricsDatabase {
205205
metric: MetricType
206206
): Promise<T | undefined> {
207207
const store = this._chooseStore(metric.lifetime);
208-
const storageKey = await metric.getAsyncIdentifier();
208+
const storageKey = await metric.identifier();
209209
const value = await store.get([ping, metric.type, storageKey]);
210210
if (!isUndefined(value) && !validateMetricInternalRepresentation<T>(metric.type, value)) {
211211
console.error(`Unexpected value found for metric ${storageKey}: ${JSON.stringify(value)}. Clearing.`);

glean/src/core/metrics/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ export abstract class MetricType implements CommonMetricData {
155155
* @returns The generated identifier. If `category` is empty, it's ommitted. Otherwise,
156156
* it's the combination of the metric's `category`, `name` and `label`.
157157
*/
158-
async getAsyncIdentifier(): Promise<string> {
158+
async identifier(): Promise<string> {
159159
const baseIdentifier = this.baseIdentifier();
160160

161161
// We need to use `isUndefined` and cannot use `(this.dynamicLabel)` because we want
162-
// empty strings to propagate as a dynamic labels, so that erros are potentially recorded.
162+
// empty strings to propagate as dynamic labels, so that erros are potentially recorded.
163163
if (!isUndefined(this.dynamicLabel)) {
164164
return await LabeledMetricType.getValidDynamicLabel(this);
165165
} else {
@@ -178,7 +178,7 @@ export abstract class MetricType implements CommonMetricData {
178178
}
179179

180180
/**
181-
* This is no-op internal metric representation.
181+
* This is a no-op internal metric representation.
182182
*
183183
* This can be used to instruct the validators to simply report
184184
* whatever is stored internally, without performing any specific

glean/src/core/metrics/types/labeled.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class LabeledMetricType<T extends SupportedLabeledTypes> {
5555
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5656
get: (_target: LabeledMetricType<T>, label: string): any => {
5757
if (labels) {
58-
return LabeledMetricType.createFromStaticLabel<typeof submetric>(meta, submetric, labels, label);
58+
return LabeledMetricType.createFromStaticLabel(meta, submetric, labels, label);
5959
}
6060

61-
return LabeledMetricType.createFromDynamicLabel<typeof submetric>(meta, submetric, label);
61+
return LabeledMetricType.createFromDynamicLabel(meta, submetric, label);
6262
}
6363
});
6464
}

glean/tests/core/metrics/labeled.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("LabeledMetric", function() {
3434
sendIfEmpty: false,
3535
});
3636

37-
const labeledCounterMetric = new LabeledMetricType<CounterMetricType>(
37+
const labeledCounterMetric = new LabeledMetricType(
3838
{
3939
category: "telemetry",
4040
name: "labeled_counter_metric",
@@ -79,7 +79,7 @@ describe("LabeledMetric", function() {
7979
sendIfEmpty: false,
8080
});
8181

82-
const labeledCounterMetric = new LabeledMetricType<CounterMetricType>(
82+
const labeledCounterMetric = new LabeledMetricType(
8383
{
8484
category: "telemetry",
8585
name: "labeled_counter_metric",
@@ -126,7 +126,7 @@ describe("LabeledMetric", function() {
126126
});
127127

128128
it("test __other__ label without predefined labels", async function() {
129-
const labeledCounterMetric = new LabeledMetricType<CounterMetricType>(
129+
const labeledCounterMetric = new LabeledMetricType(
130130
{
131131
category: "telemetry",
132132
name: "labeled_counter_metric",
@@ -151,7 +151,7 @@ describe("LabeledMetric", function() {
151151
});
152152

153153
it("test __other__ label without predefined labels before Glean initialization", async function() {
154-
const labeledCounterMetric = new LabeledMetricType<CounterMetricType>(
154+
const labeledCounterMetric = new LabeledMetricType(
155155
{
156156
category: "telemetry",
157157
name: "labeled_counter_metric",
@@ -181,7 +181,7 @@ describe("LabeledMetric", function() {
181181
});
182182

183183
it("Ensure invalid labels on labeled counter go to __other__", async function() {
184-
const labeledCounterMetric = new LabeledMetricType<CounterMetricType>(
184+
const labeledCounterMetric = new LabeledMetricType(
185185
{
186186
category: "telemetry",
187187
name: "labeled_counter_metric",
@@ -203,7 +203,7 @@ describe("LabeledMetric", function() {
203203
});
204204

205205
it("Ensure invalid labels on labeled boolean go to __other__", async function() {
206-
const labeledBooleanMetric = new LabeledMetricType<BooleanMetricType>(
206+
const labeledBooleanMetric = new LabeledMetricType(
207207
{
208208
category: "telemetry",
209209
name: "labeled_boolean_metric",
@@ -225,7 +225,7 @@ describe("LabeledMetric", function() {
225225
});
226226

227227
it("Ensure invalid labels on labeled string go to __other__", async function() {
228-
const labeledStringMetric = new LabeledMetricType<StringMetricType>(
228+
const labeledStringMetric = new LabeledMetricType(
229229
{
230230
category: "telemetry",
231231
name: "labeled_string_metric",
@@ -247,7 +247,7 @@ describe("LabeledMetric", function() {
247247
});
248248

249249
it("test labeled string metric type", async function() {
250-
const labeledStringMetric = new LabeledMetricType<StringMetricType>(
250+
const labeledStringMetric = new LabeledMetricType(
251251
{
252252
category: "telemetry",
253253
name: "labeled_string_metric",
@@ -269,7 +269,7 @@ describe("LabeledMetric", function() {
269269
});
270270

271271
it("test labeled boolean metric type", async function() {
272-
const metric = new LabeledMetricType<BooleanMetricType>(
272+
const metric = new LabeledMetricType(
273273
{
274274
category: "telemetry",
275275
name: "labeled_bool",
@@ -291,7 +291,7 @@ describe("LabeledMetric", function() {
291291
});
292292

293293
it("dynamic labels regex mismatch", async function() {
294-
const labeledCounterMetric = new LabeledMetricType<CounterMetricType>(
294+
const labeledCounterMetric = new LabeledMetricType(
295295
{
296296
category: "telemetry",
297297
name: "labeled_counter_metric",
@@ -320,7 +320,7 @@ describe("LabeledMetric", function() {
320320
});
321321

322322
it("dynamic labels regex allowed", async function() {
323-
const labeledCounterMetric = new LabeledMetricType<CounterMetricType>(
323+
const labeledCounterMetric = new LabeledMetricType(
324324
{
325325
category: "telemetry",
326326
name: "labeled_counter_metric",
@@ -350,7 +350,7 @@ describe("LabeledMetric", function() {
350350
});
351351

352352
it("seen labels get reloaded across initializations", async function() {
353-
const labeledCounterMetric = new LabeledMetricType<CounterMetricType>(
353+
const labeledCounterMetric = new LabeledMetricType(
354354
{
355355
category: "telemetry",
356356
name: "labeled_metric",

0 commit comments

Comments
 (0)