package com.twitter.finagle.stats

/**
 * A StatsReceiver proxy that configures all counters, stats, and gauges marked as KeyIndicators.
 * This is used with [[ReadableIndicator]].
 *
 * @param self The underlying StatsReceiver to which modified schemas are passed
 */
private[finagle] class KeyIndicatorMarkingStatsReceiver(protected val self: StatsReceiver)
    extends StatsReceiverProxy {

  override def counter(counterSchema: CounterSchema): Counter = {
    self.counter(CounterSchema(counterSchema.metricBuilder.withKeyIndicator()))
  }

  override def stat(histogramSchema: HistogramSchema): Stat = {
    self.stat(HistogramSchema(histogramSchema.metricBuilder.withKeyIndicator()))
  }

  override def addGauge(gaugeSchema: GaugeSchema)(f: => Float): Gauge = {
    self.addGauge(GaugeSchema(gaugeSchema.metricBuilder.withKeyIndicator()))(f)
  }
}

Mark SLIs as key indicators in Metrics Metadata
finagle-internal/slo: Mark SLIs as key indicators in Metrics Metadata

Problem

The user-defined SLIs in SLO can be seen as more important metrics. And we want
to mark these metrics in the metrics metadata for future usage.

Solution

The `keyIndicator` field is already defined in the MetricBuilder and by default
the value is false.  If a metric is instrumented through SLO indicators, the
`keyIndicator` should be filled as true.  Introduce the
KeyIndicatorMarkingStatsReceiverProxy for this purpose.

JIRA Issues: CSL-9961

Differential Revision: https://phabricator.twitter.biz/D568839
