NewInstrumented wraps a Gate implementation with one that records max number of inflight requests, currently inflight requests, and the duration of calls to the Start method.
(reg prometheus.Registerer, maxConcurrent int, gate Gate)
| 54 | // NewInstrumented wraps a Gate implementation with one that records max number of inflight |
| 55 | // requests, currently inflight requests, and the duration of calls to the Start method. |
| 56 | func NewInstrumented(reg prometheus.Registerer, maxConcurrent int, gate Gate) Gate { |
| 57 | g := &instrumentedGate{ |
| 58 | gate: gate, |
| 59 | max: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ |
| 60 | Name: "gate_queries_concurrent_max", |
| 61 | Help: "Number of maximum concurrent queries allowed.", |
| 62 | }), |
| 63 | inflight: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ |
| 64 | Name: "gate_queries_in_flight", |
| 65 | Help: "Number of queries that are currently in flight.", |
| 66 | }), |
| 67 | duration: promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ |
| 68 | Name: "gate_duration_seconds", |
| 69 | Help: "How many seconds it took for queries to wait at the gate.", |
| 70 | Buckets: []float64{0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720}, |
| 71 | // Use defaults recommended by Prometheus for native histograms. |
| 72 | NativeHistogramBucketFactor: 1.1, |
| 73 | NativeHistogramMaxBucketNumber: 100, |
| 74 | NativeHistogramMinResetDuration: time.Hour, |
| 75 | }, []string{"outcome"}), |
| 76 | } |
| 77 | |
| 78 | g.max.Set(float64(maxConcurrent)) |
| 79 | return g |
| 80 | } |
| 81 | |
| 82 | type instrumentedGate struct { |
| 83 | gate Gate |