Module metric

Source
Expand description

Defines the public components of the metric system.

§Design

The main design goals of this system are:

  • Use lockless operations, preferably ones that don’t require anything other than simple reads/writes being atomic.
  • Exploit interior mutability and atomics being Sync to allow all methods (including the ones which are effectively mutable) to be callable on a global non-mut static.
  • Rely on serde to provide the actual serialization for writing the metrics.
  • Since all metrics start at 0, we implement the Default trait via derive for all of them, to avoid having to initialize everything by hand.

The system implements 2 types of metrics:

  • Shared Incremental Metrics (SharedIncMetrics) - dedicated for the metrics which need a counter (i.e the number of times an API request failed). These metrics are reset upon flush.
  • Shared Store Metrics (SharedStoreMetrics) - are targeted at keeping a persistent value, it is not intended to act as a counter (i.e for measure the process start up time for example).

The current approach for the SharedIncMetrics type is to store two values (current and previous) and compute the delta between them each time we do a flush (i.e by serialization). There are a number of advantages to this approach, including:

  • We don’t have to introduce an additional write (to reset the value) from the thread which does to actual writing, so less synchronization effort is required.
  • We don’t have to worry at all that much about losing some data if writing fails for a while (this could be a concern, I guess). If if turns out this approach is not really what we want, it’s pretty easy to resort to something else, while working behind the same interface.

Structs§

SharedIncMetric
Representation of a metric that is expected to be incremented from more than one thread, so more synchronization is necessary.
SharedStoreMetric
Representation of a metric that is expected to hold a value that can be accessed from more than one thread, so more synchronization is necessary.

Traits§

IncMetric
Used for defining new types of metrics that act as a counter (i.e they are continuously updated by incrementing their value).
StoreMetric
Used for defining new types of metrics that do not need a counter and act as a persistent indicator.