Skip to content

Commit

Permalink
fmt: format load strings and promql in tests
Browse files Browse the repository at this point in the history
* added small tool to automatically format tests
* reformatted all tests

Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
  • Loading branch information
MichaHoffmann committed Jun 8, 2024
1 parent b1c0214 commit a059bcd
Show file tree
Hide file tree
Showing 8 changed files with 1,532 additions and 1,339 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ check-docs: $(MDOX)
format: $(GOIMPORTS)
@echo ">> formatting go code"
@gofmt -s -w $(FILES_TO_FMT)
@echo ">> formatting promql tests"
@go run scripts/testvet/main.go -json -fix ./...
@echo ">> formatting imports"
@$(GOIMPORTS) -w $(FILES_TO_FMT)

.PHONY:lint
Expand Down
74 changes: 37 additions & 37 deletions engine/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,37 +137,37 @@ func BenchmarkRangeQuery(b *testing.B) {
}{
{
name: "vector selector",
query: "http_requests_total",
query: `http_requests_total`,
storage: sixHourDataset,
},
{
name: "sum",
query: "sum(http_requests_total)",
query: `sum(http_requests_total)`,
storage: sixHourDataset,
},
{
name: "sum by pod",
query: "sum by (pod) (http_requests_total)",
query: `sum by (pod) (http_requests_total)`,
storage: sixHourDataset,
},
{
name: "topk",
query: "topk(2,http_requests_total)",
query: `topk(2, http_requests_total)`,
storage: sixHourDataset,
},
{
name: "bottomk",
query: "bottomk(2,http_requests_total)",
query: `bottomk(2, http_requests_total)`,
storage: sixHourDataset,
},
{
name: "rate",
query: "rate(http_requests_total[1m])",
query: `rate(http_requests_total[1m])`,
storage: sixHourDataset,
},
{
name: "subquery",
query: "sum_over_time(rate(http_requests_total[1m])[10m:1m])",
query: `sum_over_time(rate(http_requests_total[1m])[10m:1m])`,
storage: sixHourDataset,
},
/*
Expand All @@ -189,27 +189,27 @@ func BenchmarkRangeQuery(b *testing.B) {
*/
{
name: "sum rate",
query: "sum(rate(http_requests_total[1m]))",
query: `sum(rate(http_requests_total[1m]))`,
storage: sixHourDataset,
},
{
name: "sum by rate",
query: "sum by (pod) (rate(http_requests_total[1m]))",
query: `sum by (pod) (rate(http_requests_total[1m]))`,
storage: sixHourDataset,
},
{
name: "quantile with variable parameter",
query: "quantile by (pod) (scalar(min(http_requests_total)), http_requests_total)",
query: `quantile by (pod) (scalar(min(http_requests_total)), http_requests_total)`,
storage: sixHourDataset,
},
{
name: "binary operation with one to one",
query: `http_requests_total{container="c1"} / ignoring(container) http_responses_total`,
query: `http_requests_total{container="c1"} / ignoring (container) http_responses_total`,
storage: sixHourDataset,
},
{
name: "binary operation with many to one",
query: `http_requests_total / on (pod) group_left http_responses_total`,
query: `http_requests_total / on (pod) group_left () http_responses_total`,
storage: sixHourDataset,
},
{
Expand All @@ -229,17 +229,17 @@ func BenchmarkRangeQuery(b *testing.B) {
},
{
name: "positive offset vector",
query: "http_requests_total offset 5m",
query: `http_requests_total offset 5m`,
storage: sixHourDataset,
},
{
name: "at modifier ",
query: "http_requests_total @ 600",
query: `http_requests_total @ 600.000`,
storage: sixHourDataset,
},
{
name: "at modifier with positive offset vector",
query: "http_requests_total @ 600 offset 5m",
query: `http_requests_total @ 600.000 offset 5m`,
storage: sixHourDataset,
},
{
Expand Down Expand Up @@ -354,43 +354,43 @@ func BenchmarkNativeHistograms(b *testing.B) {
}{
{
name: "selector",
query: "native_histogram_series",
query: `native_histogram_series`,
},
{
name: "sum",
query: "sum(native_histogram_series)",
query: `sum(native_histogram_series)`,
},
{
name: "rate",
query: "rate(native_histogram_series[1m])",
query: `rate(native_histogram_series[1m])`,
},
{
name: "sum rate",
query: "sum(rate(native_histogram_series[1m]))",
query: `sum(rate(native_histogram_series[1m]))`,
},
{
name: "histogram_sum",
query: "histogram_sum(native_histogram_series)",
query: `histogram_sum(native_histogram_series)`,
},
{
name: "histogram_count with rate",
query: "histogram_count(rate(native_histogram_series[1m]))",
query: `histogram_count(rate(native_histogram_series[1m]))`,
},
{
name: "histogram_count",
query: "histogram_count(native_histogram_series)",
query: `histogram_count(native_histogram_series)`,
},
{
name: "histogram_count with sum and rate",
query: "histogram_count(sum(rate(native_histogram_series[1m])))",
query: `histogram_count(sum(rate(native_histogram_series[1m])))`,
},
{
name: "histogram_quantile",
query: "histogram_quantile(0.9, sum(native_histogram_series))",
query: `histogram_quantile(0.9, sum(native_histogram_series))`,
},
{
name: "histogram scalar binop",
query: "sum(native_histogram_series * 60)",
query: `sum(native_histogram_series * 60)`,
},
}

Expand Down Expand Up @@ -449,51 +449,51 @@ func BenchmarkInstantQuery(b *testing.B) {
}{
{
name: "vector selector",
query: "http_requests_total",
query: `http_requests_total`,
},
{
name: "count",
query: "count(http_requests_total)",
query: `count(http_requests_total)`,
},
{
name: "count_values",
query: "count_values('val', http_requests_total)",
query: `count_values("val", http_requests_total)`,
},
{
name: "round",
query: "round(http_requests_total)",
query: `round(http_requests_total)`,
},
{
name: "round with argument",
query: "round(http_requests_total, 0.5)",
query: `round(http_requests_total, 0.5)`,
},
{
name: "avg",
query: "avg(http_requests_total)",
query: `avg(http_requests_total)`,
},
{
name: "sum",
query: "sum(http_requests_total)",
query: `sum(http_requests_total)`,
},
{
name: "sum by pod",
query: "sum by (pod) (http_requests_total)",
query: `sum by (pod) (http_requests_total)`,
},
{
name: "rate",
query: "rate(http_requests_total[1m])",
query: `rate(http_requests_total[1m])`,
},
{
name: "sum rate",
query: "sum(rate(http_requests_total[1m]))",
query: `sum(rate(http_requests_total[1m]))`,
},
{
name: "sum by rate",
query: "sum by (pod) (rate(http_requests_total[1m]))",
query: `sum by (pod) (rate(http_requests_total[1m]))`,
},
{
name: "binary operation with many to one",
query: `http_requests_total / on (pod) group_left http_responses_total`,
query: `http_requests_total / on (pod) group_left () http_responses_total`,
},
{
name: "unary negation",
Expand Down
4 changes: 2 additions & 2 deletions engine/distributed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ func TestDistributedAggregations(t *testing.T) {
rangeStart: time.Unix(7, 0),
query: `max_over_time(min_over_time(sum(bar)[15s:15s])[15s:15s])`,
},
{name: "subquery over distributed binary expression", query: `max_over_time((bar/bar)[30s:15s])`},
{name: "subquery over distributed binary expression", query: `max_over_time((bar / bar)[30s:15s])`},
{name: "timestamp", query: `timestamp(bar)`},
{name: "timestamp - step invariant", query: `timestamp(bar @ 6000)`},
{name: "timestamp - step invariant", query: `timestamp(bar @ 6000.000)`},
}

lookbackDeltas := []time.Duration{0, 30 * time.Second, 5 * time.Minute}
Expand Down
Loading

0 comments on commit a059bcd

Please sign in to comment.