Commit b0361124 by Carl Bergquist Committed by GitHub

remove status label from histogram (#28387)

Signed-off-by: bergquist <carl.bergquist@gmail.com>
parent 8032b438
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
var ( var (
databaseQueryCounter *prometheus.CounterVec databaseQueryCounter *prometheus.CounterVec
databaseQueryHistogram *prometheus.HistogramVec databaseQueryHistogram prometheus.Histogram
) )
func init() { func init() {
...@@ -28,12 +28,12 @@ func init() { ...@@ -28,12 +28,12 @@ func init() {
Help: "The total amount of Database queries", Help: "The total amount of Database queries",
}, []string{"status"}) }, []string{"status"})
databaseQueryHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ databaseQueryHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "grafana", Namespace: "grafana",
Name: "database_queries_duration_seconds", Name: "database_queries_duration_seconds",
Help: "Database query histogram", Help: "Database query histogram",
Buckets: prometheus.ExponentialBuckets(0.0001, 4, 9), Buckets: prometheus.ExponentialBuckets(0.0001, 4, 9),
}, []string{"status"}) })
prometheus.MustRegister(databaseQueryCounter, databaseQueryHistogram) prometheus.MustRegister(databaseQueryCounter, databaseQueryHistogram)
} }
...@@ -78,7 +78,7 @@ func (h *databaseQueryWrapper) After(ctx context.Context, query string, args ... ...@@ -78,7 +78,7 @@ func (h *databaseQueryWrapper) After(ctx context.Context, query string, args ...
begin := ctx.Value(databaseQueryWrapperKey{}).(time.Time) begin := ctx.Value(databaseQueryWrapperKey{}).(time.Time)
elapsed := time.Since(begin) elapsed := time.Since(begin)
databaseQueryCounter.WithLabelValues("success").Inc() databaseQueryCounter.WithLabelValues("success").Inc()
databaseQueryHistogram.WithLabelValues("success").Observe(elapsed.Seconds()) databaseQueryHistogram.Observe(elapsed.Seconds())
h.log.Debug("query finished", "status", "success", "elapsed time", elapsed, "sql", query) h.log.Debug("query finished", "status", "success", "elapsed time", elapsed, "sql", query)
return ctx, nil return ctx, nil
} }
...@@ -94,7 +94,7 @@ func (h *databaseQueryWrapper) OnError(ctx context.Context, err error, query str ...@@ -94,7 +94,7 @@ func (h *databaseQueryWrapper) OnError(ctx context.Context, err error, query str
begin := ctx.Value(databaseQueryWrapperKey{}).(time.Time) begin := ctx.Value(databaseQueryWrapperKey{}).(time.Time)
elapsed := time.Since(begin) elapsed := time.Since(begin)
databaseQueryCounter.WithLabelValues(status).Inc() databaseQueryCounter.WithLabelValues(status).Inc()
databaseQueryHistogram.WithLabelValues(status).Observe(elapsed.Seconds()) databaseQueryHistogram.Observe(elapsed.Seconds())
h.log.Debug("query finished", "status", status, "elapsed time", elapsed, "sql", query, "error", err) h.log.Debug("query finished", "status", status, "elapsed time", elapsed, "sql", query, "error", err)
return err return err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment