envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.86k stars 4.78k forks source link

Prometheus histogram buckets act like upper bound exclusive #36549

Open sekar-saravanan opened 3 days ago

sekar-saravanan commented 3 days ago

Title: Prometheus histogram buckets act like upper bound exclusive

Description: I am using the metrics exposed by Envoy at the endpoint /stats/prometheus. I've encountered an issue with the latency metric being added to the histogram buckets. Specifically, when the latency matches the upper bound of a bucket, it falls into the next bucket instead.
For instance, I have configured the following histogram buckets (in milliseconds): [1, 5, 10, 25, 50, 100, 150, 200, 250, 300, 350, 400, 500, 1000, 5000, 10000, 30000].

This behavior seems to indicate that the configuration is upper bound exclusive.

  1. Is this behavior expected?
  2. If it is upper bound exclusive, why is it labeled with le (less than or equal to)?
  3. Is there any way to make this configuration upper bound inclusive ?

In the attached screenshot, you can see the following statistics:

But the count added as below

I verified this information on the stats endpoint (as shown in the attached screenshot) and in the stats sink (also shown in the attached screenshot).

Other details: Currently, using emissary-ingress as a wrapper on top of envoy

  1. Emissary-Ingress version: 3.9
  2. Envoy version: 1.27.2

Verified the same behaviour with Envoy Gateway as wrapper on top of envoy.

  1. Envoy Gateway version: 1.1
  2. Envoy version: 1.31.0

Repro steps: Please generate requests with latencies that match some of the configured histogram buckets. For example, if the buckets are set as follows (in milliseconds): [1, 5, 10, 25, 50, 100, 150, 200, 250, 300, 350, 400, 500, 1000, 5000, 10000, 30000], you could generate a request with a latency of 25ms.

stats_active-html-view stats_metrics stats_sink_listen_latency

alyssawilk commented 3 days ago

cc @jmarantz