Data Sources: Add gauge for response size (#104394)

This commit is contained in:
Andreas Christou
2025-04-24 13:26:28 +01:00
committed by GitHub
parent a8aa6b74a8
commit 35145801a2
@@ -43,6 +43,14 @@ var (
}, []string{"datasource", "datasource_type", "secure_socks_ds_proxy_enabled"},
)
datasourceResponseGauge = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "plugins",
Name: "datasource_response_size",
Help: "gauge of external data source response sizes returned to Grafana in bytes",
}, []string{"datasource", "datasource_type", "secure_socks_ds_proxy_enabled"},
)
datasourceRequestsInFlight = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "grafana",
@@ -102,6 +110,7 @@ func executeMiddleware(next http.RoundTripper, labels prometheus.Labels) http.Ro
requestHistogram := datasourceRequestHistogram.MustCurryWith(labels)
requestInFlight := datasourceRequestsInFlight.With(labels)
responseSizeHistogram := datasourceResponseHistogram.With(labels)
responseSizeGauge := datasourceResponseGauge.With(labels)
res, err := promhttp.InstrumentRoundTripperDuration(requestHistogram,
promhttp.InstrumentRoundTripperCounter(requestCounter,
@@ -114,6 +123,7 @@ func executeMiddleware(next http.RoundTripper, labels prometheus.Labels) http.Ro
if res != nil && res.StatusCode != http.StatusSwitchingProtocols {
res.Body = sdkhttpclient.CountBytesReader(res.Body, func(bytesRead int64) {
responseSizeHistogram.Observe(float64(bytesRead))
responseSizeGauge.Set(float64(bytesRead))
})
}