Skip to content

feat(tools): add debug printouts to rules unit testing#15196

Merged
krajorama merged 3 commits intomainfrom
promtool-debug
Oct 22, 2024
Merged

feat(tools): add debug printouts to rules unit testing#15196
krajorama merged 3 commits intomainfrom
promtool-debug

Conversation

@krajorama
Copy link
Member

This makes it print out the tsdb state (both input_series and rules that
are run) at the end of a test, making reasoning about tests much easier.

Originally by @dlg
Continued from #8349 .

dgl and others added 2 commits September 6, 2023 10:33
This makes it print out the tsdb state (both input_series and rules that
are run) at the end of a test, making reasoning about tests much easier.

Signed-off-by: David Leadbeater <dgl@dgl.cx>
# Conflicts:
#	cmd/promtool/main.go
#	cmd/promtool/unittest.go
#	cmd/promtool/unittest_test.go
@krajorama krajorama requested a review from dgl as a code owner October 22, 2024 12:26
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
// Potentially a test can be specified at a time with fractional seconds,
// which PromQL cannot represent, so round up to the next whole second.
ts = (ts + time.Second).Truncate(time.Second)
expr := fmt.Sprintf(`{__name__=~".+"}[%v]`, ts)
Copy link
Member Author

@krajorama krajorama Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one issue here is that the engine is started with max samples == 10000, so I get an error when running with a lot of data:

$ ./promtool test rules --debug cmd/promtool/testdata/unittest.yml 
DEBUG: Starting test unnamed#0
DEBUG: Dump of all data (input_series and rules) at 5m1s:
{__name__="ALERTS", alertname="AlwaysFiring", alertstate="firing"} =>
1 @[60000]
1 @[120000]
1 @[180000]
1 @[240000]
1 @[300000]
{__name__="ALERTS_FOR_STATE", alertname="AlwaysFiring"} =>
0 @[60000]
0 @[120000]
0 @[180000]
0 @[240000]
0 @[300000]
{__name__="fixed_data"} =>
1 @[60000]
1 @[120000]
1 @[180000]
1 @[240000]
1 @[300000]
{__name__="test_full"} =>
0 @[60000]
{__name__="test_histogram_increase"} =>
{count:3, sum:4.3, (0.5,1]:3} @[60000]
{count:4, sum:5.6, (0.5,1]:4} @[120000]
{__name__="test_histogram_repeat"} =>
{count:2, sum:3, (0.5,1]:2} @[60000]
{count:2, sum:3, (0.5,1]:2} @[120000]
{__name__="test_increase"} =>
2 @[60000]
3 @[120000]
{__name__="test_repeat"} =>
1 @[60000]
1 @[120000]
DEBUG: Test unnamed#0 finished, took 21.667828ms
DEBUG: Starting test unnamed#1
DEBUG: Dump of all data (input_series and rules) at 1s:

DEBUG: Test unnamed#1 finished, took 18.396051ms
DEBUG: Starting test unnamed#2
DEBUG: Dump of all data (input_series and rules) at 1h0m1s:
<cut out by krajorama>
DEBUG: Test unnamed#2 finished, took 32.819317ms
DEBUG: Starting test unnamed#3
DEBUG: Failed query exec, expr: "{__name__=~\".+\"}[24h0m1s]", err: query processing would load too many samples into memory in query execution
DEBUG: Test unnamed#3 finished, took 648.141484ms
DEBUG: Starting test unnamed#4
<rest cut out by krajorama>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can fix in subsequent PR 👍🏽

@krajorama krajorama requested a review from bwplotka October 22, 2024 12:57
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 💪🏽

// Potentially a test can be specified at a time with fractional seconds,
// which PromQL cannot represent, so round up to the next whole second.
ts = (ts + time.Second).Truncate(time.Second)
expr := fmt.Sprintf(`{__name__=~".+"}[%v]`, ts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can fix in subsequent PR 👍🏽

@krajorama krajorama merged commit 1b4e7f7 into main Oct 22, 2024
@krajorama krajorama deleted the promtool-debug branch October 22, 2024 13:24
KeyOfSpectator added a commit to AliyunContainerService/prometheus that referenced this pull request Oct 23, 2024
* master: (667 commits)
  NHCB scrape: refactor state handling and speed up scrape test (prometheus#15193)
  feat(tools): add debug printouts to rules unit testing (prometheus#15196)
  docs: add keep_firing_for in alerting rules
  api: Add rule group pagination to list rules api (prometheus#14017)
  Update scrape/scrape.go
  benchmark, rename parser omtext_with_nhcb
  goimports run
  Better docstring on test
  Remove omcounterdata.txt as redundant
  Fix failing benchmarks
  Add unit test to show that current wrapper is sub-optimal
  Rename convert_classic_histograms to convert_classic_histograms_to_nhcb
  More followup to prometheus#15164
  Follow up prometheus#15178
  Followup to prometheus#15164
  test(cmd/prometheus): speed up test execution by t.Parallel() when possible
  feat: normalize "le" and "quantile" labels values upon ingestion
  scrape: provide a fallback format (prometheus#15136)
  Disallowing configure AM with the v1 api (prometheus#13883)
  feat: ProtobufParse.formatOpenMetricsFloat: improve float formatting by using strconv.AppendFloat instead of fmt.Sprint
  ...

# Conflicts:
#	go.mod
#	go.sum
@dlg
Copy link

dlg commented Oct 23, 2024

I think you meant to tag @dgl rather than dlg.

julienduchesne pushed a commit to julienduchesne/prometheus that referenced this pull request Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants