Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge pull request #142 from cloudflare/series" #143

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# Changelog

## [next]

### Changed

- `query/series` check now uses `/api/v1/series` Prometheus API instead of running
instant queries.

## v0.9.0

### Changed
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/tests/0043_watch_cancel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pint.ok --no-color watch --interval=1h --listen=:6043 --pidfile=pint.pid rules
! stdout .
stderr 'level=info msg="Shutting down"'
stderr 'level=error msg="Failed to query Prometheus configuration" error="Get \\"http://127.0.0.1:7043/api/v1/status/config\\": context canceled" uri=http://127.0.0.1:7043'
stderr 'level=error msg="Query failed" error="Get \\"http://127.0.0.1:7043\/api\/v1\/series\?end=.+&match%5B%5D=foo&start=.+\\": context canceled" matches=\["foo"\] uri=http://127.0.0.1:7043'
stderr 'level=error msg="Query failed" error="Post \\"http://127.0.0.1:7043/api/v1/query\\": context canceled" query=count\(foo\) uri=http://127.0.0.1:7043'
stderr 'level=info msg="Waiting for all background tasks to finish"'
stderr 'level=info msg="Background worker finished"'

Expand Down
10 changes: 8 additions & 2 deletions internal/checks/query_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func (c SeriesCheck) Check(ctx context.Context, rule parser.Rule) (problems []Pr
}

func (c SeriesCheck) countSeries(ctx context.Context, expr parser.PromQLExpr, selector promParser.VectorSelector) (problems []Problem) {
sets, err := c.prom.Series(ctx, []string{selector.String()})
q := fmt.Sprintf("count(%s)", selector.String())
qr, err := c.prom.Query(ctx, q)
if err != nil {
problems = append(problems, Problem{
Fragment: selector.String(),
Expand All @@ -71,7 +72,12 @@ func (c SeriesCheck) countSeries(ctx context.Context, expr parser.PromQLExpr, se
return
}

if len(sets) == 0 {
var series int
for _, s := range qr.Series {
series += int(s.Value)
}

if series == 0 {
if len(selector.LabelMatchers) > 1 {
// retry selector with only __name__ label
s := stripLabels(selector)
Expand Down
66 changes: 41 additions & 25 deletions internal/checks/query_series_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package checks_test
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

Expand All @@ -17,65 +16,82 @@ func TestSeriesCheck(t *testing.T) {
zerolog.SetGlobalLevel(zerolog.FatalLevel)

srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
match := r.URL.Query()[("match[]")]
err := r.ParseForm()
if err != nil {
t.Fatal(err)
}
query := r.Form.Get("query")

switch strings.Join(match, ", ") {
case "notfound", `notfound{job="foo"}`, `notfound{job!="foo"}`, `{__name__="notfound",job="bar"}`:
switch query {
case "count(notfound)", `count(notfound{job="foo"})`, `count(notfound{job!="foo"})`, `count({__name__="notfound",job="bar"})`:
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{
"status":"success",
"data": []
"data":{
"resultType":"vector",
"result":[]
}
}`))
case "found_1", `{__name__="notfound"}`:
case "count(found_1)", `count({__name__="notfound"})`:
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{
"status":"success",
"data": [{"__name__":"single", "foo": "bar"}]
"data":{
"resultType":"vector",
"result":[{"metric":{},"value":[1614859502.068,"1"]}]
}
}`))
case "found_7":
case "count(found_7)":
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{
"status":"success",
"data": [
{"__name__":"seven", "id": "1"},
{"__name__":"seven", "id": "2"},
{"__name__":"seven", "id": "3"},
{"__name__":"seven", "id": "4"},
{"__name__":"seven", "id": "5"},
{"__name__":"seven", "id": "6"},
{"__name__":"seven", "id": "7"}
]
"data":{
"resultType":"vector",
"result":[{"metric":{},"value":[1614859502.068,"7"]}]
}
}`))
case `node_filesystem_readonly{mountpoint!=""}`:
case `count(node_filesystem_readonly{mountpoint!=""})`:
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{
"status":"success",
"data": [{"__name__":"single", "foo": "bar"}]
"data":{
"resultType":"vector",
"result":[{"metric":{},"value":[1614859502.068,"1"]}]
}
}`))
case `disk_info{interface_speed!="6.0 Gb/s",type="sat"}`:
case `count(disk_info{interface_speed!="6.0 Gb/s",type="sat"})`:
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{
"status":"success",
"data": [{"__name__":"disk_info"}]
"data":{
"resultType":"vector",
"result":[{"metric":{},"value":[1614859502.068,"1"]}]
}
}`))
case `found{job="notfound"}`, `notfound{job="notfound"}`:
case `count(found{job="notfound"})`, `count(notfound{job="notfound"})`:
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{
"status":"success",
"data": []
"data":{
"resultType":"vector",
"result":[]
}
}`))
case `found`:
case `count(found)`:
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{
"status":"success",
"data": [{"__name__":"found"}]
"data":{
"resultType":"vector",
"result":[{"metric":{},"value":[1614859502.068,"1"]}]
}
}`))
default:
w.WriteHeader(400)
Expand Down
56 changes: 0 additions & 56 deletions internal/promapi/series.go

This file was deleted.

Loading