@@ -13,8 +13,8 @@ import (
1313 "github.com/pkg/errors"
1414 "github.com/prometheus/client_golang/prometheus"
1515 "github.com/prometheus/client_golang/prometheus/promauto"
16- "github.com/prometheus/prometheus/promql/parser"
1716 "github.com/thanos-io/thanos/internal/cortex/querier/queryrange"
17+ "github.com/thanos-io/thanos/pkg/extpromql"
1818 "github.com/weaveworks/common/httpgrpc"
1919)
2020
@@ -29,26 +29,28 @@ type protectionMiddleware struct {
2929
3030// NewProtectionMiddleware creates a new middleware that applies protection rules to queries.
3131func NewProtectionMiddleware (engine * ProtectionEngine , logger log.Logger , reg prometheus.Registerer ) queryrange.Middleware {
32+ durationBuckets := []float64 {0.0001 , 0.00025 , 0.0005 , 0.001 , 0.005 , 0.01 , 0.1 , 1.0 , 10.0 }
33+
3234 parseLatency := promauto .With (reg ).NewHistogram (prometheus.HistogramOpts {
3335 Namespace : "thanos" ,
3436 Subsystem : "query_frontend" ,
3537 Name : "protection_parse_duration_seconds" ,
3638 Help : "Duration of PromQL parsing in the protection middleware." ,
37- Buckets : prometheus . DefBuckets ,
39+ Buckets : durationBuckets ,
3840 })
3941 evalLatency := promauto .With (reg ).NewHistogram (prometheus.HistogramOpts {
4042 Namespace : "thanos" ,
4143 Subsystem : "query_frontend" ,
4244 Name : "protection_evaluate_duration_seconds" ,
4345 Help : "Duration of rule evaluation in the protection middleware." ,
44- Buckets : prometheus . DefBuckets ,
46+ Buckets : durationBuckets ,
4547 })
4648 totalLatency := promauto .With (reg ).NewHistogram (prometheus.HistogramOpts {
4749 Namespace : "thanos" ,
4850 Subsystem : "query_frontend" ,
4951 Name : "protection_duration_seconds" ,
5052 Help : "Total duration of the protection middleware, including parsing and evaluation." ,
51- Buckets : prometheus . DefBuckets ,
53+ Buckets : durationBuckets ,
5254 })
5355
5456 return queryrange .MiddlewareFunc (func (next queryrange.Handler ) queryrange.Handler {
@@ -74,7 +76,7 @@ func (m *protectionMiddleware) Do(ctx context.Context, r queryrange.Request) (qu
7476
7577 // Parse PromQL and measure latency.
7678 parseStart := time .Now ()
77- parsed , err := parser .ParseExpr (query )
79+ parsed , err := extpromql .ParseExpr (query )
7880 m .parseLatency .Observe (time .Since (parseStart ).Seconds ())
7981
8082 if err != nil {
0 commit comments