-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export: Added "promtest" framework allowing tests against GCM and Pro…
…metheus; Added counter test. Signed-off-by: bwplotka <bwplotka@google.com>
- Loading branch information
Showing
56 changed files
with
6,004 additions
and
6 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/build | ||
/**/node_modules/.cache | ||
.idea/ | ||
e2e_* | ||
.idea/ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package export_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/GoogleCloudPlatform/prometheus-engine/pkg/export/promtest" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func TestExportGCM_CounterReset(t *testing.T) { | ||
const interval = 30 * time.Second | ||
|
||
prom := promtest.Prometheus("quay.io/prometheus/prometheus:v2.47.2") | ||
export := promtest.LocalExportWithGCM(promtest.GCMServiceAccountOrSkip(t)) | ||
|
||
it := promtest.NewIngestionTest(t, []promtest.Backend{prom, export}) | ||
|
||
counter := prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Name: "pe_test_counter_total", | ||
Help: "Test counter used by prometheus-engine export GCM acceptance tests.", | ||
}, []string{"foo"}) | ||
var c prometheus.Counter | ||
|
||
it.RecordScrapes(func(r prometheus.Registerer, scrape promtest.Scrape) { | ||
r.MustRegister(counter) | ||
|
||
// No metric. | ||
scrape(interval) | ||
|
||
c = counter.WithLabelValues("bar") | ||
c.Add(200) | ||
|
||
scrape(interval). | ||
Expect(200, c, prom) | ||
// Nothing is expected for GMP due to cannibalization. | ||
// TODO(bwplotka): Fix with b/259261536. | ||
|
||
c.Add(10) | ||
scrape(interval). | ||
Expect(10, c, export). | ||
Expect(210, c, prom) | ||
|
||
c.Add(50) | ||
scrape(interval). | ||
Expect(60, c, export). | ||
Expect(260, c, prom) | ||
|
||
// Reset to 0, then add something that still should indicate "decreased counter" | ||
// in absolute values, but our current cannibalization logic is wrong here. | ||
// It's perhaps unusual that reset happens without scrape target restart | ||
// so, it was easy to forget about this case. | ||
counter.Reset() | ||
c = counter.WithLabelValues("bar") | ||
c.Add(250) | ||
scrape(interval). | ||
Expect(310, c, export). // TODO(bwplotka): Fix with b/259261536. | ||
Expect(250, c, prom) | ||
|
||
c.Add(50) | ||
scrape(interval). | ||
Expect(360, c, export). | ||
Expect(300, c, prom) | ||
|
||
// Reset to 0 again, our export does not detect it again. | ||
counter.Reset() | ||
c = counter.WithLabelValues("bar") | ||
c.Add(100) | ||
scrape(interval). | ||
Expect(460, c, export). // TODO(bwplotka): Fix with b/259261536. | ||
Expect(100, c, prom) | ||
|
||
c.Add(50) | ||
scrape(interval). | ||
Expect(510, c, export). | ||
Expect(150, c, prom) | ||
|
||
// Tricky reset case, unnoticeable reset for Prometheus without created timestamp as well. | ||
counter.Reset() | ||
c = counter.WithLabelValues("bar") | ||
c.Add(600) | ||
scrape(interval). | ||
// TODO(bwplotka): Fix using created timestamp. | ||
Expect(960, c, export). // Also something is off, why 960, not 1110? | ||
Expect(600, c, prom) | ||
}) | ||
|
||
// Expect what we set we want for each backend. | ||
for _, b := range []promtest.Backend{export, prom} { | ||
t.Run(b.Ref(), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
it.FatalOnUnexpectedPromQLResults(b, c, 2*time.Minute) | ||
}) | ||
} | ||
} |
Oops, something went wrong.