001package io.prometheus.metrics.core.datapoints;
002
003import io.prometheus.metrics.annotations.StableApi;
004import io.prometheus.metrics.model.snapshots.Labels;
005
006/**
007 * Represents a single data point of a histogram or a summary metric.
008 *
009 * <p>Single data point means identified label values like {@code {method="GET", path="/",
010 * status_code="200"}}, ignoring the {@code "le"} label for histograms or the {@code "quantile"}
011 * label for summaries.
012 *
013 * <p>This interface is named <i>DistributionDataPoint</i> because both histograms and summaries are
014 * used to observe distributions, like latency distributions or distributions of request sizes.
015 * Therefore <i>DistributionDataPoint</i> is a good name for a common interface implemented by
016 * histogram data points and summary data points.
017 *
018 * <p>See JavaDoc of {@link CounterDataPoint} on how using data points directly can improve
019 * performance.
020 */
021@StableApi
022public interface DistributionDataPoint extends DataPoint, TimerApi {
023
024  /** Get the count of observations. */
025  long getCount();
026
027  /** Get the sum of all observed values. */
028  double getSum();
029
030  /** Observe {@code value}. */
031  void observe(double value);
032
033  /** Observe {@code value}, and create a custom exemplar with the given labels. */
034  void observeWithExemplar(double value, Labels labels);
035
036  @Override
037  default Timer startTimer() {
038    return new Timer(this::observe);
039  }
040}