@mozilla/glean
Advanced tools
Comparing version 3.0.0 to 4.0.0-pre.0
export const GLEAN_SCHEMA_VERSION = 1; | ||
export const GLEAN_VERSION = "3.0.0"; | ||
export const GLEAN_VERSION = "4.0.0-pre.0"; | ||
export const PING_INFO_STORAGE = "glean_ping_info"; | ||
@@ -4,0 +4,0 @@ export const CLIENT_INFO_STORAGE = "glean_client_info"; |
@@ -1,2 +0,1 @@ | ||
import Dispatcher from "./dispatcher.js"; | ||
import log, { LoggingLevel } from "./log.js"; | ||
@@ -10,3 +9,2 @@ const LOG_TAG = "core.Context"; | ||
this.startTime = new Date(); | ||
this.dispatcher = new Dispatcher(); | ||
} | ||
@@ -22,5 +20,2 @@ static get instance() { | ||
} | ||
static get dispatcher() { | ||
return Context.instance.dispatcher; | ||
} | ||
static get uploadEnabled() { | ||
@@ -144,6 +139,2 @@ if (typeof Context.instance.uploadEnabled === "undefined") { | ||
} | ||
static isPlatformSync() { | ||
var _a; | ||
return ((_a = Context.instance.platform) === null || _a === void 0 ? void 0 : _a.name) === "web"; | ||
} | ||
static getSupportedMetric(type) { | ||
@@ -150,0 +141,0 @@ return Context.instance.supportedMetrics[type]; |
import { Context } from "../context.js"; | ||
import { isUndefined, testOnlyCheck } from "../utils.js"; | ||
import { getValidDynamicLabel, getValidDynamicLabelSync } from "./types/labeled.js"; | ||
import { getValidDynamicLabel } from "./types/labeled.js"; | ||
export class MetricType { | ||
@@ -25,6 +25,6 @@ constructor(type, meta, metricCtor) { | ||
} | ||
async identifier() { | ||
identifier() { | ||
const baseIdentifier = this.baseIdentifier(); | ||
if (!isUndefined(this.dynamicLabel)) { | ||
return await getValidDynamicLabel(this); | ||
return getValidDynamicLabel(this); | ||
} | ||
@@ -35,15 +35,6 @@ else { | ||
} | ||
identifierSync() { | ||
const baseIdentifier = this.baseIdentifier(); | ||
if (!isUndefined(this.dynamicLabel)) { | ||
return getValidDynamicLabelSync(this); | ||
} | ||
else { | ||
return baseIdentifier; | ||
} | ||
} | ||
shouldRecord(uploadEnabled) { | ||
return uploadEnabled && !this.disabled; | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = this.sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetNumRecordedErrors")) { | ||
@@ -50,0 +41,0 @@ return Context.errorManager.testGetNumRecordedErrors(this, errorType, ping); |
@@ -14,6 +14,3 @@ import { Context } from "../context.js"; | ||
} | ||
async recordError(metric) { | ||
await Context.errorManager.record(metric, this.type, this.message); | ||
} | ||
recordErrorSync(metric) { | ||
recordError(metric) { | ||
Context.errorManager.record(metric, this.type, this.message); | ||
@@ -20,0 +17,0 @@ } |
@@ -43,26 +43,2 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
set(value) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(value); | ||
} | ||
else { | ||
this.setAsync(value); | ||
} | ||
} | ||
setAsync(value) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
const metric = new BooleanMetric(value); | ||
await Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
}); | ||
} | ||
setSync(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -77,13 +53,9 @@ return; | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -100,6 +72,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -106,0 +78,0 @@ } |
@@ -40,8 +40,16 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
add(amount) { | ||
if (Context.isPlatformSync()) { | ||
this.addSync(amount); | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
else { | ||
this.addAsync(amount); | ||
if (isUndefined(amount)) { | ||
amount = 1; | ||
} | ||
try { | ||
Context.metricsDatabase.transform(this, this.transformFn(amount)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
@@ -62,44 +70,5 @@ transformFn(amount) { | ||
} | ||
addAsync(amount) { | ||
Context.dispatcher.launch(async () => this.addUndispatched(amount)); | ||
} | ||
async addUndispatched(amount) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
if (isUndefined(amount)) { | ||
amount = 1; | ||
} | ||
try { | ||
await Context.metricsDatabase.transform(this, this.transformFn(amount)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
} | ||
addSync(amount) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
if (isUndefined(amount)) { | ||
amount = 1; | ||
} | ||
try { | ||
Context.metricsDatabase.transform(this, this.transformFn(amount)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -116,6 +85,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -122,0 +91,0 @@ } |
@@ -89,8 +89,17 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
accumulateSamples(samples) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(samples); | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
else { | ||
this.setAsync(samples); | ||
try { | ||
Context.metricsDatabase.transform(this, this.transformFn(samples)); | ||
const numNegativeSamples = getNumNegativeSamples(samples); | ||
if (numNegativeSamples > 0) { | ||
Context.errorManager.record(this, ErrorType.InvalidValue, `Accumulated ${numNegativeSamples} negative samples`, numNegativeSamples); | ||
} | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
@@ -115,44 +124,5 @@ transformFn(samples) { | ||
} | ||
setAsync(samples) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
await Context.metricsDatabase.transform(this, this.transformFn(samples)); | ||
const numNegativeSamples = getNumNegativeSamples(samples); | ||
if (numNegativeSamples > 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, `Accumulated ${numNegativeSamples} negative samples`, numNegativeSamples); | ||
} | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
}); | ||
} | ||
setSync(samples) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
Context.metricsDatabase.transform(this, this.transformFn(samples)); | ||
const numNegativeSamples = getNumNegativeSamples(samples); | ||
if (numNegativeSamples > 0) { | ||
Context.errorManager.record(this, ErrorType.InvalidValue, `Accumulated ${numNegativeSamples} negative samples`, numNegativeSamples); | ||
} | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let value; | ||
await Context.dispatcher.testLaunch(async () => { | ||
value = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
const value = Context.metricsDatabase.getMetric(ping, this); | ||
if (value) { | ||
@@ -173,6 +143,6 @@ const { bucketCount, histogramType, rangeMax, rangeMin, values } = value; | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -179,0 +149,0 @@ } |
@@ -120,8 +120,15 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
set(value) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(value); | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
else { | ||
this.setAsync(value); | ||
const truncatedDate = this.truncateDate(value); | ||
try { | ||
const metric = DatetimeMetric.fromDate(truncatedDate, this.timeUnit); | ||
Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
@@ -153,40 +160,7 @@ truncateDate(value) { | ||
} | ||
setAsync(value) { | ||
Context.dispatcher.launch(() => this.setUndispatched(value)); | ||
} | ||
async setUndispatched(value) { | ||
setRaw(isoString, timezone, timeUnit) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
const truncatedDate = this.truncateDate(value); | ||
try { | ||
const metric = DatetimeMetric.fromDate(truncatedDate, this.timeUnit); | ||
await Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
} | ||
setSync(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
const truncatedDate = this.truncateDate(value); | ||
try { | ||
const metric = DatetimeMetric.fromDate(truncatedDate, this.timeUnit); | ||
Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
} | ||
} | ||
} | ||
setSyncRaw(isoString, timezone, timeUnit) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
const metric = DatetimeMetric.fromRawDatetime(isoString, timezone, timeUnit); | ||
@@ -197,12 +171,9 @@ Context.metricsDatabase.record(this, metric); | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
async testGetValueAsDatetimeMetric(ping, fn) { | ||
testGetValueAsDatetimeMetric(ping, fn) { | ||
if (testOnlyCheck(fn, LOG_TAG)) { | ||
let value; | ||
await Context.dispatcher.testLaunch(async () => { | ||
value = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
const value = Context.metricsDatabase.getMetric(ping, this); | ||
if (value) { | ||
@@ -213,8 +184,8 @@ return new DatetimeMetric(value); | ||
} | ||
async testGetValueAsString(ping = this.sendInPings[0]) { | ||
const metric = await this.testGetValueAsDatetimeMetric(ping, "testGetValueAsString"); | ||
testGetValueAsString(ping = this.sendInPings[0]) { | ||
const metric = this.testGetValueAsDatetimeMetric(ping, "testGetValueAsString"); | ||
return metric ? metric.payload() : undefined; | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
const metric = await this.testGetValueAsDatetimeMetric(ping, "testGetValue"); | ||
testGetValue(ping = this.sendInPings[0]) { | ||
const metric = this.testGetValueAsDatetimeMetric(ping, "testGetValue"); | ||
return metric ? metric.date : undefined; | ||
@@ -231,9 +202,9 @@ } | ||
} | ||
async testGetValueAsString(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValueAsString(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValueAsString(ping); | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -240,0 +211,0 @@ } |
@@ -15,3 +15,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
import { MetricType } from "../index.js"; | ||
import { getMonotonicNow, isString, testOnlyCheck, truncateStringAtBoundaryWithError, truncateStringAtBoundaryWithErrorSync } from "../../utils.js"; | ||
import { getMonotonicNow, isString, testOnlyCheck, truncateStringAtBoundaryWithError } from "../../utils.js"; | ||
import { Context } from "../../context.js"; | ||
@@ -28,15 +28,2 @@ import { ErrorType } from "../../error/error_type.js"; | ||
record(extra, timestamp = getMonotonicNow()) { | ||
if (Context.isPlatformSync()) { | ||
this.recordSync(timestamp, extra); | ||
} | ||
else { | ||
this.recordAsync(timestamp, extra); | ||
} | ||
} | ||
recordAsync(timestamp, extra) { | ||
Context.dispatcher.launch(async () => { | ||
await this.recordUndispatched(extra, timestamp); | ||
}); | ||
} | ||
async recordUndispatched(extra, timestamp = getMonotonicNow()) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -58,3 +45,3 @@ return; | ||
if (isString(value)) { | ||
truncatedExtra[name] = await truncateStringAtBoundaryWithError(this, value, MAX_LENGTH_EXTRA_KEY_VALUE); | ||
truncatedExtra[name] = truncateStringAtBoundaryWithError(this, value, MAX_LENGTH_EXTRA_KEY_VALUE); | ||
} | ||
@@ -66,43 +53,2 @@ else { | ||
else { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, `Invalid key index: ${name}`); | ||
continue; | ||
} | ||
} | ||
} | ||
metric.set({ | ||
...metric.get(), | ||
extra: truncatedExtra | ||
}); | ||
return Context.eventsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
} | ||
recordSync(timestamp, extra) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
const metric = new RecordedEvent({ | ||
category: this.category, | ||
name: this.name, | ||
timestamp, | ||
extra | ||
}); | ||
let truncatedExtra = undefined; | ||
if (extra && this.allowedExtraKeys) { | ||
truncatedExtra = {}; | ||
for (const [name, value] of Object.entries(extra)) { | ||
if (this.allowedExtraKeys.includes(name)) { | ||
if (isString(value)) { | ||
truncatedExtra[name] = truncateStringAtBoundaryWithErrorSync(this, value, MAX_LENGTH_EXTRA_KEY_VALUE); | ||
} | ||
else { | ||
truncatedExtra[name] = value; | ||
} | ||
} | ||
else { | ||
Context.errorManager.record(this, ErrorType.InvalidValue, `Invalid key index: ${name}`); | ||
@@ -121,13 +67,9 @@ continue; | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let events; | ||
await Context.dispatcher.testLaunch(async () => { | ||
events = await Context.eventsDatabase.getEvents(ping, this); | ||
}); | ||
return events; | ||
return Context.eventsDatabase.getEvents(ping, this); | ||
} | ||
@@ -144,6 +86,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _EventMetricType_inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _EventMetricType_inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _EventMetricType_inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _EventMetricType_inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _EventMetricType_inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _EventMetricType_inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -150,0 +92,0 @@ } |
@@ -25,3 +25,3 @@ import { Metric, MetricValidation } from "../metric.js"; | ||
} | ||
export async function getValidDynamicLabel(metric) { | ||
export function getValidDynamicLabel(metric) { | ||
if (metric.dynamicLabel === undefined) { | ||
@@ -32,30 +32,2 @@ throw new Error("This point should never be reached."); | ||
for (const ping of metric.sendInPings) { | ||
if (await Context.metricsDatabase.hasMetric(metric.lifetime, ping, metric.type, key)) { | ||
return key; | ||
} | ||
} | ||
let numUsedKeys = 0; | ||
for (const ping of metric.sendInPings) { | ||
numUsedKeys += await Context.metricsDatabase.countByBaseIdentifier(metric.lifetime, ping, metric.type, metric.baseIdentifier()); | ||
} | ||
let hitError = false; | ||
if (numUsedKeys >= MAX_LABELS) { | ||
hitError = true; | ||
} | ||
else if (metric.dynamicLabel.length > MAX_LABEL_LENGTH) { | ||
hitError = true; | ||
await Context.errorManager.record(metric, ErrorType.InvalidLabel, `Label length ${metric.dynamicLabel.length} exceeds maximum of ${MAX_LABEL_LENGTH}.`); | ||
} | ||
else if (!LABEL_REGEX.test(metric.dynamicLabel)) { | ||
hitError = true; | ||
await Context.errorManager.record(metric, ErrorType.InvalidLabel, `Label must be snake_case, got '${metric.dynamicLabel}'.`); | ||
} | ||
return hitError ? combineIdentifierAndLabel(metric.baseIdentifier(), OTHER_LABEL) : key; | ||
} | ||
export function getValidDynamicLabelSync(metric) { | ||
if (metric.dynamicLabel === undefined) { | ||
throw new Error("This point should never be reached."); | ||
} | ||
const key = combineIdentifierAndLabel(metric.baseIdentifier(), metric.dynamicLabel); | ||
for (const ping of metric.sendInPings) { | ||
if (Context.metricsDatabase.hasMetric(metric.lifetime, ping, metric.type, key)) { | ||
@@ -62,0 +34,0 @@ return key; |
@@ -64,80 +64,2 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
accumulate(sample) { | ||
if (Context.isPlatformSync()) { | ||
this.accumulateSync(sample); | ||
} | ||
else { | ||
this.accumulateAsync(sample); | ||
} | ||
} | ||
accumulateTransformFn(sample) { | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
return new MemoryDistributionMetric([...values, sample]); | ||
}; | ||
} | ||
accumulateSamples(samples) { | ||
if (Context.isPlatformSync()) { | ||
this.accumulateSamplesSync(samples); | ||
} | ||
else { | ||
this.accumulateSamplesAsync(samples); | ||
} | ||
} | ||
accumulateSamplesTransformFn(samples) { | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
const convertedSamples = []; | ||
samples.forEach((sample) => { | ||
if (sample >= 0) { | ||
sample = convertMemoryUnitToBytes(sample, this.memoryUnit); | ||
if (sample > MAX_BYTES) { | ||
sample = MAX_BYTES; | ||
} | ||
convertedSamples.push(sample); | ||
} | ||
}); | ||
return new MemoryDistributionMetric([...values, ...convertedSamples]); | ||
}; | ||
} | ||
accumulateAsync(sample) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
if (sample < 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, "Accumulated a negative sample"); | ||
return; | ||
} | ||
let convertedSample = convertMemoryUnitToBytes(sample, this.memoryUnit); | ||
if (sample > MAX_BYTES) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, "Sample is bigger than 1 terabyte."); | ||
convertedSample = MAX_BYTES; | ||
} | ||
try { | ||
await Context.metricsDatabase.transform(this, this.accumulateTransformFn(convertedSample)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
}); | ||
} | ||
accumulateSamplesAsync(samples) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
await Context.metricsDatabase.transform(this, this.accumulateSamplesTransformFn(samples)); | ||
const numNegativeSamples = getNumNegativeSamples(samples); | ||
if (numNegativeSamples > 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, `Accumulated ${numNegativeSamples} negative samples`, numNegativeSamples); | ||
} | ||
const numTooLongSamples = getNumTooLongSamples(samples, MAX_BYTES); | ||
if (numTooLongSamples > 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, `Accumulated ${numTooLongSamples} larger than 1TB`, numTooLongSamples); | ||
} | ||
}); | ||
} | ||
accumulateSync(sample) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -160,7 +82,7 @@ return; | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
accumulateSamplesSync(samples) { | ||
accumulateSamples(samples) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -179,8 +101,27 @@ return; | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
accumulateTransformFn(sample) { | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
return new MemoryDistributionMetric([...values, sample]); | ||
}; | ||
} | ||
accumulateSamplesTransformFn(samples) { | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
const convertedSamples = []; | ||
samples.forEach((sample) => { | ||
if (sample >= 0) { | ||
sample = convertMemoryUnitToBytes(sample, this.memoryUnit); | ||
if (sample > MAX_BYTES) { | ||
sample = MAX_BYTES; | ||
} | ||
convertedSamples.push(sample); | ||
} | ||
}); | ||
return new MemoryDistributionMetric([...values, ...convertedSamples]); | ||
}; | ||
} | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let value; | ||
await Context.dispatcher.testLaunch(async () => { | ||
value = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
const value = Context.metricsDatabase.getMetric(ping, this); | ||
if (value) { | ||
@@ -191,3 +132,3 @@ return snapshot(constructFunctionalHistogramFromValues(value, LOG_BASE, BUCKETS_PER_MAGNITUDE)); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = this.sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetNumRecordedErrors")) { | ||
@@ -210,6 +151,6 @@ return Context.errorManager.testGetNumRecordedErrors(this, errorType, ping); | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -216,0 +157,0 @@ } |
@@ -36,13 +36,2 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
set(value) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(value); | ||
} | ||
else { | ||
this.setAsync(value); | ||
} | ||
} | ||
setAsync(value) { | ||
Context.dispatcher.launch(() => this.setUndispatched(value)); | ||
} | ||
async setUndispatched(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -52,23 +41,2 @@ return; | ||
if (value < 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, `Set negative value ${value}`); | ||
return; | ||
} | ||
if (value > Number.MAX_SAFE_INTEGER) { | ||
value = Number.MAX_SAFE_INTEGER; | ||
} | ||
try { | ||
const metric = new QuantityMetric(value); | ||
await Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
} | ||
setSync(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
if (value < 0) { | ||
Context.errorManager.record(this, ErrorType.InvalidValue, `Set negative value ${value}`); | ||
@@ -86,13 +54,9 @@ return; | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -109,6 +73,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -115,0 +79,0 @@ } |
@@ -13,2 +13,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _inner; | ||
import log from "../../log.js"; | ||
import { MetricType } from "../index.js"; | ||
@@ -18,3 +19,2 @@ import { Context } from "../../context.js"; | ||
import { saturatingAdd, testOnlyCheck, isObject } from "../../utils.js"; | ||
import log from "../../log.js"; | ||
import { validatePositiveInteger } from "../utils.js"; | ||
@@ -70,8 +70,13 @@ const LOG_TAG = "core.metrics.RateMetricType"; | ||
add(value) { | ||
if (Context.isPlatformSync()) { | ||
this.addSync(value); | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
else { | ||
this.addAsync(value); | ||
try { | ||
Context.metricsDatabase.transform(this, this.transformFn(value)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
@@ -96,37 +101,5 @@ transformFn(value) { | ||
} | ||
addAsync(value) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
await Context.metricsDatabase.transform(this, this.transformFn(value)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
}); | ||
} | ||
addSync(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
Context.metricsDatabase.transform(this, this.transformFn(value)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -146,6 +119,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -152,0 +125,0 @@ } |
@@ -13,9 +13,9 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _inner; | ||
import log from "../../log.js"; | ||
import { Context } from "../../context.js"; | ||
import { ErrorType } from "../../error/error_type.js"; | ||
import { MetricType } from "../index.js"; | ||
import { Context } from "../../context.js"; | ||
import { Metric, MetricValidation, MetricValidationError } from "../metric.js"; | ||
import { testOnlyCheck, truncateStringAtBoundaryWithError, truncateStringAtBoundaryWithErrorSync } from "../../utils.js"; | ||
import { ErrorType } from "../../error/error_type.js"; | ||
import log from "../../log.js"; | ||
import { validateString } from "../utils.js"; | ||
import { testOnlyCheck, truncateStringAtBoundaryWithError } from "../../utils.js"; | ||
const LOG_TAG = "core.metrics.StringListMetricType"; | ||
@@ -60,76 +60,2 @@ export const MAX_LIST_LENGTH = 20; | ||
set(value) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(value); | ||
} | ||
else { | ||
this.setAsync(value); | ||
} | ||
} | ||
add(value) { | ||
if (Context.isPlatformSync()) { | ||
this.addSync(value); | ||
} | ||
else { | ||
this.addAsync(value); | ||
} | ||
} | ||
addTransformFn(value) { | ||
return (v) => { | ||
const metric = new StringListMetric([value]); | ||
try { | ||
v && metric.concat(v); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError && e.type !== ErrorType.InvalidType) { | ||
throw e; | ||
} | ||
else { | ||
log(LOG_TAG, `Unexpected value found in storage for metric ${this.name}: ${JSON.stringify(v)}. Overwriting.`); | ||
} | ||
} | ||
return metric; | ||
}; | ||
} | ||
setAsync(value) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
if (value.length > MAX_LIST_LENGTH) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, `String list length of ${value.length} exceeds maximum of ${MAX_LIST_LENGTH}.`); | ||
} | ||
const metric = new StringListMetric(value); | ||
const truncatedList = []; | ||
for (let i = 0; i < Math.min(value.length, MAX_LIST_LENGTH); ++i) { | ||
const truncatedString = await truncateStringAtBoundaryWithError(this, value[i], MAX_STRING_LENGTH); | ||
truncatedList.push(truncatedString); | ||
} | ||
metric.set(truncatedList); | ||
await Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
}); | ||
} | ||
addAsync(value) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
const truncatedValue = await truncateStringAtBoundaryWithError(this, value, MAX_STRING_LENGTH); | ||
await Context.metricsDatabase.transform(this, this.addTransformFn(truncatedValue)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
}); | ||
} | ||
setSync(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -145,3 +71,3 @@ return; | ||
for (let i = 0; i < Math.min(value.length, MAX_LIST_LENGTH); ++i) { | ||
const truncatedString = truncateStringAtBoundaryWithErrorSync(this, value[i], MAX_STRING_LENGTH); | ||
const truncatedString = truncateStringAtBoundaryWithError(this, value[i], MAX_STRING_LENGTH); | ||
truncatedList.push(truncatedString); | ||
@@ -154,7 +80,7 @@ } | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
addSync(value) { | ||
add(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -164,3 +90,3 @@ return; | ||
try { | ||
const truncatedValue = truncateStringAtBoundaryWithErrorSync(this, value, MAX_STRING_LENGTH); | ||
const truncatedValue = truncateStringAtBoundaryWithError(this, value, MAX_STRING_LENGTH); | ||
Context.metricsDatabase.transform(this, this.addTransformFn(truncatedValue)); | ||
@@ -170,13 +96,26 @@ } | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
addTransformFn(value) { | ||
return (v) => { | ||
const metric = new StringListMetric([value]); | ||
try { | ||
v && metric.concat(v); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError && e.type !== ErrorType.InvalidType) { | ||
throw e; | ||
} | ||
else { | ||
log(LOG_TAG, `Unexpected value found in storage for metric ${this.name}: ${JSON.stringify(v)}. Overwriting.`); | ||
} | ||
} | ||
return metric; | ||
}; | ||
} | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -196,6 +135,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -202,0 +141,0 @@ } |
@@ -13,7 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _inner; | ||
import { Context } from "../../context.js"; | ||
import { MetricType } from "../index.js"; | ||
import { Context } from "../../context.js"; | ||
import { Metric, MetricValidationError } from "../metric.js"; | ||
import { testOnlyCheck, truncateStringAtBoundaryWithError, truncateStringAtBoundaryWithErrorSync } from "../../utils.js"; | ||
import { validateString } from "../utils.js"; | ||
import { testOnlyCheck, truncateStringAtBoundaryWithError, } from "../../utils.js"; | ||
const LOG_TAG = "core.metrics.StringMetricType"; | ||
@@ -37,13 +37,2 @@ export const MAX_LENGTH_VALUE = 100; | ||
set(value) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(value); | ||
} | ||
else { | ||
this.setAsync(value); | ||
} | ||
} | ||
setAsync(value) { | ||
Context.dispatcher.launch(() => this.setUndispatched(value)); | ||
} | ||
async setUndispatched(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -53,19 +42,4 @@ return; | ||
try { | ||
const truncatedValue = await truncateStringAtBoundaryWithError(this, value, MAX_LENGTH_VALUE); | ||
const truncatedValue = truncateStringAtBoundaryWithError(this, value, MAX_LENGTH_VALUE); | ||
const metric = new StringMetric(truncatedValue); | ||
await Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
} | ||
setSync(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
const truncatedValue = truncateStringAtBoundaryWithErrorSync(this, value, MAX_LENGTH_VALUE); | ||
const metric = new StringMetric(truncatedValue); | ||
Context.metricsDatabase.record(this, metric); | ||
@@ -75,13 +49,9 @@ } | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -98,6 +68,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -104,0 +74,0 @@ } |
@@ -13,8 +13,8 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _inner; | ||
import { testOnlyCheck, truncateStringAtBoundaryWithError, truncateStringAtBoundaryWithErrorSync } from "../../utils.js"; | ||
import { Context } from "../../context.js"; | ||
import { Metric } from "../metric.js"; | ||
import { MetricType } from "../index.js"; | ||
import { Context } from "../../context.js"; | ||
import { MetricValidationError } from "../metric.js"; | ||
import { Metric } from "../metric.js"; | ||
import { validateString } from "../utils.js"; | ||
import { testOnlyCheck, truncateStringAtBoundaryWithError, } from "../../utils.js"; | ||
const LOG_TAG = "core.metrics.TextMetricType"; | ||
@@ -38,27 +38,2 @@ export const TEXT_MAX_LENGTH = 200 * 1024; | ||
set(text) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(text); | ||
} | ||
else { | ||
this.setAsync(text); | ||
} | ||
} | ||
setAsync(text) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
try { | ||
const truncatedValue = await truncateStringAtBoundaryWithError(this, text, TEXT_MAX_LENGTH); | ||
const metric = new TextMetric(truncatedValue); | ||
await Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
}); | ||
} | ||
setSync(text) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -68,3 +43,3 @@ return; | ||
try { | ||
const truncatedValue = truncateStringAtBoundaryWithErrorSync(this, text, TEXT_MAX_LENGTH); | ||
const truncatedValue = truncateStringAtBoundaryWithError(this, text, TEXT_MAX_LENGTH); | ||
const metric = new TextMetric(truncatedValue); | ||
@@ -75,13 +50,9 @@ Context.metricsDatabase.record(this, metric); | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -98,6 +69,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -104,0 +75,0 @@ } |
@@ -13,10 +13,9 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _inner; | ||
import { Context } from "../../context.js"; | ||
import { ErrorType } from "../../error/error_type.js"; | ||
import { Metric, MetricValidation, MetricValidationError } from "../metric.js"; | ||
import { MetricType } from "../index.js"; | ||
import TimeUnit from "../time_unit.js"; | ||
import { isInteger } from "../../utils.js"; | ||
import TimeUnit from "../time_unit.js"; | ||
import { MetricType } from "../index.js"; | ||
import { isString, isObject, isUndefined, getMonotonicNow, testOnlyCheck } from "../../utils.js"; | ||
import { MetricValidation, MetricValidationError } from "../metric.js"; | ||
import { Metric } from "../metric.js"; | ||
import { Context } from "../../context.js"; | ||
import { ErrorType } from "../../error/error_type.js"; | ||
const LOG_TAG = "core.metrics.TimespanMetricType"; | ||
@@ -96,83 +95,3 @@ export class TimespanMetric extends Metric { | ||
start() { | ||
if (Context.isPlatformSync()) { | ||
this.startSync(); | ||
} | ||
else { | ||
this.startAsync(); | ||
} | ||
} | ||
stop() { | ||
if (Context.isPlatformSync()) { | ||
this.stopSync(); | ||
} | ||
else { | ||
this.stopAsync(); | ||
} | ||
} | ||
cancel() { | ||
if (Context.isPlatformSync()) { | ||
this.cancelSync(); | ||
} | ||
else { | ||
this.cancelAsync(); | ||
} | ||
} | ||
setRawNanos(elapsed) { | ||
if (Context.isPlatformSync()) { | ||
this.setRawNanosSync(elapsed); | ||
} | ||
else { | ||
this.setRawNanosAsync(elapsed); | ||
} | ||
} | ||
startAsync() { | ||
const startTime = getMonotonicNow(); | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
if (!isUndefined(this.startTime)) { | ||
await Context.errorManager.record(this, ErrorType.InvalidState, "Timespan already started"); | ||
return; | ||
} | ||
this.startTime = startTime; | ||
return Promise.resolve(); | ||
}); | ||
} | ||
stopAsync() { | ||
const stopTime = getMonotonicNow(); | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
this.startTime = undefined; | ||
return; | ||
} | ||
if (isUndefined(this.startTime)) { | ||
await Context.errorManager.record(this, ErrorType.InvalidState, "Timespan not running."); | ||
return; | ||
} | ||
const elapsed = stopTime - this.startTime; | ||
this.startTime = undefined; | ||
if (elapsed < 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidState, "Timespan was negative."); | ||
return; | ||
} | ||
await this.setRawUndispatched(elapsed); | ||
}); | ||
} | ||
cancelAsync() { | ||
Context.dispatcher.launch(() => { | ||
this.startTime = undefined; | ||
return Promise.resolve(); | ||
}); | ||
} | ||
setRawNanosAsync(elapsed) { | ||
Context.dispatcher.launch(async () => { | ||
const elapsedMillis = elapsed * 10 ** -6; | ||
await this.setRawUndispatched(elapsedMillis); | ||
}); | ||
} | ||
async setRawUndispatched(elapsed) { | ||
await this.setRawAsync(elapsed); | ||
} | ||
async setRawAsync(elapsed) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -182,40 +101,2 @@ return; | ||
if (!isUndefined(this.startTime)) { | ||
await Context.errorManager.record(this, ErrorType.InvalidState, "Timespan already running. Raw value not recorded."); | ||
return; | ||
} | ||
let reportValueExists = false; | ||
try { | ||
const transformFn = ((elapsed) => { | ||
return (old) => { | ||
let metric; | ||
try { | ||
metric = new TimespanMetric(old); | ||
reportValueExists = true; | ||
} | ||
catch (_a) { | ||
metric = new TimespanMetric({ | ||
timespan: elapsed, | ||
timeUnit: this.timeUnit | ||
}); | ||
} | ||
return metric; | ||
}; | ||
})(elapsed); | ||
await Context.metricsDatabase.transform(this, transformFn); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
if (reportValueExists) { | ||
await Context.errorManager.record(this, ErrorType.InvalidState, "Timespan value already recorded. New value discarded."); | ||
} | ||
} | ||
startSync() { | ||
const startTime = getMonotonicNow(); | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
if (!isUndefined(this.startTime)) { | ||
Context.errorManager.record(this, ErrorType.InvalidState, "Timespan already started"); | ||
@@ -226,3 +107,3 @@ return; | ||
} | ||
stopSync() { | ||
stop() { | ||
const stopTime = getMonotonicNow(); | ||
@@ -243,12 +124,12 @@ if (!this.shouldRecord(Context.uploadEnabled)) { | ||
} | ||
this.setRawSync(elapsed); | ||
this.setRaw(elapsed); | ||
} | ||
cancelSync() { | ||
cancel() { | ||
this.startTime = undefined; | ||
} | ||
setRawNanosSync(elapsed) { | ||
setRawNanos(elapsed) { | ||
const elapsedMillis = elapsed * 10 ** -6; | ||
this.setRawSync(elapsedMillis); | ||
this.setRaw(elapsedMillis); | ||
} | ||
setRawSync(elapsed) { | ||
setRaw(elapsed) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -283,3 +164,3 @@ return; | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
@@ -291,8 +172,5 @@ } | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let value; | ||
await Context.dispatcher.testLaunch(async () => { | ||
value = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
const value = Context.metricsDatabase.getMetric(ping, this); | ||
if (value) { | ||
@@ -321,6 +199,6 @@ return new TimespanMetric(value).timespan; | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -327,0 +205,0 @@ } |
@@ -13,11 +13,10 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _inner; | ||
import { MetricType } from "../index.js"; | ||
import { Context } from "../../context.js"; | ||
import { ErrorType } from "../../error/error_type.js"; | ||
import { Metric, MetricValidation, MetricValidationError } from "../metric.js"; | ||
import { ErrorType } from "../../error/error_type.js"; | ||
import { MetricType } from "../index.js"; | ||
import { convertTimeUnitToNanos } from "../time_unit.js"; | ||
import { getCurrentTimeInNanoSeconds, isUndefined, testOnlyCheck } from "../../utils.js"; | ||
import { constructFunctionalHistogramFromValues } from "../../../histogram/functional.js"; | ||
import { getCurrentTimeInNanoSeconds, isUndefined, testOnlyCheck } from "../../utils.js"; | ||
import { convertTimeUnitToNanos } from "../time_unit.js"; | ||
import { snapshot } from "../distributions.js"; | ||
import { extractAccumulatedValuesFromJsonValue, getNumNegativeSamples, getNumTooLongSamples } from "../distributions.js"; | ||
import { extractAccumulatedValuesFromJsonValue, getNumNegativeSamples, getNumTooLongSamples, snapshot } from "../distributions.js"; | ||
const LOG_TAG = "core.metrics.TimingDistributionMetricType"; | ||
@@ -74,168 +73,13 @@ const LOG_BASE = 2.0; | ||
const id = this.getNextTimerId(); | ||
if (Context.isPlatformSync()) { | ||
this.setStartSync(id, startTime); | ||
} | ||
else { | ||
this.setStart(id, startTime); | ||
} | ||
this.setStart(id, startTime); | ||
return id; | ||
} | ||
setStart(id, startTime) { | ||
this.setStartAsync(id, startTime); | ||
this.startTimes[id] = startTime; | ||
} | ||
stopAndAccumulate(id) { | ||
const stopTime = getCurrentTimeInNanoSeconds(); | ||
if (Context.isPlatformSync()) { | ||
this.setStopAndAccumulateSync(id, stopTime); | ||
} | ||
else { | ||
this.setStopAndAccumulate(id, stopTime); | ||
} | ||
this.setStopAndAccumulate(id, stopTime); | ||
} | ||
setStopAndAccumulate(id, stopTime) { | ||
this.setStopAndAccumulateAsync(id, stopTime); | ||
} | ||
cancel(id) { | ||
delete this.startTimes[id]; | ||
} | ||
accumulateSamples(samples) { | ||
if (Context.isPlatformSync()) { | ||
this.setAccumulateSamplesSync(samples); | ||
} | ||
else { | ||
this.setAccumulateSamples(samples); | ||
} | ||
} | ||
setAccumulateSamples(samples) { | ||
this.setAccumulateSamplesAsync(samples); | ||
} | ||
accumulateRawSamplesNanos(samples) { | ||
if (Context.isPlatformSync()) { | ||
this.accumulateRawSamplesNanosSync(samples); | ||
} | ||
else { | ||
this.accumulateRawSamplesNanosAsync(samples); | ||
} | ||
} | ||
setStopAndAccumulateTransformFn(duration) { | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
return new TimingDistributionMetric([...values, duration]); | ||
}; | ||
} | ||
setAccumulateSamplesTransformFn(samples, maxSampleTime) { | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
const convertedSamples = []; | ||
samples.forEach((sample) => { | ||
if (sample >= 0) { | ||
if (sample === 0) { | ||
sample = 1; | ||
} | ||
else if (sample > maxSampleTime) { | ||
sample = maxSampleTime; | ||
} | ||
sample = convertTimeUnitToNanos(sample, this.timeUnit); | ||
convertedSamples.push(sample); | ||
} | ||
}); | ||
return new TimingDistributionMetric([...values, ...convertedSamples]); | ||
}; | ||
} | ||
accumulateRawSamplesNanosTransformFn(samples, maxSampleTime) { | ||
const minSampleTime = convertTimeUnitToNanos(1, this.timeUnit); | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
const convertedSamples = []; | ||
samples.forEach((sample) => { | ||
if (sample < minSampleTime) { | ||
sample = minSampleTime; | ||
} | ||
else if (sample > maxSampleTime) { | ||
sample = maxSampleTime; | ||
} | ||
convertedSamples.push(sample); | ||
}); | ||
return new TimingDistributionMetric([...values, ...convertedSamples]); | ||
}; | ||
} | ||
setStartAsync(id, startTime) { | ||
Context.dispatcher.launch(async () => { | ||
this.startTimes[id] = startTime; | ||
return Promise.resolve(); | ||
}); | ||
} | ||
setStopAndAccumulateAsync(id, stopTime) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
delete this.startTimes[id]; | ||
return; | ||
} | ||
const startTime = this.startTimes[id]; | ||
if (startTime !== undefined) { | ||
delete this.startTimes[id]; | ||
} | ||
else { | ||
await Context.errorManager.record(this, ErrorType.InvalidState, "Timing not running"); | ||
return; | ||
} | ||
let duration = stopTime - startTime; | ||
if (duration < 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, "Timer stopped with negative duration"); | ||
return; | ||
} | ||
const minSampleTime = convertTimeUnitToNanos(1, this.timeUnit); | ||
const maxSampleTime = convertTimeUnitToNanos(MAX_SAMPLE_TIME, this.timeUnit); | ||
if (duration < minSampleTime) { | ||
duration = minSampleTime; | ||
} | ||
else if (duration > maxSampleTime) { | ||
await Context.errorManager.record(this, ErrorType.InvalidState, `Sample is longer than the max for a timeUnit of ${this.timeUnit} (${duration} ns)`); | ||
duration = maxSampleTime; | ||
} | ||
try { | ||
await Context.metricsDatabase.transform(this, this.setStopAndAccumulateTransformFn(duration)); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
return Promise.resolve(); | ||
}); | ||
} | ||
setAccumulateSamplesAsync(samples) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
const maxSampleTime = convertTimeUnitToNanos(MAX_SAMPLE_TIME, this.timeUnit); | ||
await Context.metricsDatabase.transform(this, this.setAccumulateSamplesTransformFn(samples, maxSampleTime)); | ||
const numNegativeSamples = getNumNegativeSamples(samples); | ||
if (numNegativeSamples > 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidValue, `Accumulated ${numNegativeSamples} negative samples`, numNegativeSamples); | ||
} | ||
const numTooLongSamples = getNumTooLongSamples(samples, maxSampleTime); | ||
if (numTooLongSamples > 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidOverflow, `${numTooLongSamples} samples are longer than the maximum of ${maxSampleTime}`, numTooLongSamples); | ||
} | ||
}); | ||
} | ||
accumulateRawSamplesNanosAsync(samples) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
const maxSampleTime = convertTimeUnitToNanos(MAX_SAMPLE_TIME, this.timeUnit); | ||
await Context.metricsDatabase.transform(this, this.accumulateRawSamplesNanosTransformFn(samples, maxSampleTime)); | ||
const numTooLongSamples = getNumTooLongSamples(samples, maxSampleTime); | ||
if (numTooLongSamples > 0) { | ||
await Context.errorManager.record(this, ErrorType.InvalidOverflow, `${numTooLongSamples} samples are longer than the maximum of ${maxSampleTime}`, numTooLongSamples); | ||
} | ||
}); | ||
} | ||
setStartSync(id, startTime) { | ||
this.startTimes[id] = startTime; | ||
} | ||
setStopAndAccumulateSync(id, stopTime) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -272,7 +116,13 @@ delete this.startTimes[id]; | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
setAccumulateSamplesSync(samples) { | ||
cancel(id) { | ||
delete this.startTimes[id]; | ||
} | ||
accumulateSamples(samples) { | ||
this.setAccumulateSamples(samples); | ||
} | ||
setAccumulateSamples(samples) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -292,3 +142,3 @@ return; | ||
} | ||
accumulateRawSamplesNanosSync(samples) { | ||
accumulateRawSamplesNanos(samples) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -304,8 +154,47 @@ return; | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
setStopAndAccumulateTransformFn(duration) { | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
return new TimingDistributionMetric([...values, duration]); | ||
}; | ||
} | ||
setAccumulateSamplesTransformFn(samples, maxSampleTime) { | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
const convertedSamples = []; | ||
samples.forEach((sample) => { | ||
if (sample >= 0) { | ||
if (sample === 0) { | ||
sample = 1; | ||
} | ||
else if (sample > maxSampleTime) { | ||
sample = maxSampleTime; | ||
} | ||
sample = convertTimeUnitToNanos(sample, this.timeUnit); | ||
convertedSamples.push(sample); | ||
} | ||
}); | ||
return new TimingDistributionMetric([...values, ...convertedSamples]); | ||
}; | ||
} | ||
accumulateRawSamplesNanosTransformFn(samples, maxSampleTime) { | ||
const minSampleTime = convertTimeUnitToNanos(1, this.timeUnit); | ||
return (old) => { | ||
const values = extractAccumulatedValuesFromJsonValue(old); | ||
const convertedSamples = []; | ||
samples.forEach((sample) => { | ||
if (sample < minSampleTime) { | ||
sample = minSampleTime; | ||
} | ||
else if (sample > maxSampleTime) { | ||
sample = maxSampleTime; | ||
} | ||
convertedSamples.push(sample); | ||
}); | ||
return new TimingDistributionMetric([...values, ...convertedSamples]); | ||
}; | ||
} | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let value; | ||
await Context.dispatcher.testLaunch(async () => { | ||
value = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
const value = Context.metricsDatabase.getMetric(ping, this); | ||
if (value) { | ||
@@ -316,3 +205,3 @@ return snapshot(constructFunctionalHistogramFromValues(value, LOG_BASE, BUCKETS_PER_MAGNITUDE)); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = this.sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetNumRecordedErrors")) { | ||
@@ -354,6 +243,6 @@ return Context.errorManager.testGetNumRecordedErrors(this, errorType, ping); | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -360,0 +249,0 @@ } |
@@ -13,8 +13,8 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _inner; | ||
import { testOnlyCheck, truncateStringAtBoundaryWithError, truncateStringAtBoundaryWithErrorSync } from "../../utils.js"; | ||
import { MetricType } from "../index.js"; | ||
import { Context } from "../../context.js"; | ||
import { MetricValidationError, MetricValidation, Metric } from "../metric.js"; | ||
import { ErrorType } from "../../error/error_type.js"; | ||
import { Metric, MetricValidationError, MetricValidation } from "../metric.js"; | ||
import { MetricType } from "../index.js"; | ||
import { validateString } from "../utils.js"; | ||
import { testOnlyCheck, truncateStringAtBoundaryWithError } from "../../utils.js"; | ||
const LOG_TAG = "core.metrics.URLMetricType"; | ||
@@ -58,41 +58,2 @@ const URL_MAX_LENGTH = 8192; | ||
set(url) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(url); | ||
} | ||
else { | ||
this.setAsync(url); | ||
} | ||
} | ||
setUrl(url) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(url.toString()); | ||
} | ||
else { | ||
this.setAsync(url.toString()); | ||
} | ||
} | ||
setAsync(url) { | ||
Context.dispatcher.launch(async () => { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
let formattedUrl; | ||
if (url.length > URL_MAX_LENGTH) { | ||
formattedUrl = await truncateStringAtBoundaryWithError(this, url, URL_MAX_LENGTH); | ||
} | ||
else { | ||
formattedUrl = url; | ||
} | ||
try { | ||
const metric = new UrlMetric(formattedUrl); | ||
await Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
} | ||
} | ||
}); | ||
} | ||
setSync(url) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
@@ -103,3 +64,3 @@ return; | ||
if (url.length > URL_MAX_LENGTH) { | ||
formattedUrl = truncateStringAtBoundaryWithErrorSync(this, url, URL_MAX_LENGTH); | ||
formattedUrl = truncateStringAtBoundaryWithError(this, url, URL_MAX_LENGTH); | ||
} | ||
@@ -115,13 +76,12 @@ else { | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
setUrl(url) { | ||
this.set(url.toString()); | ||
} | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -141,6 +101,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -147,0 +107,0 @@ } |
@@ -49,24 +49,5 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
set(value) { | ||
if (Context.isPlatformSync()) { | ||
this.setSync(value); | ||
} | ||
else { | ||
this.setAsync(value); | ||
} | ||
} | ||
generateAndSet() { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
const value = generateUUIDv4(); | ||
this.set(value); | ||
return value; | ||
} | ||
setAsync(value) { | ||
Context.dispatcher.launch(() => this.setUndispatched(value)); | ||
} | ||
async setUndispatched(value) { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
if (!value) { | ||
@@ -78,35 +59,21 @@ value = generateUUIDv4(); | ||
metric = new UUIDMetric(value); | ||
await Context.metricsDatabase.record(this, metric); | ||
Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
await e.recordError(this); | ||
e.recordError(this); | ||
} | ||
} | ||
} | ||
setSync(value) { | ||
generateAndSet() { | ||
if (!this.shouldRecord(Context.uploadEnabled)) { | ||
return; | ||
} | ||
if (!value) { | ||
value = generateUUIDv4(); | ||
} | ||
let metric; | ||
try { | ||
metric = new UUIDMetric(value); | ||
Context.metricsDatabase.record(this, metric); | ||
} | ||
catch (e) { | ||
if (e instanceof MetricValidationError) { | ||
e.recordErrorSync(this); | ||
} | ||
} | ||
const value = generateUUIDv4(); | ||
this.set(value); | ||
return value; | ||
} | ||
async testGetValue(ping = this.sendInPings[0]) { | ||
testGetValue(ping = this.sendInPings[0]) { | ||
if (testOnlyCheck("testGetValue", LOG_TAG)) { | ||
let metric; | ||
await Context.dispatcher.testLaunch(async () => { | ||
metric = await Context.metricsDatabase.getMetric(ping, this); | ||
}); | ||
return metric; | ||
return Context.metricsDatabase.getMetric(ping, this); | ||
} | ||
@@ -126,6 +93,6 @@ } | ||
} | ||
async testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetValue(ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetValue(ping); | ||
} | ||
async testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
testGetNumRecordedErrors(errorType, ping = __classPrivateFieldGet(this, _inner, "f").sendInPings[0]) { | ||
return __classPrivateFieldGet(this, _inner, "f").testGetNumRecordedErrors(errorType, ping); | ||
@@ -132,0 +99,0 @@ } |
@@ -13,8 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _inner; | ||
import { Context } from "../context.js"; | ||
import log, { LoggingLevel } from "../log.js"; | ||
import { DELETION_REQUEST_PING_NAME } from "../constants.js"; | ||
import { generateUUIDv4, testOnlyCheck } from "../utils.js"; | ||
import collectAndStorePing from "../pings/maker/async.js"; | ||
import collectAndStorePingSync from "../pings/maker/sync.js"; | ||
import { Context } from "../context.js"; | ||
import log, { LoggingLevel } from "../log.js"; | ||
import collectAndStorePing from "../pings/maker.js"; | ||
const LOG_TAG = "core.Pings.PingType"; | ||
@@ -34,10 +33,2 @@ function isDeletionRequest(name) { | ||
submit(reason) { | ||
if (Context.isPlatformSync()) { | ||
this.submitSync(reason); | ||
} | ||
else { | ||
this.submitAsync(reason); | ||
} | ||
} | ||
submitAsync(reason) { | ||
if (this.testCallback) { | ||
@@ -58,7 +49,2 @@ this.testCallback(reason) | ||
internalSubmit(reason, testResolver) { | ||
Context.dispatcher.launch(async () => { | ||
await this.submitUndispatched(reason, testResolver); | ||
}); | ||
} | ||
async submitUndispatched(reason, testResolver) { | ||
if (!Context.initialized) { | ||
@@ -78,3 +64,3 @@ log(LOG_TAG, "Glean must be initialized before submitting pings.", LoggingLevel.Info); | ||
const identifier = generateUUIDv4(); | ||
await collectAndStorePing(identifier, this, correctedReason); | ||
collectAndStorePing(identifier, this, correctedReason); | ||
if (testResolver) { | ||
@@ -87,40 +73,2 @@ testResolver(); | ||
} | ||
submitSync(reason) { | ||
if (this.testCallback) { | ||
this.testCallback(reason) | ||
.then(() => { | ||
this.internalSubmitSync(reason, this.resolveTestPromiseFunction); | ||
}) | ||
.catch((e) => { | ||
log(LOG_TAG, [`There was an error validating "${this.name}" (${reason !== null && reason !== void 0 ? reason : "no reason"}):`, e], LoggingLevel.Error); | ||
this.internalSubmitSync(reason, this.rejectTestPromiseFunction); | ||
}); | ||
} | ||
else { | ||
this.internalSubmitSync(reason); | ||
} | ||
} | ||
internalSubmitSync(reason, testResolver) { | ||
if (!Context.initialized) { | ||
log(LOG_TAG, "Glean must be initialized before submitting pings.", LoggingLevel.Info); | ||
return; | ||
} | ||
if (!Context.uploadEnabled && !isDeletionRequest(this.name)) { | ||
log(LOG_TAG, "Glean disabled: not submitting pings. Glean may still submit the deletion-request ping.", LoggingLevel.Info); | ||
return; | ||
} | ||
let correctedReason = reason; | ||
if (reason && !this.reasonCodes.includes(reason)) { | ||
log(LOG_TAG, `Invalid reason code ${reason} from ${this.name}. Ignoring.`, LoggingLevel.Warn); | ||
correctedReason = undefined; | ||
} | ||
const identifier = generateUUIDv4(); | ||
collectAndStorePingSync(identifier, this, correctedReason); | ||
if (testResolver) { | ||
testResolver(); | ||
this.resolveTestPromiseFunction = undefined; | ||
this.rejectTestPromiseFunction = undefined; | ||
this.testCallback = undefined; | ||
} | ||
} | ||
async testBeforeNextSubmit(callbackFn) { | ||
@@ -148,3 +96,3 @@ if (testOnlyCheck("testBeforeNextSubmit", LOG_TAG)) { | ||
} | ||
async testBeforeNextSubmit(callbackFn) { | ||
testBeforeNextSubmit(callbackFn) { | ||
return __classPrivateFieldGet(this, _inner, "f").testBeforeNextSubmit(callbackFn); | ||
@@ -151,0 +99,0 @@ } |
import { Context } from "../context.js"; | ||
import EventsDatabase from "../metrics/events_database/async.js"; | ||
export async function testRestartGlean(timeOffset = 1000 * 60) { | ||
import EventsDatabase from "../metrics/events_database/index.js"; | ||
export function testRestartGlean(timeOffset = 1000 * 60) { | ||
Context.startTime.setTime(Context.startTime.getTime() + timeOffset); | ||
const db = new EventsDatabase(); | ||
await db.initialize(); | ||
db.initialize(); | ||
return db; | ||
} |
import { testInitializeGlean, testUninitializeGlean } from "./utils.js"; | ||
export async function testResetGlean(applicationId, uploadEnabled = true, config, clearStores = true) { | ||
await testUninitializeGlean(clearStores); | ||
await testInitializeGlean(applicationId, uploadEnabled, config); | ||
export function testResetGlean(applicationId, uploadEnabled = true, config, clearStores = true) { | ||
testUninitializeGlean(clearStores); | ||
testInitializeGlean(applicationId, uploadEnabled, config); | ||
} | ||
export * from "./utils.js"; | ||
export * from "./events.js"; |
import TestPlatform from "../../platform/test/index.js"; | ||
import { Context } from "../context.js"; | ||
import { testResetEvents } from "../events/utils/async.js"; | ||
import Glean from "../glean/async.js"; | ||
export async function testInitializeGlean(applicationId, uploadEnabled = true, config) { | ||
import Glean from "../glean.js"; | ||
export function testInitializeGlean(applicationId, uploadEnabled = true, config) { | ||
Context.testing = true; | ||
Glean.setPlatform(TestPlatform); | ||
Glean.initialize(applicationId, uploadEnabled, config); | ||
await Context.dispatcher.testBlockOnQueue(); | ||
} | ||
export async function testUninitializeGlean(clearStores = true) { | ||
export function testUninitializeGlean(clearStores = true) { | ||
if (Context.initialized) { | ||
await Glean.shutdown(); | ||
if (clearStores) { | ||
await Context.eventsDatabase.clearAll(); | ||
await Context.metricsDatabase.clearAll(); | ||
await Context.pingsDatabase.clearAll(); | ||
Context.eventsDatabase.clearAll(); | ||
Context.metricsDatabase.clearAll(); | ||
Context.pingsDatabase.clearAll(); | ||
} | ||
Context.testUninitialize(); | ||
testResetEvents(); | ||
Glean.preInitLogPings = undefined; | ||
@@ -22,0 +18,0 @@ Glean.preInitDebugViewTag = undefined; |
@@ -81,3 +81,3 @@ import { v4 as UUIDv4 } from "uuid"; | ||
} | ||
export async function truncateStringAtBoundaryWithError(metric, value, length) { | ||
export function truncateStringAtBoundaryWithError(metric, value, length) { | ||
if (!isString(value)) { | ||
@@ -88,12 +88,2 @@ throw new MetricValidationError(`Expected string, got ${JSON.stringify(value)}`); | ||
if (truncated !== value) { | ||
await Context.errorManager.record(metric, ErrorType.InvalidOverflow, `Value length ${value.length} exceeds maximum of ${length}.`); | ||
} | ||
return truncated; | ||
} | ||
export function truncateStringAtBoundaryWithErrorSync(metric, value, length) { | ||
if (!isString(value)) { | ||
throw new MetricValidationError(`Expected string, got ${JSON.stringify(value)}`); | ||
} | ||
const truncated = value.substring(0, length); | ||
if (truncated !== value) { | ||
Context.errorManager.record(metric, ErrorType.InvalidOverflow, `Value length ${value.length} exceeds maximum of ${length}.`); | ||
@@ -100,0 +90,0 @@ } |
import platform from "../platform/browser/web/index.js"; | ||
import { baseSync } from "./base/sync.js"; | ||
import { base } from "./base.js"; | ||
export { default as Uploader, UploadResult, UploadResultStatus } from "../core/upload/uploader.js"; | ||
export default baseSync(platform); | ||
export default base(platform); |
@@ -6,5 +6,9 @@ import log, { LoggingLevel } from "../../core/log.js"; | ||
class BrowserUploader extends Uploader { | ||
constructor() { | ||
super(...arguments); | ||
this.timeoutMs = DEFAULT_UPLOAD_TIMEOUT_MS; | ||
} | ||
async post(url, body, headers = {}, keepalive = true) { | ||
const controller = new AbortController(); | ||
const timeout = setTimeout(() => controller.abort(), DEFAULT_UPLOAD_TIMEOUT_MS); | ||
const timeout = setTimeout(() => controller.abort(), this.timeoutMs); | ||
let response; | ||
@@ -11,0 +15,0 @@ try { |
import log, { LoggingLevel } from "../../../core/log.js"; | ||
import { deleteKeyFromNestedObject, getValueFromNestedObject, updateNestedObject } from "../../../core/storage/utils.js"; | ||
import { deleteKeyFromNestedObject, getValueFromNestedObject, updateNestedObject } from "../../../core/storage.js"; | ||
import { isWindowObjectUnavailable } from "../../../core/utils.js"; | ||
@@ -4,0 +4,0 @@ const LOG_TAG = "platform.web.Storage"; |
@@ -12,12 +12,12 @@ import MockStorage from "../test/storage.js"; | ||
os() { | ||
return Promise.resolve("Unknown"); | ||
return "Unknown"; | ||
}, | ||
osVersion() { | ||
return Promise.resolve("Unknown"); | ||
return "Unknown"; | ||
}, | ||
arch() { | ||
return Promise.resolve("Unknown"); | ||
return "Unknown"; | ||
}, | ||
locale() { | ||
return Promise.resolve("Unknown"); | ||
return "Unknown"; | ||
}, | ||
@@ -24,0 +24,0 @@ }; |
import log, { LoggingLevel } from "../../core/log.js"; | ||
import { updateNestedObject, getValueFromNestedObject, deleteKeyFromNestedObject } from "../../core/storage/utils.js"; | ||
import { updateNestedObject, getValueFromNestedObject, deleteKeyFromNestedObject } from "../../core/storage.js"; | ||
const LOG_TAG = "platform.test.Storage"; | ||
@@ -12,6 +12,6 @@ let globalStore = {}; | ||
const value = getValueFromNestedObject(globalStore, [this.rootKey, ...index]); | ||
return Promise.resolve(value); | ||
return value; | ||
} | ||
catch (e) { | ||
return Promise.reject(e); | ||
throw e; | ||
} | ||
@@ -22,6 +22,6 @@ } | ||
globalStore = updateNestedObject(globalStore, [this.rootKey, ...index], transformFn); | ||
return Promise.resolve(); | ||
return; | ||
} | ||
catch (e) { | ||
return Promise.reject(e); | ||
throw e; | ||
} | ||
@@ -36,5 +36,5 @@ } | ||
} | ||
return Promise.resolve(); | ||
return; | ||
} | ||
} | ||
export default MockStore; |
@@ -1,2 +0,1 @@ | ||
import type Plugin from "../plugins/index.js"; | ||
import type Uploader from "./upload/uploader.js"; | ||
@@ -20,3 +19,2 @@ /** | ||
readonly maxEvents?: number; | ||
plugins?: Plugin[]; | ||
httpClient?: Uploader; | ||
@@ -23,0 +21,0 @@ readonly buildDate?: Date; |
export declare const GLEAN_SCHEMA_VERSION = 1; | ||
export declare const GLEAN_VERSION = "3.0.0"; | ||
export declare const GLEAN_VERSION = "4.0.0-pre.0"; | ||
export declare const PING_INFO_STORAGE = "glean_ping_info"; | ||
@@ -4,0 +4,0 @@ export declare const CLIENT_INFO_STORAGE = "glean_client_info"; |
@@ -1,13 +0,7 @@ | ||
import type MetricsDatabase from "./metrics/database/async.js"; | ||
import type MetricsDatabaseSync from "./metrics/database/sync.js"; | ||
import type EventsDatabase from "./metrics/events_database/async.js"; | ||
import type { EventsDatabaseSync } from "./metrics/events_database/sync.js"; | ||
import type PingsDatabase from "./pings/database/async.js"; | ||
import type PingsDatabaseSync from "./pings/database/sync.js"; | ||
import type ErrorManager from "./error/async.js"; | ||
import type ErrorManagerSync from "./error/sync.js"; | ||
import type Platform from "../platform/async.js"; | ||
import type PlatformSync from "../platform/sync.js"; | ||
import type { CoreMetrics } from "./internal_metrics/async.js"; | ||
import type { CoreMetricsSync } from "./internal_metrics/sync.js"; | ||
import type MetricsDatabase from "./metrics/database.js"; | ||
import type EventsDatabase from "./metrics/events_database/index.js"; | ||
import type PingsDatabase from "./pings/database.js"; | ||
import type ErrorManager from "./error/index.js"; | ||
import type Platform from "../platform/index.js"; | ||
import type { CoreMetrics } from "./internal_metrics.js"; | ||
import type { Configuration } from "./config.js"; | ||
@@ -17,3 +11,2 @@ import type CorePings from "./internal_pings.js"; | ||
import type { JSONValue } from "./utils.js"; | ||
import Dispatcher from "./dispatcher.js"; | ||
/** | ||
@@ -33,3 +26,2 @@ * This class holds all of the Glean singleton's state and internal dependencies. | ||
private static _instance?; | ||
private dispatcher; | ||
private platform; | ||
@@ -57,13 +49,12 @@ private corePings; | ||
static testUninitialize(): void; | ||
static get dispatcher(): Dispatcher; | ||
static get uploadEnabled(): boolean; | ||
static set uploadEnabled(upload: boolean); | ||
static get metricsDatabase(): MetricsDatabase | MetricsDatabaseSync; | ||
static set metricsDatabase(db: MetricsDatabase | MetricsDatabaseSync); | ||
static get eventsDatabase(): EventsDatabase | EventsDatabaseSync; | ||
static set eventsDatabase(db: EventsDatabase | EventsDatabaseSync); | ||
static get pingsDatabase(): PingsDatabase | PingsDatabaseSync; | ||
static set pingsDatabase(db: PingsDatabase | PingsDatabaseSync); | ||
static get errorManager(): ErrorManager | ErrorManagerSync; | ||
static set errorManager(db: ErrorManager | ErrorManagerSync); | ||
static get metricsDatabase(): MetricsDatabase; | ||
static set metricsDatabase(db: MetricsDatabase); | ||
static get eventsDatabase(): EventsDatabase; | ||
static set eventsDatabase(db: EventsDatabase); | ||
static get pingsDatabase(): PingsDatabase; | ||
static set pingsDatabase(db: PingsDatabase); | ||
static get errorManager(): ErrorManager; | ||
static set errorManager(db: ErrorManager); | ||
static get applicationId(): string; | ||
@@ -80,8 +71,7 @@ static set applicationId(id: string); | ||
static set corePings(pings: CorePings); | ||
static get coreMetrics(): CoreMetrics | CoreMetricsSync; | ||
static set coreMetrics(metrics: CoreMetrics | CoreMetricsSync); | ||
static set platform(platform: Platform | PlatformSync); | ||
static get platform(): Platform | PlatformSync; | ||
static get coreMetrics(): CoreMetrics; | ||
static set coreMetrics(metrics: CoreMetrics); | ||
static set platform(platform: Platform); | ||
static get platform(): Platform; | ||
static isPlatformSet(): boolean; | ||
static isPlatformSync(): boolean; | ||
static getSupportedMetric(type: string): (new (v: unknown) => Metric<JSONValue, JSONValue>) | undefined; | ||
@@ -88,0 +78,0 @@ /** |
@@ -45,11 +45,4 @@ import type { JSONValue } from "../utils.js"; | ||
*/ | ||
identifier(): Promise<string>; | ||
identifier(): string; | ||
/** | ||
* The metric's unique identifier, including the category, name and label. | ||
* | ||
* @returns The generated identifier. If `category` is empty, it's omitted. Otherwise, | ||
* it's the combination of the metric's `category`, `name` and `label`. | ||
*/ | ||
identifierSync(): string; | ||
/** | ||
* Verify whether or not this metric instance should be recorded. | ||
@@ -62,3 +55,3 @@ * | ||
shouldRecord(uploadEnabled: boolean): boolean; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -18,4 +18,3 @@ import type { JSONValue } from "../utils.js"; | ||
constructor(message?: string, type?: ErrorType); | ||
recordError(metric: MetricType): Promise<void>; | ||
recordErrorSync(metric: MetricType): void; | ||
recordError(metric: MetricType): void; | ||
} | ||
@@ -22,0 +21,0 @@ /** |
@@ -34,3 +34,3 @@ import type { CommonMetricData } from "../index.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<boolean | undefined>; | ||
testGetValue(ping?: string): boolean | undefined; | ||
/** | ||
@@ -46,3 +46,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -22,20 +22,3 @@ import type { CommonMetricData } from "../index.js"; | ||
private transformFn; | ||
addAsync(amount?: number): void; | ||
/** | ||
* An implementation of `add` that does not dispatch the recording task. | ||
* | ||
* # Important | ||
* | ||
* This method should **never** be exposed to users. | ||
* | ||
* @param amount The amount we want to add. | ||
*/ | ||
addUndispatched(amount?: number): Promise<void>; | ||
/** | ||
* A synchronous implementation of add. | ||
* | ||
* @param amount The amount we want to add. | ||
*/ | ||
addSync(amount?: number): void; | ||
testGetValue(ping?: string): Promise<number | undefined>; | ||
testGetValue(ping?: string): number | undefined; | ||
} | ||
@@ -75,3 +58,3 @@ /** | ||
*/ | ||
testGetValue(ping?: string): Promise<number | undefined>; | ||
testGetValue(ping?: string): number | undefined; | ||
/** | ||
@@ -87,3 +70,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -45,3 +45,3 @@ import type { CommonMetricData } from "../index.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<DistributionData | undefined>; | ||
testGetValue(ping?: string): DistributionData | undefined; | ||
/** | ||
@@ -57,4 +57,4 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} | ||
export {}; |
@@ -67,15 +67,3 @@ import type { CommonMetricData } from "../index.js"; | ||
private truncateDate; | ||
setAsync(value?: Date): void; | ||
/** | ||
* An implementation of `set` that does not dispatch the recording task. | ||
* | ||
* # Important | ||
* | ||
* This method should **never** be exposed to users. | ||
* | ||
* @param value The date we want to set to. | ||
*/ | ||
setUndispatched(value?: Date): Promise<void>; | ||
setSync(value?: Date): void; | ||
/** | ||
* Set a datetime metric from raw values. | ||
@@ -91,3 +79,3 @@ * | ||
*/ | ||
setSyncRaw(isoString: string, timezone: number, timeUnit: TimeUnit): void; | ||
setRaw(isoString: string, timezone: number, timeUnit: TimeUnit): void; | ||
/** | ||
@@ -105,4 +93,4 @@ * Test-only API | ||
private testGetValueAsDatetimeMetric; | ||
testGetValueAsString(ping?: string): Promise<string | undefined>; | ||
testGetValue(ping?: string): Promise<Date | undefined>; | ||
testGetValueAsString(ping?: string): string | undefined; | ||
testGetValue(ping?: string): Date | undefined; | ||
} | ||
@@ -135,3 +123,3 @@ /** | ||
*/ | ||
testGetValueAsString(ping?: string): Promise<string | undefined>; | ||
testGetValueAsString(ping?: string): string | undefined; | ||
/** | ||
@@ -155,3 +143,3 @@ * Test-only API | ||
*/ | ||
testGetValue(ping?: string): Promise<Date | undefined>; | ||
testGetValue(ping?: string): Date | undefined; | ||
/** | ||
@@ -167,3 +155,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -22,18 +22,3 @@ import type { CommonMetricData } from "../index.js"; | ||
record(extra?: SpecificExtraMap, timestamp?: number): void; | ||
recordAsync(timestamp: number, extra?: SpecificExtraMap): void; | ||
/** | ||
* An implementation of `record` that does not dispatch the recording task. | ||
* | ||
* # Important | ||
* | ||
* This method should **never** be exposed to users. | ||
* | ||
* @param extra optional. Used for events where additional richer context is needed. | ||
* The maximum length for string values is 100 bytes. | ||
* @param timestamp The event timestamp, defaults to now. | ||
* @returns A promise that resolves once the event is recorded. | ||
*/ | ||
recordUndispatched(extra?: ExtraMap, timestamp?: number): Promise<void>; | ||
recordSync(timestamp: number, extra?: SpecificExtraMap): void; | ||
/** | ||
* Test-only API | ||
@@ -49,3 +34,3 @@ * | ||
*/ | ||
testGetValue(ping?: string): Promise<Event[] | undefined>; | ||
testGetValue(ping?: string): Event[] | undefined; | ||
} | ||
@@ -76,3 +61,3 @@ /** | ||
*/ | ||
testGetValue(ping?: string): Promise<Event[] | undefined>; | ||
testGetValue(ping?: string): Event[] | undefined; | ||
/** | ||
@@ -88,3 +73,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -46,12 +46,3 @@ import type { CommonMetricData, MetricType } from "../index.js"; | ||
*/ | ||
export declare function getValidDynamicLabel(metric: MetricType): Promise<string>; | ||
/** | ||
* Checks if the dynamic label stored in the metric data is | ||
* valid. If not, record an error and store data in the "__other__" | ||
* label. | ||
* | ||
* @param metric the metric to record to. | ||
* @returns a valid label that can be used to store data. | ||
*/ | ||
export declare function getValidDynamicLabelSync(metric: MetricType): string; | ||
export declare function getValidDynamicLabel(metric: MetricType): string; | ||
type SupportedLabeledTypes = CounterMetricType | BooleanMetricType | StringMetricType; | ||
@@ -58,0 +49,0 @@ declare class LabeledMetricType<T extends SupportedLabeledTypes> { |
@@ -65,3 +65,3 @@ import type { DistributionData } from "../distributions.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<DistributionData | undefined>; | ||
testGetValue(ping?: string): DistributionData | undefined; | ||
/** | ||
@@ -77,4 +77,4 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} | ||
export {}; |
@@ -36,3 +36,3 @@ import type { CommonMetricData } from "../index.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<number | undefined>; | ||
testGetValue(ping?: string): number | undefined; | ||
/** | ||
@@ -48,3 +48,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -53,3 +53,3 @@ import type { CommonMetricData } from "../index.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<Rate | undefined>; | ||
testGetValue(ping?: string): Rate | undefined; | ||
/** | ||
@@ -65,3 +65,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -51,3 +51,3 @@ import type { CommonMetricData } from "../index.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<string[] | undefined>; | ||
testGetValue(ping?: string): string[] | undefined; | ||
/** | ||
@@ -63,3 +63,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -21,15 +21,3 @@ import type { CommonMetricData } from "../index.js"; | ||
set(value: string): void; | ||
setAsync(value: string): void; | ||
/** | ||
* An implementation of `set` that does not dispatch the recording task. | ||
* | ||
* # Important | ||
* | ||
* This method should **never** be exposed to users. | ||
* | ||
* @param value The string we want to set to. | ||
*/ | ||
setUndispatched(value: string): Promise<void>; | ||
setSync(value: string): void; | ||
testGetValue(ping?: string): Promise<string | undefined>; | ||
testGetValue(ping?: string): string | undefined; | ||
} | ||
@@ -67,3 +55,3 @@ /** | ||
*/ | ||
testGetValue(ping?: string): Promise<string | undefined>; | ||
testGetValue(ping?: string): string | undefined; | ||
/** | ||
@@ -79,3 +67,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -39,3 +39,3 @@ import type { CommonMetricData } from "../index.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<string | undefined>; | ||
testGetValue(ping?: string): string | undefined; | ||
/** | ||
@@ -51,3 +51,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
import type { CommonMetricData } from "../index.js"; | ||
import type { MetricValidationResult } from "../metric.js"; | ||
import { Metric } from "../metric.js"; | ||
import { MetricType } from "../index.js"; | ||
import TimeUnit from "../time_unit.js"; | ||
import { MetricType } from "../index.js"; | ||
import { Metric } from "../metric.js"; | ||
export type TimespanInternalRepresentation = { | ||
@@ -36,23 +36,4 @@ timeUnit: TimeUnit; | ||
setRawNanos(elapsed: number): void; | ||
startAsync(): void; | ||
stopAsync(): void; | ||
cancelAsync(): void; | ||
setRawNanosAsync(elapsed: number): void; | ||
/** | ||
* An implementation of `setRaw` that does not dispatch the recording task. | ||
* | ||
* # Important | ||
* | ||
* This method should **never** be exposed to users. | ||
* | ||
* @param elapsed The elapsed time to record, in milliseconds. | ||
*/ | ||
setRawUndispatched(elapsed: number): Promise<void>; | ||
setRawAsync(elapsed: number): Promise<void>; | ||
startSync(): void; | ||
stopSync(): void; | ||
cancelSync(): void; | ||
setRawNanosSync(elapsed: number): void; | ||
setRawSync(elapsed: number): void; | ||
testGetValue(ping?: string): Promise<number | undefined>; | ||
setRaw(elapsed: number): void; | ||
testGetValue(ping?: string): number | undefined; | ||
} | ||
@@ -113,3 +94,3 @@ /** | ||
*/ | ||
testGetValue(ping?: string): Promise<number | undefined>; | ||
testGetValue(ping?: string): number | undefined; | ||
/** | ||
@@ -125,3 +106,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -120,3 +120,3 @@ import type { CommonMetricData } from "../index.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<DistributionData | undefined>; | ||
testGetValue(ping?: string): DistributionData | undefined; | ||
/** | ||
@@ -132,4 +132,4 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} | ||
export {}; |
@@ -55,3 +55,3 @@ import type { CommonMetricData } from "../index.js"; | ||
*/ | ||
testGetValue(ping?: string): Promise<string | undefined>; | ||
testGetValue(ping?: string): string | undefined; | ||
/** | ||
@@ -67,3 +67,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
@@ -21,15 +21,3 @@ import type { CommonMetricData } from "../index.js"; | ||
generateAndSet(): string | undefined; | ||
setAsync(value: string): void; | ||
/** | ||
* An implementation of `set` that does not dispatch the recording task. | ||
* | ||
* # Important | ||
* | ||
* This method should **never** be exposed to users. | ||
* | ||
* @param value The UUID we want to set to. | ||
*/ | ||
setUndispatched(value: string): Promise<void>; | ||
setSync(value: string): void; | ||
testGetValue(ping?: string): Promise<string | undefined>; | ||
testGetValue(ping?: string): string | undefined; | ||
} | ||
@@ -69,3 +57,3 @@ /** | ||
*/ | ||
testGetValue(ping?: string): Promise<string | undefined>; | ||
testGetValue(ping?: string): string | undefined; | ||
/** | ||
@@ -81,3 +69,3 @@ * Test-only API | ||
*/ | ||
testGetNumRecordedErrors(errorType: string, ping?: string): Promise<number>; | ||
testGetNumRecordedErrors(errorType: string, ping?: string): number; | ||
} |
import type CommonPingData from "./common_ping_data.js"; | ||
type ValidatorFunction = (reason?: string) => Promise<void>; | ||
type PromiseCallback = (value: void | PromiseLike<void>) => void; | ||
export declare class InternalPingType implements CommonPingData { | ||
@@ -15,19 +14,3 @@ readonly name: string; | ||
submit(reason?: string): void; | ||
submitAsync(reason?: string): void; | ||
private internalSubmit; | ||
/** | ||
* An implementation of `submit` that does not dispatch the submission task. | ||
* | ||
* # Important | ||
* | ||
* This method should **never** be exposed to users. | ||
* | ||
* @param reason The reason the ping was triggered. Included in the | ||
* `ping_info.reason` part of the payload. | ||
* @param testResolver The asynchronous validation function to run in order to validate | ||
* the ping content. | ||
*/ | ||
submitUndispatched(reason?: string, testResolver?: PromiseCallback): Promise<void>; | ||
submitSync(reason?: string): void; | ||
private internalSubmitSync; | ||
testBeforeNextSubmit(callbackFn: ValidatorFunction): Promise<void>; | ||
@@ -34,0 +17,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import EventsDatabase from "../metrics/events_database/async.js"; | ||
import EventsDatabase from "../metrics/events_database/index.js"; | ||
/** | ||
@@ -14,2 +14,2 @@ * Test-only API | ||
*/ | ||
export declare function testRestartGlean(timeOffset?: number): Promise<EventsDatabase>; | ||
export declare function testRestartGlean(timeOffset?: number): EventsDatabase; |
@@ -17,4 +17,4 @@ import type { ConfigurationInterface } from "../config"; | ||
*/ | ||
export declare function testResetGlean(applicationId: string, uploadEnabled?: boolean, config?: ConfigurationInterface, clearStores?: boolean): Promise<void>; | ||
export declare function testResetGlean(applicationId: string, uploadEnabled?: boolean, config?: ConfigurationInterface, clearStores?: boolean): void; | ||
export * from "./utils.js"; | ||
export * from "./events.js"; |
@@ -15,3 +15,3 @@ import type { ConfigurationInterface } from "../config.js"; | ||
*/ | ||
export declare function testInitializeGlean(applicationId: string, uploadEnabled?: boolean, config?: ConfigurationInterface): Promise<void>; | ||
export declare function testInitializeGlean(applicationId: string, uploadEnabled?: boolean, config?: ConfigurationInterface): void; | ||
/** | ||
@@ -25,2 +25,2 @@ * Test-only API | ||
*/ | ||
export declare function testUninitializeGlean(clearStores?: boolean): Promise<void>; | ||
export declare function testUninitializeGlean(clearStores?: boolean): void; |
@@ -1,2 +0,2 @@ | ||
import type { QueuedPing } from "./manager/shared.js"; | ||
import type { QueuedPing } from "./manager.js"; | ||
export declare const enum UploadTaskTypes { | ||
@@ -3,0 +3,0 @@ Done = "done", |
@@ -133,17 +133,4 @@ import type { MetricType } from "./metrics/index.js"; | ||
*/ | ||
export declare function truncateStringAtBoundaryWithError(metric: MetricType, value: unknown, length: number): Promise<string>; | ||
export declare function truncateStringAtBoundaryWithError(metric: MetricType, value: unknown, length: number): string; | ||
/** | ||
* Truncates a string to a given max length SYNCHRONOUSLY. | ||
* | ||
* If the string required truncation, records an error through the error | ||
* reporting mechanism. | ||
* | ||
* @param metric The metric to record an error to, if necessary, | ||
* @param value The string to truncate. | ||
* @param length The length to truncate to. | ||
* @returns A string with at most `length` bytes. | ||
* @throws In case `value` is not a string. | ||
*/ | ||
export declare function truncateStringAtBoundaryWithErrorSync(metric: MetricType, value: unknown, length: number): string; | ||
/** | ||
* Decorator factory that will only allow a function to be called when Glean is in testing mode. | ||
@@ -150,0 +137,0 @@ * |
export { default as Uploader, UploadResult, UploadResultStatus } from "../core/upload/uploader.js"; | ||
declare const _default: import("./base/shared.js").IGlean; | ||
declare const _default: { | ||
initialize(applicationId: string, uploadEnabled: boolean, config?: import("../core/config.js").ConfigurationInterface | undefined): void; | ||
setUploadEnabled(flag: boolean): void; | ||
setLogPings(flag: boolean): void; | ||
setDebugViewTag(value: string): void; | ||
setSourceTags(value: string[]): void; | ||
}; | ||
export default _default; |
import Uploader from "../../core/upload/uploader.js"; | ||
import { UploadResult } from "../../core/upload/uploader.js"; | ||
declare class BrowserUploader extends Uploader { | ||
timeoutMs: number; | ||
post(url: string, body: string | Uint8Array, headers?: Record<string, string>, keepalive?: boolean): Promise<UploadResult>; | ||
@@ -5,0 +6,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import type PlatformSync from "../../sync.js"; | ||
declare const WebPlatform: PlatformSync; | ||
import type Platform from "../../index.js"; | ||
declare const WebPlatform: Platform; | ||
export default WebPlatform; |
@@ -1,3 +0,3 @@ | ||
import type PlatformInfoSync from "../../../core/platform_info/sync.js"; | ||
declare const BrowserPlatformInfo: PlatformInfoSync; | ||
import type PlatformInfo from "../../../core/platform_info.js"; | ||
declare const BrowserPlatformInfo: PlatformInfo; | ||
export default BrowserPlatformInfo; |
@@ -1,5 +0,5 @@ | ||
import type SynchronousStore from "../../../core/storage/sync.js"; | ||
import type { StorageIndex } from "../../../core/storage/shared.js"; | ||
import type Store from "../../../core/storage.js"; | ||
import type { StorageIndex } from "../../../core/storage.js"; | ||
import type { JSONValue } from "../../../core/utils.js"; | ||
declare class WebStore implements SynchronousStore { | ||
declare class WebStore implements Store { | ||
private rootKey; | ||
@@ -6,0 +6,0 @@ private logTag; |
@@ -1,3 +0,3 @@ | ||
import type Platform from "../async.js"; | ||
import type Platform from "../index.js"; | ||
declare const TestPlatform: Platform; | ||
export default TestPlatform; |
@@ -1,3 +0,3 @@ | ||
import type { StorageIndex } from "../../core/storage/shared.js"; | ||
import type Store from "../../core/storage/async.js"; | ||
import type { StorageIndex } from "../../core/storage.js"; | ||
import type Store from "../../core/storage.js"; | ||
import type { JSONValue } from "../../core/utils.js"; | ||
@@ -13,6 +13,6 @@ /** | ||
constructor(rootKey: string); | ||
get(index?: StorageIndex): Promise<JSONValue | undefined>; | ||
update(index: StorageIndex, transformFn: (v?: JSONValue) => JSONValue): Promise<void>; | ||
delete(index: StorageIndex): Promise<void>; | ||
get(index?: StorageIndex): JSONValue | undefined; | ||
update(index: StorageIndex, transformFn: (v?: JSONValue) => JSONValue): void; | ||
delete(index: StorageIndex): void; | ||
} | ||
export default MockStore; |
{ | ||
"name": "@mozilla/glean", | ||
"version": "3.0.0", | ||
"version": "4.0.0-pre.0", | ||
"description": "An implementation of the Glean SDK, a modern cross-platform telemetry client, for JavaScript environments.", | ||
@@ -12,3 +12,2 @@ "type": "module", | ||
"./private/ping": "./dist/core/pings/ping_type.js", | ||
"./plugins/*": "./dist/plugins/*.js", | ||
"./uploader": "./dist/core/upload/uploader.js", | ||
@@ -29,5 +28,2 @@ "./testing": "./dist/core/testing/index.js", | ||
], | ||
"plugins/*": [ | ||
"./dist/types/plugins/*" | ||
], | ||
"uploader": [ | ||
@@ -56,5 +52,4 @@ "./dist/types/core/upload/uploader.d.ts" | ||
"pretest:integration": "../bin/parser-for-schema-testing.sh && ../bin/python-env-vars-test.sh", | ||
"test:unit": "run-s test:unit:core test:unit:platform test:unit:plugins", | ||
"test:unit": "run-s test:unit:core test:unit:platform", | ||
"test:unit:core": "npm run test:base -- \"tests/unit/core/**/*.spec.ts\" --recursive", | ||
"test:unit:plugins": "npm run test:base -- \"tests/unit/plugins/**/*.spec.ts\" --recursive", | ||
"test:unit:platform": "npm run test:base -- \"tests/unit/platform/**/*.spec.ts\" --recursive --timeout 0", | ||
@@ -135,3 +130,2 @@ "test:base": "node --experimental-modules --experimental-specifier-resolution=node --loader=ts-node/esm node_modules/mocha/lib/cli/cli.js", | ||
"fflate": "^0.8.0", | ||
"jose": "^4.0.4", | ||
"tslib": "^2.3.1", | ||
@@ -138,0 +132,0 @@ "uuid": "^9.0.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
328879
138
8452
1
- Removedjose@^4.0.4
- Removedjose@4.15.9(transitive)