Commit Graph

10 Commits

Author SHA1 Message Date
Bryan Boreham 0289dd6157 relabel: blank replacement deletes label post-regexp
If `cfg.TargetLabel` is a template like `$1`, it won't match any labels,
so no point calling `lb.Del` with it.

Similarly if `target` is not a valid label name, it won't match any
labels, so don't call with that either.

The intention seems to have been that a blank _value_ would delete the
target, so change that code to use `target` instead of `cfg.TargetLabel`.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2023-12-18 16:39:01 +00:00
Bryan Boreham 000182e4b8 relabel: check validity of all test cases
Thought this would be a nice check on the `Validate()` function, but
some of the test cases needed tweaking to pass.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2023-12-18 15:03:24 +00:00
Bryan Boreham 9ab7e3b3de relabel: refactor: extract config.Validate method
And add a test for it, which fails because validation is not strong enough.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2023-12-18 14:54:55 +00:00
Bryan Boreham 7a48a266b6
labels: respect Set after Del in Builder (#12322)
* labels: respect Set after Del in Builder

The implementations are not symmetric between `Set()` and `Del()`, so
we must be careful. Add tests for this, both in labels and in relabel
where the issue was reported.

Also make the slice implementation consistent re `slices.Contains`.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2023-05-03 11:59:27 +01:00
Bryan Boreham fe9fe0e1e5 Update package model/relabel tests for new labels.Labels type
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2022-12-19 15:22:09 +00:00
Julien Pivotto 005ede70de relabel: add keepequal/dropequal relabel action
Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
2022-11-10 14:41:02 +01:00
Bryan Boreham 8b863c42dd
Optimise relabeling by re-using memory (#11147)
* model/relabel: Add benchmark

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* model/relabel: re-use Builder across relabels

Saves memory allocations.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* labels.Builder: allow re-use of result slice

This reduces memory allocations where the caller has a suitable slice available.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* model/relabel: re-use source values slice

To reduce memory allocations.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Unwind one change causing test failures

Restore original behaviour in PopulateLabels, where we must not overwrite the input set.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* relabel: simplify values optimisation

Use a stack-based array for up to 16 source labels, which will be the
vast majority of cases.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* lint

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2022-08-19 15:27:52 +05:30
Paschalis Tsilias 4f3791024a
Drop extra string held in relabel.Regexp struct (#10846)
* Drop extra string held in relabel.Regexp struct

Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>

* Use slice operations instead of TrimPrefix/TrimSuffix; Override String() method

Signed-off-by: Paschalis Tsilias <paschalist0@gmail.com>
2022-06-13 15:00:48 +02:00
Julien Pivotto 71dbb4d091
Add lowercase and uppercase relabel action (#10641)
Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
2022-05-03 10:09:53 +02:00
beorn7 c954cd9d1d Move packages out of deprecated pkg directory
This creates a new `model` directory and moves all data-model related
packages over there:
  exemplar labels relabel rulefmt textparse timestamp value

All the others are more or less utilities and have been moved to `util`:
  gate logging modetimevfs pool runtime

Signed-off-by: beorn7 <beorn@grafana.com>
2021-11-09 08:03:10 +01:00