Oleg Zaytsev
005d8de006
Improve performance of WithLabelValues(...)
...
The slice with variadic arguments passed to MetricVec.WithLabelValues()
was escaping to heap. This change fixes that by performing a copy of the
slice before passing it to fmt.Errorf(), which is where the slice was
escaping. This keeps the hot path without that allocation.
Meaningful benchmark results (skipping ~0 CPU and 0 alloc ones):
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
Counter/With_Label_Values-16 108.00n ± 6% 58.06n ± 1% -46.24% (p=0.000 n=10)
Counter/With_Label_Values_and_Constraint-16 174.5n ± 15% 136.8n ± 6% -21.63% (p=0.000 n=10)
Counter/With_triple_Label_Values-16 309.3n ± 12% 172.9n ± 1% -44.08% (p=0.000 n=10)
Counter/With_triple_Label_Values_and_Constraint-16 591.5n ± 11% 418.9n ± 3% -29.17% (p=0.000 n=10)
Counter/With_repeated_Label_Values-16 212.9n ± 10% 116.8n ± 23% -45.16% (p=0.000 n=10)
Counter/With_repeated_Label_Values_and_Constraint-16 406.2n ± 14% 275.1n ± 4% -32.30% (p=0.000 n=10)
CounterWithLabelValuesConcurrent-16 85.45n ± 2% 89.09n ± 2% +4.26% (p=0.003 n=10)
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
Counter/With_Label_Values-16 48.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10)
Counter/With_Label_Values_and_Constraint-16 96.00 ± 0% 48.00 ± 0% -50.00% (p=0.000 n=10)
Counter/With_triple_Label_Values-16 144.0 ± 0% 0.0 ± 0% -100.00% (p=0.000 n=10)
Counter/With_triple_Label_Values_and_Constraint-16 288.0 ± 0% 144.0 ± 0% -50.00% (p=0.000 n=10)
Counter/With_repeated_Label_Values-16 96.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10)
Counter/With_repeated_Label_Values_and_Constraint-16 192.00 ± 0% 96.00 ± 0% -50.00% (p=0.000 n=10)
CounterWithLabelValuesConcurrent-16 48.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10)
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
Counter/With_Label_Values-16 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10)
Counter/With_Label_Values_and_Constraint-16 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=10)
Counter/With_triple_Label_Values-16 3.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10)
Counter/With_triple_Label_Values_and_Constraint-16 6.000 ± 0% 3.000 ± 0% -50.00% (p=0.000 n=10)
Counter/With_repeated_Label_Values-16 2.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10)
Counter/With_repeated_Label_Values_and_Constraint-16 4.000 ± 0% 2.000 ± 0% -50.00% (p=0.000 n=10)
CounterWithLabelValuesConcurrent-16 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10)
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
2023-10-04 18:09:15 +02:00
Quentin D
644c80d136
Do not allocate memory when there's no constraints ( #1296 )
...
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
2023-06-27 12:21:36 +01:00
Quentin D
fae2f6306b
Add constrained labels and Constrained variant for all MetricVecs ( #1151 )
...
* Introduce MetricVecOpts and add constraints to VariableLabels
MetricVecOpts exposes options specific to MetricVec initialisation. The
first option exposed by MetricVecOpts are constraints on VariableLabels,
allowing restrictions on the possible values a label can take, to
prevent cardinality explosion when the label value comes from a
non-trusted source (as a user input or HTTP header).
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
* Add tests
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
2022-12-13 13:47:52 +01:00
Kemal Akkoyun
870469ecf9
Test and support 1.19 ( #1160 )
...
* Add new Go 1.19 metrics
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
* Format files with the latest formatter
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2022-11-08 00:14:19 +01:00
Christoph Mewes
618194de6a
fix assorted oddities found by golangci-lint ( #1040 )
...
* fix assorted oddities found by golangci-lint
Signed-off-by: Christoph Mewes <christoph@kubermatic.com>
* permanently enable the linters
Signed-off-by: Christoph Mewes <christoph@kubermatic.com>
* post-rebase blues
Signed-off-by: Christoph Mewes <christoph@kubermatic.com>
2022-08-03 06:30:51 +02:00
Peter Jausovec
ea348d7c20
Update code based on the PR feedback
...
Signed-off-by: Peter Jausovec <peter.jausovec@oracle.com>
2018-11-02 09:01:14 -07:00
Peter Jausovec
902733d080
Add more info to the inconsistent cardinality errors
...
Signed-off-by: Peter Jausovec <peter.jausovec@oracle.com>
2018-10-31 11:01:42 -07:00
glefloch
cb71127117
Add missing license headers
...
Signed-off-by: glefloch <glfloch@gmail.com>
2018-08-22 13:53:56 +02:00
Marco Jantke
a956c5fdd6
improve validation function naming
2017-08-25 17:58:59 +02:00
Marco Jantke
0b8aef084e
implement review feedback
2017-08-25 14:51:19 +02:00