Skip to content

feat(nhcb): implement created timestamp handling#15198

Merged
krajorama merged 4 commits intomainfrom
nhcb-scrape-ct
Oct 24, 2024
Merged

feat(nhcb): implement created timestamp handling#15198
krajorama merged 4 commits intomainfrom
nhcb-scrape-ct

Conversation

@krajorama
Copy link
Member

@krajorama krajorama commented Oct 23, 2024

Follows #14978
Related to #13529
Fixes: #15137

Implement missing created timestamp handling

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Call through to the underlaying parser if we are not in a histogram
and the entry is a series or exponential native histogram.

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Fixes: #15137
Ignore exemplars while peeking ahead during CT parsing.
Simplify state reset with defer().

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
if ct := p.CreatedTimestamp(); ct != nil {
got.ct = int64p(*ct)
}
for e := (exemplar.Exemplar{}); p.Exemplar(&e); {
Copy link
Member Author

@krajorama krajorama Oct 23, 2024

Choose a reason for hiding this comment

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

Note to reviewers: this reordering is done to trigger #15137. And also means the tests use the same order that scrape.go actually does things.

@krajorama krajorama marked this pull request as ready for review October 23, 2024 08:39
@krajorama
Copy link
Member Author

krajorama commented Oct 23, 2024

Improved OM parser performance due to not fully parsing exemplars twice.
Overhead of CT on NHCB parser is +15%.

goos: linux
goarch: amd64
pkg: github.com/prometheus/prometheus/model/textparse
cpu: AMD Ryzen 7 4700U with Radeon Graphics         
                                                         │  main.txt   │               pr.txt               │
                                                         │   sec/op    │   sec/op     vs base               │
Parse/data=promtestdata.txt/parser=promtext-2              312.3µ ± 2%   315.2µ ± 3%        ~ (p=0.485 n=6)
Parse/data=promtestdata.txt/parser=xpfmt-2                 1.642m ± 5%   1.693m ± 4%        ~ (p=0.180 n=6)
Parse/data=promtestdata.nometa.txt/parser=promtext-2       238.7µ ± 2%   242.3µ ± 5%        ~ (p=0.589 n=6)
Parse/data=promtestdata.nometa.txt/parser=xpfmt-2          1.119m ± 6%   1.143m ± 3%        ~ (p=0.818 n=6)
Parse/data=createTestProtoBuf()/parser=promproto-2         103.6µ ± 7%   104.9µ ± 5%        ~ (p=0.699 n=6)
Parse/data=omtestdata.txt/parser=omtext-2                  66.92µ ± 3%   64.53µ ± 4%   -3.57% (p=0.026 n=6)
Parse/data=promtestdata.txt/parser=omtext-2                4.053m ± 1%   3.619m ± 2%  -10.72% (p=0.002 n=6)
Parse/data=omhistogramdata.txt/parser=omtext-2             358.8µ ± 2%   340.9µ ± 1%   -5.01% (p=0.002 n=6)
Parse/data=omhistogramdata.txt/parser=omtext_with_nhcb-2   127.0µ ± 6%   147.0µ ± 4%  +15.72% (p=0.002 n=6)
geomean                                                    382.5µ        384.0µ        +0.37%

                                                         │   main.txt    │               pr.txt                │
                                                         │      B/s      │     B/s       vs base               │
Parse/data=promtestdata.txt/parser=promtext-2               101.9Mi ± 2%   100.9Mi ± 3%        ~ (p=0.485 n=6)
Parse/data=promtestdata.txt/parser=xpfmt-2                  19.39Mi ± 5%   18.79Mi ± 4%        ~ (p=0.167 n=6)
Parse/data=promtestdata.nometa.txt/parser=promtext-2       100.93Mi ± 2%   99.43Mi ± 5%        ~ (p=0.589 n=6)
Parse/data=promtestdata.nometa.txt/parser=xpfmt-2           21.55Mi ± 6%   21.09Mi ± 3%        ~ (p=0.818 n=6)
Parse/data=createTestProtoBuf()/parser=promproto-2          35.39Mi ± 7%   34.96Mi ± 5%        ~ (p=0.623 n=6)
Parse/data=omtestdata.txt/parser=omtext-2                   63.81Mi ± 3%   66.17Mi ± 4%   +3.70% (p=0.026 n=6)
Parse/data=promtestdata.txt/parser=omtext-2                 7.849Mi ± 1%   8.793Mi ± 2%  +12.03% (p=0.002 n=6)
Parse/data=omhistogramdata.txt/parser=omtext-2              11.14Mi ± 2%   11.73Mi ± 1%   +5.27% (p=0.002 n=6)
Parse/data=omhistogramdata.txt/parser=omtext_with_nhcb-2    31.47Mi ± 7%   27.19Mi ± 4%  -13.61% (p=0.002 n=6)
geomean                                                     31.03Mi        30.91Mi        -0.39%

                                                         │   main.txt   │                pr.txt                │
                                                         │     B/op     │     B/op      vs base                │
Parse/data=promtestdata.txt/parser=promtext-2              57.90Ki ± 0%   57.90Ki ± 0%       ~ (p=1.000 n=6)
Parse/data=promtestdata.txt/parser=xpfmt-2                 536.8Ki ± 0%   536.8Ki ± 0%       ~ (p=0.623 n=6)
Parse/data=promtestdata.nometa.txt/parser=promtext-2       57.07Ki ± 0%   57.07Ki ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=promtestdata.nometa.txt/parser=xpfmt-2          381.1Ki ± 0%   381.1Ki ± 0%       ~ (p=0.784 n=6)
Parse/data=createTestProtoBuf()/parser=promproto-2         40.14Ki ± 0%   40.14Ki ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=omtestdata.txt/parser=omtext-2                  11.06Ki ± 0%   11.06Ki ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=promtestdata.txt/parser=omtext-2                109.9Ki ± 0%   109.9Ki ± 0%       ~ (p=0.545 n=6)
Parse/data=omhistogramdata.txt/parser=omtext-2             24.67Ki ± 0%   24.67Ki ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=omhistogramdata.txt/parser=omtext_with_nhcb-2   41.66Ki ± 0%   42.58Ki ± 0%  +2.20% (p=0.002 n=6)
geomean                                                    68.65Ki        68.82Ki       +0.24%
¹ all samples are equal

                                                         │  main.txt   │               pr.txt                │
                                                         │  allocs/op  │  allocs/op   vs base                │
Parse/data=promtestdata.txt/parser=promtext-2              1.038k ± 0%   1.038k ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=promtestdata.txt/parser=xpfmt-2                 12.35k ± 0%   12.35k ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=promtestdata.nometa.txt/parser=promtext-2        828.0 ± 0%    828.0 ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=promtestdata.nometa.txt/parser=xpfmt-2          10.01k ± 0%   10.01k ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=createTestProtoBuf()/parser=promproto-2          870.0 ± 0%    870.0 ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=omtestdata.txt/parser=omtext-2                   240.0 ± 0%    240.0 ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=promtestdata.txt/parser=omtext-2                2.492k ± 0%   2.492k ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=omhistogramdata.txt/parser=omtext-2              375.0 ± 0%    375.0 ± 0%       ~ (p=1.000 n=6) ¹
Parse/data=omhistogramdata.txt/parser=omtext_with_nhcb-2    506.0 ± 0%    524.0 ± 0%  +3.56% (p=0.002 n=6)
geomean                                                    1.298k        1.303k       +0.39%
¹ all samples are equal

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.

Beautiful, thanks!

Maybe one nit is to include a quick test case for your change in OMParser that would surface the previous regression if it would come back. Do you think this would be useful?

cc @Maniktherana would you like to review too and give your LGTM/comments? 🤗

@krajorama
Copy link
Member Author

krajorama commented Oct 23, 2024

Maybe one nit is to include a quick test case for your change in OMParser that would surface the previous regression if it would come back. Do you think this would be useful?

The tests already fail on main if you change the order, no new test needed:

--- FAIL: TestOpenMetricsParse (0.01s)
...
        	            	  	... // 18 identical elements
        	            	  	{m: `gh_bucket{le="+Inf"}`, v: 1, lset: s`{__name__="gh_bucket", le="+Inf"}`},
        	            	  	{m: "hhh", typ: "histogram"},
        	            	  	{
        	            	  		... // 4 identical fields
        	            	  		lset: s`{__name__="hhh_bucket", le="+Inf"}`,
        	            	  		t:    nil,
        	            	- 		es:   []exemplar.Exemplar{{Labels: s`{id="histogram-bucket-test"}`, Value: 4}},
        	            	+ 		es:   nil,
        	            	  		ct:   nil,
        	            	  		typ:  "",
        	            	  		... // 3 identical fields
        	            	  	},
        	            	  	{m: "hhh_count", v: 1, lset: s`{__name__="hhh_count"}`, es: {{Labels: s`{id="histogram-count-test"}`, Value: 4}}, ...},
        	            	  	{m: "ggh", typ: "gaugehistogram"},
        	            	  	{m: `ggh_bucket{le="+Inf"}`, v: 1, lset: s`{__name__="ggh_bucket", le="+Inf"}`, es: {{Labels: s`{id="gaugehistogram-bucket-test", xx="yy"}`, Value: 4, Ts: 123123, HasTs: true}}, ...},
        	            	  	{m: "ggh_count", v: 1, lset: s`{__name__="ggh_count"}`, es: {{Labels: s`{id="gaugehistogram-count-test", xx="yy"}`, Value: 4, Ts: 123123, HasTs: true}}, ...},
        	            	  	{m: "smr_seconds", typ: "summary"},
        	            	  	{
        	            	  		... // 4 identical fields
        	            	  		lset: s`{__name__="smr_seconds_count"}`,
        	            	  		t:    nil,
        	            	- 		es:   []exemplar.Exemplar{{Labels: s`{id="summary-count-test"}`, Value: 1, Ts: 123321, HasTs: true}},
        	            	+ 		es:   nil,
        	            	  		ct:   nil,
        	            	  		typ:  "",
        	            	  		... // 3 identical fields
        	            	  	},
        	            	  	{m: "smr_seconds_sum", v: 42, lset: s`{__name__="smr_seconds_sum"}`, es: {{Labels: s`{id="summary-sum-test"}`, Value: 1, Ts: 123321, HasTs: true}}, ...},
        	            	  	{m: "ii", typ: "info"},
        	            	  	... // 9 identical elements
        	            	  	{m: "foo", help: "Counter with and without labels to certify CT is parsed for both"...},
        	            	  	{m: "foo", typ: "counter"},
        	            	  	{
        	            	  		... // 4 identical fields
        	            	  		lset: s`{__name__="foo_total"}`,
        	            	  		t:    &1520879607789,
        	            	- 		es:   []exemplar.Exemplar{{Labels: s`{id="counter-test"}`, Value: 5}},
        	            	+ 		es:   nil,
        	            	  		ct:   &1520872607123,
        	            	  		typ:  "",
        	            	  		... // 3 identical fields
        	            	  	},
        	            	  	{
        	            	  		... // 4 identical fields
        	            	  		lset: s`{__name__="foo_total", a="b"}`,
        	            	  		t:    &1520879607789,
        	            	- 		es:   []exemplar.Exemplar{{Labels: s`{id="counter-test"}`, Value: 5}},
        	            	+ 		es:   nil,
        	            	  		ct:   &1520872607123,
        	            	  		typ:  "",
        	            	  		... // 3 identical fields
        	            	  	},
        	            	  	{m: `foo_total{le="c"}`, v: 21, lset: s`{__name__="foo_total", le="c"}`, ct: &1520872621123, ...},
        	            	  	{m: `foo_total{le="1"}`, v: 10, lset: s`{__name__="foo_total", le="1"}`},
        	            	  	... // 36 identical elements
        	            	  }
        	Test:       	TestOpenMetricsParse

defer func() {
p.ignoreExemplar = false
p.start = savedStart
p.l = resetLexer
Copy link
Contributor

Choose a reason for hiding this comment

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

why didn't I think of that

LGTM!

@krajorama krajorama merged commit 2182b83 into main Oct 24, 2024
@krajorama krajorama deleted the nhcb-scrape-ct branch October 24, 2024 05:39
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.

CT, OM: no exemplars on first scrape for created timestamp compatible open metrics

3 participants