Prometheus: Fix recording rules expansion (#24977)

* First pass solution

* Refactor solution

* Add test coverage, update tests

* Fix behaviour for multiple labels, add test for this

* Add recordin rules to devenv prometheus

* Update devenv/prometheus2 instead of devenv/prometheus

* Add newlines

* Fix label matching if labels include comma, add test coverage

* Refactor

* Refactor, simplify
This commit is contained in:
Ivana Huckova
2020-05-22 15:16:01 +02:00
committed by GitHub
parent 4f1bbdfc0a
commit 4d18bda2e1
7 changed files with 103 additions and 21 deletions

View File

@@ -117,4 +117,27 @@ describe('expandRecordingRules()', () => {
expect(expandRecordingRules('metric[]', { metric: 'foo' })).toBe('foo[]');
expect(expandRecordingRules('metric + foo', { metric: 'foo', foo: 'bar' })).toBe('foo + bar');
});
it('returns query with labels with expanded recording rules', () => {
expect(
expandRecordingRules('metricA{label1="value1"} / metricB{label2="value2"}', { metricA: 'fooA', metricB: 'fooB' })
).toBe('fooA{label1="value1"} / fooB{label2="value2"}');
expect(
expandRecordingRules('metricA{label1="value1",label2="value,2"}', {
metricA: 'rate(fooA[])',
})
).toBe('rate(fooA{label1="value1",label2="value,2"}[])');
expect(
expandRecordingRules('metricA{label1="value1"} / metricB{label2="value2"}', {
metricA: 'rate(fooA[])',
metricB: 'rate(fooB[])',
})
).toBe('rate(fooA{label1="value1"}[])/ rate(fooB{label2="value2"}[])');
expect(
expandRecordingRules('metricA{label1="value1",label2="value2"} / metricB{label3="value3"}', {
metricA: 'rate(fooA[])',
metricB: 'rate(fooB[])',
})
).toBe('rate(fooA{label1="value1",label2="value2"}[])/ rate(fooB{label3="value3"}[])');
});
});