Add createInt64FnGauge / createDoubleFnGauge to MetricsService

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Networking & Observability
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      MetricsService currently supports Gauge<T> via createInt64Gauge / createDoubleGauge. These are push-based: callers call set(value) to store a value, and OTel reads the stored value at collection time via an internal observableCallback.

      Some metrics are most naturally expressed as live computations rather than stored state. For example, "replication lag" should be evaluated at OTel collection time so it reflects the true current lag, not the lag at whatever point the caller last called set(). Storing a pre-computed value requires the caller to update it continuously, or accept that it is stale between updates.

      This ticket propose to add a function-based gauge variant. Callers register a std::function<T()> at metric creation time. MetricsService calls the function whenever OTel collects the metric or serverStatus is serialized. No stored state, no staleness.

      Important considerations

      Objects captured by fn must outlive MetricsService (program lifetime). This must be documented in the API comment. In practice callers should only capture: Atomics or other members of objects with program lifetime (static members, Meyers singletons, ServiceContext::Decoration instances, etc.)

            Assignee:
            Unassigned
            Reporter:
            Ernesto Rodriguez Reina
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: