Options
All
  • Public
  • Public/Protected
  • All
Menu

The metrics database is an abstraction layer on top of the underlying storage.

Metric data is saved to the database in the following format:

{ "pingName": { "metricType (i.e. boolean)": { "metricIdentifier": metricPayload } } }

We have one store in this format for each lifetime: user, ping and application.

Hierarchy

  • default

Index

Constructors

constructor

Properties

Private appStore

appStore: default

Private pingStore

pingStore: default

Private userStore

userStore: default

Methods

Private _chooseStore

  • Returns the store instance for a given lifetime.

    throws

    If the provided lifetime does not have a related store.

    Parameters

    • lifetime: Lifetime

      The lifetime related to the store we want to retrieve.

    Returns default

    The store related to the given lifetime.

clear

  • clear(lifetime: Lifetime, ping?: string): Promise<void>
  • Clears currently persisted data for a given lifetime.

    Parameters

    • lifetime: Lifetime

      The lifetime to clear.

    • Optional ping: string

      The ping to clear data from. When ommited, data from all pings will be cleared.

    Returns Promise<void>

clearAll

  • clearAll(): Promise<void>

countByBaseIdentifier

  • countByBaseIdentifier(lifetime: Lifetime, ping: string, metricType: string, metricIdentifier: string): Promise<number>
  • Counts the number of stored metrics with an id starting with a specific identifier.

    Parameters

    • lifetime: Lifetime

      the metric Lifetime.

    • ping: string

      the ping storage to search in.

    • metricType: string

      the type of the metric.

    • metricIdentifier: string

      the metric identifier.

    Returns Promise<number>

    the number of stored metrics with their id starting with the given identifier.

Private getAndValidatePingData

  • Helper function to validate and get a specific lifetime data related to a ping from the underlying storage.

    Note

    If the value in storage for any of the metrics in the ping is of an unexpected type, the whole ping payload for that lifetime will be thrown away.

    Parameters

    • ping: string

      The ping we want to get the data from

    • lifetime: Lifetime

      The lifetime of the data we want to retrieve

    Returns Promise<Metrics>

    The ping payload found for the given parameters or an empty object in case no data was found or the data that was found, was invalid.

getMetric

  • getMetric<T>(ping: string, metric: MetricType): Promise<undefined | T>
  • Gets and validates the persisted payload of a given metric in a given ping.

    If the persisted value is invalid for the metric we are attempting to retrieve, the persisted value is deleted and `undefined is returned.

    This behaviour is not consistent with what the Glean SDK does, but this is on purpose. On the Glean SDK we panic when we can't serialize the persisted value, that is because this is an extremely unlikely situation for that environment.

    Since Glean.js will run on the browser, it is easy for a consumers / developers to mess with the storage which makes this sort of errors plausible. That is why we choose to not panic and simply delete the corrupted data here.

    Note: This is not a strong guard against consumers / developers messing with the storage on their own. Currently Glean.js does not include mechanisms to reliably prevent that.

    Type parameters

    Parameters

    • ping: string

      The ping from which we want to retrieve the given metric.

    • metric: MetricType

      An object containing the information about the metric to retrieve.

    Returns Promise<undefined | T>

    The payload persisted for the given metric, undefined in case the metric has not been recorded yet or the found valus in invalid.

getPingMetrics

  • getPingMetrics(ping: string, clearPingLifetimeData: boolean): Promise<undefined | Metrics>
  • Gets all of the persisted metrics related to a given ping.

    Parameters

    • ping: string

      The name of the ping to retrieve.

    • clearPingLifetimeData: boolean

      Whether or not to clear the ping lifetime metrics retrieved.

    Returns Promise<undefined | Metrics>

    An object containing all the metrics recorded to the given ping, undefined in case the ping doesn't contain any recorded metrics.

hasMetric

  • hasMetric(lifetime: Lifetime, ping: string, metricType: string, metricIdentifier: string): Promise<boolean>
  • Checks if anything was stored for the provided metric.

    Parameters

    • lifetime: Lifetime

      the metric Lifetime.

    • ping: string

      the ping storage to search in.

    • metricType: string

      the type of the metric.

    • metricIdentifier: string

      the metric identifier.

    Returns Promise<boolean>

    true if the metric was found (regardless of the validity of the stored data), false otherwise.

Private processLabeledMetric

  • processLabeledMetric(snapshot: Metrics, metricType: string, metricId: string, metricData: JSONValue): void

record

transform

Generated using TypeDoc