-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional latency metrics to query service
Adding some additoinal metrics to the query service. This will allow us to see which operations take a long time. If query service takes a long time, but indexer/store are fast, then there is something withing the RunQuery body taking too long.
- Loading branch information
Jordan Pellizzari
committed
Dec 14, 2023
1 parent
dbfa652
commit 1d69664
Showing
3 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package metrics | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const queryServiceSubSystem = "query" | ||
|
||
const RunQueryAction = "RunQuery" | ||
|
||
const ( | ||
FailedLabel = "error" | ||
SuccessLabel = "success" | ||
) | ||
|
||
var QueryServiceLatencyHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{ | ||
Subsystem: queryServiceSubSystem, | ||
Name: "latency_seconds", | ||
Help: "query service latency", | ||
Buckets: prometheus.LinearBuckets(0.01, 0.01, 10), | ||
}, []string{"action", "status"}) | ||
|
||
func QueryServiceSetLatency(action string, status string, duration time.Duration) { | ||
QueryServiceLatencyHistogram.WithLabelValues(action, status).Observe(duration.Seconds()) | ||
} | ||
|
||
func init() { | ||
prometheus.MustRegister(QueryServiceLatencyHistogram) | ||
} | ||
|
||
func AssertMetrics(t *testing.T, ts *httptest.Server, expMetrics []string) { | ||
resp, err := http.Get(ts.URL) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
b, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
metrics := string(b) | ||
|
||
fmt.Println(metrics) | ||
|
||
for _, expMetric := range expMetrics { | ||
if !strings.Contains(metrics, expMetric) { | ||
t.Errorf("Expected metric not found: %s", expMetric) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters