Skip to content

Commit d758fb6

Browse files
authored
Merge branch 'master' into gaantunes/postgres-observ-lib
2 parents 20e3585 + 297984b commit d758fb6

File tree

7 files changed

+133
-51
lines changed

7 files changed

+133
-51
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
cache-hit: ${{ steps.tools-cache.outputs.cache-hit }}
2020
steps:
2121
- name: Checkout
22-
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
22+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
2323
with:
2424
fetch-depth: 0
2525
persist-credentials: false
@@ -45,7 +45,7 @@ jobs:
4545
runs-on: ubuntu-latest
4646
steps:
4747
- name: Checkout
48-
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
48+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
4949
with:
5050
fetch-depth: 0
5151
persist-credentials: false
@@ -69,7 +69,7 @@ jobs:
6969
runs-on: ubuntu-latest
7070
steps:
7171
- name: Checkout
72-
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
72+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
7373
with:
7474
fetch-depth: 0
7575
persist-credentials: false

.github/workflows/test-mixins.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
cache-hit: ${{ steps.tools-cache.outputs.cache-hit }}
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
21+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
2222
with:
2323
fetch-depth: 0
2424
persist-credentials: false
@@ -46,7 +46,7 @@ jobs:
4646
changed-mixins: ${{ steps.changed-mixins.outputs.all_changed_files }}
4747
steps:
4848
- name: Checkout
49-
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
49+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
5050
with:
5151
fetch-depth: 0
5252
persist-credentials: false
@@ -91,7 +91,7 @@ jobs:
9191
GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin"
9292
steps:
9393
- name: Checkout
94-
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
94+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6
9595
with:
9696
fetch-depth: 0
9797
persist-credentials: false

cert-manager/default_clusterissuers.libsonnet

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
},
1111
},
1212

13+
issuer:: self.clusterIssuer {
14+
new(name): {
15+
apiVersion: 'cert-manager.io/v1',
16+
kind: 'Issuer',
17+
metadata: {
18+
name: name,
19+
},
20+
},
21+
},
22+
1323
clusterIssuer:: {
1424
new(name): {
1525
apiVersion: 'cert-manager.io/v1',

grafana-builder/grafana.libsonnet

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ local utils = import 'mixin-utils/utils.libsonnet';
552552

553553
// Assumes that there is a dashboard variable named latency_metrics, values are -1 (native) or 1 (classic)
554554
// By default it shows the 99th and 50th quantile.
555-
latencyPanelNativeHistogram(metricName, selector, multiplier='1e3', quantile=[99, 50]):: {
555+
latencyPanelNativeHistogram(metricName, selector, multiplier='1e3', quantile=[99, 50], from_recording=false):: {
556556
nullPointMode: 'null as zero',
557557
fieldConfig+: {
558558
defaults+: {
@@ -570,13 +570,13 @@ local utils = import 'mixin-utils/utils.libsonnet';
570570
local qStr = std.toString(q);
571571
acc + [
572572
{
573-
expr: utils.showNativeHistogramQuery(utils.ncHistogramQuantile('0.' + qStr, metricName, selector, multiplier=multiplier)),
573+
expr: utils.showNativeHistogramQuery(utils.ncHistogramQuantile(std.format('%.2f', q / 100), metricName, selector, multiplier=multiplier, from_recording=from_recording)),
574574
format: 'time_series',
575575
legendFormat: qStr + 'th percentile',
576576
refId: getNextRefId(acc),
577577
},
578578
{
579-
expr: utils.showClassicHistogramQuery(utils.ncHistogramQuantile('0.' + qStr, metricName, selector, multiplier=multiplier)),
579+
expr: utils.showClassicHistogramQuery(utils.ncHistogramQuantile(std.format('%.2f', q / 100), metricName, selector, multiplier=multiplier, from_recording=from_recording)),
580580
format: 'time_series',
581581
legendFormat: qStr + 'th percentile',
582582
refId: getNextRefId(acc) + '_classic',
@@ -589,13 +589,13 @@ local utils = import 'mixin-utils/utils.libsonnet';
589589
qTargets +
590590
[
591591
{
592-
expr: utils.showNativeHistogramQuery(utils.ncHistogramAverageRate(metricName, selector, multiplier=multiplier)),
592+
expr: utils.showNativeHistogramQuery(utils.ncHistogramAverageRate(metricName, selector, multiplier=multiplier, from_recording=from_recording)),
593593
format: 'time_series',
594594
legendFormat: 'Average',
595595
refId: getNextRefId(qTargets),
596596
},
597597
{
598-
expr: utils.showClassicHistogramQuery(utils.ncHistogramAverageRate(metricName, selector, multiplier=multiplier)),
598+
expr: utils.showClassicHistogramQuery(utils.ncHistogramAverageRate(metricName, selector, multiplier=multiplier, from_recording=from_recording)),
599599
format: 'time_series',
600600
legendFormat: 'Average',
601601
refId: getNextRefId(qTargets) + '_classic',

grafana-builder/test/test_native-classic-histogram.libsonnet

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,102 @@ test.new(std.thisFile)
66
+ test.case.new(
77
name='LatencyPanel fieldConfig',
88
test=test.expect.eq(
9-
actual=std.get(builder.latencyPanelNativeHistogram('request_duration_seconds', 'cluster="cluster1", job="job1"'), 'targets', []),
9+
actual=std.get(builder.latencyPanelNativeHistogram('request_duration_seconds', 'cluster="cluster1", job="job1"', '1e3', [100, 99, 50]), 'targets'),
1010
expected=[
11+
{
12+
expr: '(histogram_quantile(1.00, sum (rate(request_duration_seconds{cluster="cluster1", job="job1"}[$__rate_interval]))) * 1e3) and on() (vector($latency_metrics) == -1)',
13+
format: 'time_series',
14+
legendFormat: '100th percentile',
15+
refId: 'A',
16+
},
17+
{
18+
expr: '(histogram_quantile(1.00, sum by (le) (rate(request_duration_seconds_bucket{cluster="cluster1", job="job1"}[$__rate_interval]))) * 1e3) and on() (vector($latency_metrics) == 1)',
19+
format: 'time_series',
20+
legendFormat: '100th percentile',
21+
refId: 'A_classic',
22+
},
1123
{
1224
expr: '(histogram_quantile(0.99, sum (rate(request_duration_seconds{cluster="cluster1", job="job1"}[$__rate_interval]))) * 1e3) and on() (vector($latency_metrics) == -1)',
1325
format: 'time_series',
1426
legendFormat: '99th percentile',
15-
refId: 'A',
27+
refId: 'B',
1628
},
1729
{
1830
expr: '(histogram_quantile(0.99, sum by (le) (rate(request_duration_seconds_bucket{cluster="cluster1", job="job1"}[$__rate_interval]))) * 1e3) and on() (vector($latency_metrics) == 1)',
1931
format: 'time_series',
2032
legendFormat: '99th percentile',
21-
refId: 'A_classic',
33+
refId: 'B_classic',
2234
},
2335
{
2436
expr: '(histogram_quantile(0.50, sum (rate(request_duration_seconds{cluster="cluster1", job="job1"}[$__rate_interval]))) * 1e3) and on() (vector($latency_metrics) == -1)',
2537
format: 'time_series',
2638
legendFormat: '50th percentile',
27-
refId: 'B',
39+
refId: 'C',
2840
},
2941
{
3042
expr: '(histogram_quantile(0.50, sum by (le) (rate(request_duration_seconds_bucket{cluster="cluster1", job="job1"}[$__rate_interval]))) * 1e3) and on() (vector($latency_metrics) == 1)',
3143
format: 'time_series',
3244
legendFormat: '50th percentile',
33-
refId: 'B_classic',
45+
refId: 'C_classic',
3446
},
3547
{
3648
expr: '(1e3 * sum(histogram_sum(rate(request_duration_seconds{cluster="cluster1", job="job1"}[$__rate_interval]))) /\nsum(histogram_count(rate(request_duration_seconds{cluster="cluster1", job="job1"}[$__rate_interval])))\n) and on() (vector($latency_metrics) == -1)',
3749
format: 'time_series',
3850
legendFormat: 'Average',
39-
refId: 'C',
51+
refId: 'D',
4052
},
4153
{
4254
expr: '(1e3 * sum(rate(request_duration_seconds_sum{cluster="cluster1", job="job1"}[$__rate_interval])) /\nsum(rate(request_duration_seconds_count{cluster="cluster1", job="job1"}[$__rate_interval]))\n) and on() (vector($latency_metrics) == 1)',
4355
format: 'time_series',
4456
legendFormat: 'Average',
45-
refId: 'C_classic',
57+
refId: 'D_classic',
4658
},
4759
],
4860
)
4961
)
62+
63+
64+
+ test.case.new(
65+
name='LatencyPanel from recording',
66+
test=test.expect.eq(
67+
actual=std.get(builder.latencyPanelNativeHistogram('cluster_job_route:cortex_request_duration_seconds_bucket', 'cluster="cluster1"', '1e3', [99, 50], true), 'targets'),
68+
expected=[
69+
{
70+
expr: '(histogram_quantile(0.99, sum (cluster_job_route:cortex_request_duration_seconds_bucket:sum_rate{cluster="cluster1"})) * 1e3) and on() (vector($latency_metrics) == -1)',
71+
format: 'time_series',
72+
legendFormat: '99th percentile',
73+
refId: 'A',
74+
},
75+
{
76+
expr: '(histogram_quantile(0.99, sum by (le) (cluster_job_route:cortex_request_duration_seconds_bucket_bucket:sum_rate{cluster="cluster1"})) * 1e3) and on() (vector($latency_metrics) == 1)',
77+
format: 'time_series',
78+
legendFormat: '99th percentile',
79+
refId: 'A_classic',
80+
},
81+
{
82+
expr: '(histogram_quantile(0.50, sum (cluster_job_route:cortex_request_duration_seconds_bucket:sum_rate{cluster="cluster1"})) * 1e3) and on() (vector($latency_metrics) == -1)',
83+
format: 'time_series',
84+
legendFormat: '50th percentile',
85+
refId: 'B',
86+
},
87+
{
88+
expr: '(histogram_quantile(0.50, sum by (le) (cluster_job_route:cortex_request_duration_seconds_bucket_bucket:sum_rate{cluster="cluster1"})) * 1e3) and on() (vector($latency_metrics) == 1)',
89+
format: 'time_series',
90+
legendFormat: '50th percentile',
91+
refId: 'B_classic',
92+
},
93+
{
94+
expr: '(1e3 * sum(histogram_sum(cluster_job_route:cortex_request_duration_seconds_bucket:sum_rate{cluster="cluster1"})) /\nsum(histogram_count(cluster_job_route:cortex_request_duration_seconds_bucket:sum_rate{cluster="cluster1"}))\n) and on() (vector($latency_metrics) == -1)',
95+
format: 'time_series',
96+
legendFormat: 'Average',
97+
refId: 'C',
98+
},
99+
{
100+
expr: '(1e3 * sum(cluster_job_route:cortex_request_duration_seconds_bucket_sum:sum_rate{cluster="cluster1"}) /\nsum(cluster_job_route:cortex_request_duration_seconds_bucket_count:sum_rate{cluster="cluster1"})\n) and on() (vector($latency_metrics) == 1)',
101+
format: 'time_series',
102+
legendFormat: 'Average',
103+
refId: 'C_classic',
104+
},
105+
]
106+
)
107+
)

mixin-utils/test/test_native-classic-histogram.libsonnet

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,23 @@ test.new(std.thisFile)
238238
}
239239
)
240240
)
241+
+ test.case.new(
242+
name='histogram count increase',
243+
test=test.expect.eq(
244+
actual=utils.ncHistogramCountIncrease('request_duration_seconds', 'cluster="cluster1", job="job1"'),
245+
expected={
246+
classic: 'increase(request_duration_seconds_count{cluster="cluster1", job="job1"}[$__rate_interval])',
247+
native: 'histogram_count(increase(request_duration_seconds{cluster="cluster1", job="job1"}[$__rate_interval]))',
248+
}
249+
)
250+
)
251+
+ test.case.new(
252+
name='histogram count increase with rate interval',
253+
test=test.expect.eq(
254+
actual=utils.ncHistogramCountIncrease('request_duration_seconds', 'cluster="cluster1", job="job1"', rate_interval='5m'),
255+
expected={
256+
classic: 'increase(request_duration_seconds_count{cluster="cluster1", job="job1"}[5m])',
257+
native: 'histogram_count(increase(request_duration_seconds{cluster="cluster1", job="job1"}[5m]))',
258+
}
259+
)
260+
)

mixin-utils/utils.libsonnet

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,52 +45,46 @@ local g = import 'grafana-builder/grafana.libsonnet';
4545
// If from_recording is true, the function will assume :sum_rate metric
4646
// suffix and no rate needed.
4747
ncHistogramSumRate(metric, selector, rate_interval='$__rate_interval', from_recording=false)::
48-
local rateOpen = if from_recording then '' else 'rate(';
49-
local rateClose = if from_recording then '' else '[%s])' % rate_interval;
50-
{
51-
classic: '%(rateOpen)s%(metric)s_sum%(suffix)s{%(selector)s}%(rateClose)s' % {
52-
metric: metric,
53-
rateInterval: rate_interval,
54-
rateOpen: rateOpen,
55-
rateClose: rateClose,
56-
selector: selector,
57-
suffix: if from_recording then ':sum_rate' else '',
58-
},
59-
native: 'histogram_sum(%(rateOpen)s%(metric)s%(suffix)s{%(selector)s}%(rateClose)s)' % {
60-
metric: metric,
61-
rateInterval: rate_interval,
62-
rateOpen: rateOpen,
63-
rateClose: rateClose,
64-
selector: selector,
65-
suffix: if from_recording then ':sum_rate' else '',
66-
},
67-
},
68-
48+
$.ncHistogramChange('sum', 'rate', metric, selector, rate_interval, from_recording),
6949

7050
// The ncHistogramCountRate (native classic histogram count rate) function is
7151
// used to calculate the histogram rate of count from native histograms or
7252
// classic histograms. Metric name should be provided without _count suffix.
7353
// If from_recording is true, the function will assume :sum_rate metric
7454
// suffix and no rate needed.
7555
ncHistogramCountRate(metric, selector, rate_interval='$__rate_interval', from_recording=false)::
76-
local rateOpen = if from_recording then '' else 'rate(';
77-
local rateClose = if from_recording then '' else '[%s])' % rate_interval;
56+
$.ncHistogramChange('count', 'rate', metric, selector, rate_interval, from_recording),
57+
58+
// The ncHistogramCountIncrease (native classic histogram count rate) function is
59+
// used to calculate the histogram increase of count from native histograms or
60+
// classic histograms. Metric name should be provided without _count suffix.
61+
ncHistogramCountIncrease(metric, selector, rate_interval='$__rate_interval')::
62+
$.ncHistogramChange('count', 'increase', metric, selector, rate_interval, false),
63+
64+
// ncHistogramChange is a helper function to generate queries for either
65+
// histogram sum or count changes over time using the specified function
66+
// (e.g., rate, increase). Metric name should be provided without _sum or
67+
// _count suffix.
68+
ncHistogramChange(sum_or_count, func_name, metric, selector, rate_interval='$__rate_interval', from_recording=false)::
69+
local funcOpen = if from_recording then '' else '%s(' % func_name;
70+
local funcClose = if from_recording then '' else '[%s])' % rate_interval;
71+
local suffix = if from_recording then ':sum_%s' % func_name else '';
7872
{
79-
classic: '%(rateOpen)s%(metric)s_count%(suffix)s{%(selector)s}%(rateClose)s' % {
73+
classic: '%(funcOpen)s%(metric)s_%(sum_or_count)s%(suffix)s{%(selector)s}%(funcClose)s' % {
8074
metric: metric,
81-
rateInterval: rate_interval,
82-
rateOpen: rateOpen,
83-
rateClose: rateClose,
75+
sum_or_count: sum_or_count,
76+
funcOpen: funcOpen,
77+
funcClose: funcClose,
8478
selector: selector,
85-
suffix: if from_recording then ':sum_rate' else '',
79+
suffix: suffix,
8680
},
87-
native: 'histogram_count(%(rateOpen)s%(metric)s%(suffix)s{%(selector)s}%(rateClose)s)' % {
81+
native: 'histogram_%(sum_or_count)s(%(funcOpen)s%(metric)s%(suffix)s{%(selector)s}%(funcClose)s)' % {
8882
metric: metric,
89-
rateInterval: rate_interval,
90-
rateOpen: rateOpen,
91-
rateClose: rateClose,
83+
sum_or_count: sum_or_count,
84+
funcOpen: funcOpen,
85+
funcClose: funcClose,
9286
selector: selector,
93-
suffix: if from_recording then ':sum_rate' else '',
87+
suffix: suffix,
9488
},
9589
},
9690

0 commit comments

Comments
 (0)