Skip to content

Commit

Permalink
[kube-prometheus-stack] Update mixins, switch to kube-prometheus mixi…
Browse files Browse the repository at this point in the history
…n and fix label aggregation in TargetDown alert

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
  • Loading branch information
jkroepke committed May 25, 2024
1 parent c43f4b2 commit a2736d7
Show file tree
Hide file tree
Showing 68 changed files with 141 additions and 141 deletions.
2 changes: 1 addition & 1 deletion charts/kube-prometheus-stack/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name: kube-prometheus-stack
sources:
- https://github.com/prometheus-community/helm-charts
- https://github.com/prometheus-operator/kube-prometheus
version: 58.7.2
version: 58.8.0
appVersion: v0.73.2
kubeVersion: ">=1.19.0-0"
home: https://github.com/prometheus-operator/kube-prometheus
Expand Down
6 changes: 3 additions & 3 deletions charts/kube-prometheus-stack/hack/sync_grafana_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def new_representer(dumper, data):

refs = {
# https://github.com/prometheus-operator/kube-prometheus
'ref.kube-prometheus': 'cb55161e24eee55d67f3bb7e7f1719feab66da52',
'ref.kube-prometheus': '65922b9fd8c3869c06686b44f5f3aa9f96560666',
# https://github.com/kubernetes-monitoring/kubernetes-mixin
'ref.kubernetes-mixin': '033a6fb33be80d381045dc570fc53f0b7750e8b6',
'ref.kubernetes-mixin': 'de834e9a291b49396125768f041e2078763f48b5',
# https://github.com/etcd-io/etcd
'ref.etcd': '52fb28c1a8db4e66c547b7975bf6dc1e0b17f8bf',
'ref.etcd': 'a5292685f9963154df385140c9bf33dd988ebfe5',
}

# Source files list
Expand Down
116 changes: 59 additions & 57 deletions charts/kube-prometheus-stack/hack/sync_prometheus_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,48 @@ def new_representer(dumper, data):

refs = {
# https://github.com/prometheus-operator/kube-prometheus
'ref.kube-prometheus': 'cb55161e24eee55d67f3bb7e7f1719feab66da52',
'ref.kube-prometheus': '65922b9fd8c3869c06686b44f5f3aa9f96560666',
# https://github.com/kubernetes-monitoring/kubernetes-mixin
'ref.kubernetes-mixin': '033a6fb33be80d381045dc570fc53f0b7750e8b6',
'ref.kubernetes-mixin': 'de834e9a291b49396125768f041e2078763f48b5',
# https://github.com/etcd-io/etcd
'ref.etcd': '52fb28c1a8db4e66c547b7975bf6dc1e0b17f8bf',
'ref.etcd': 'a5292685f9963154df385140c9bf33dd988ebfe5',
}

# Source files list
charts = [
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/alertmanager-prometheusRule.yaml' % (refs['ref.kube-prometheus'],),
'git': 'https://github.com/prometheus-operator/kube-prometheus.git',
'branch': refs['ref.kube-prometheus'],
'source': 'main.libsonnet',
'cwd': 'jsonnet/kube-prometheus',
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/kubePrometheus-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/kubernetesControlPlane-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/kubeStateMetrics-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/nodeExporter-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/prometheus-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
},
{
'source': 'https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/%s/manifests/prometheusOperator-prometheusRule.yaml'% (refs['ref.kube-prometheus'],),
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0'
'min_kubernetes': '1.14.0-0',
'mixin': """
local kp =
(import 'main.libsonnet') + {
values+:: {
common+: {
namespace: 'monitoring',
},
kubernetesControlPlane+: {
kubeProxy: true,
},
},
grafana: {},
};
{
groups: std.flattenArrays([
kp[component][resource].spec.groups
for component in std.objectFields(kp)
for resource in std.filter(
function(resource)
kp[component][resource].kind == 'PrometheusRule',
std.objectFields(kp[component])
)
]),
}
"""
},
{
'git': 'https://github.com/kubernetes-monitoring/kubernetes-mixin.git',
Expand All @@ -80,12 +79,18 @@ def new_representer(dumper, data):
'cwd': 'rules',
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0',
'is_mixin': True,
'mixin_vars': {'_config': {
'clusterLabel': 'cluster',
'windowsExporterSelector': 'job="windows-exporter"',
'kubeStateMetricsSelector': 'job="kube-state-metrics"',
}}
'mixin': """
local kp =
{ prometheusAlerts+:: {}, prometheusRules+:: {}} +
(import "windows.libsonnet") +
{'_config': {
'clusterLabel': 'cluster',
'windowsExporterSelector': 'job="windows-exporter"',
'kubeStateMetricsSelector': 'job="kube-state-metrics"',
}};
kp.prometheusAlerts + kp.prometheusRules
"""
},
{
'git': 'https://github.com/etcd-io/etcd.git',
Expand All @@ -94,8 +99,11 @@ def new_representer(dumper, data):
'cwd': 'contrib/mixin',
'destination': '../templates/prometheus/rules-1.14',
'min_kubernetes': '1.14.0-0',
'is_mixin': True,
'mixin_vars': {'_config+': {}}
'mixin': """
local kp = { prometheusAlerts+:: {}, prometheusRules+:: {}} + (import "mixin.libsonnet");
kp.prometheusAlerts + kp.prometheusRules
"""
},
]

Expand Down Expand Up @@ -185,6 +193,9 @@ def new_representer(dumper, data):
'init': ''},
'(namespace,service)': {
'replacement': '(namespace,service,cluster)',
'init': ''},
'(namespace, job, handler': {
'replacement': '(cluster, namespace, job, handler',
'init': ''}
}

Expand Down Expand Up @@ -508,7 +519,8 @@ def write_group_to_file(group, url, destination, min_kubernetes, max_kubernetes)
lines += re.sub(
r'\s(by|on) ?\(',
r' \1 ({{ range $.Values.defaultRules.additionalAggregationLabels }}{{ . }},{{ end }}',
rules
rules,
flags=re.IGNORECASE
)

# footer
Expand Down Expand Up @@ -563,7 +575,7 @@ def main():
subprocess.run(["git", "-C", checkout_dir, "fetch", "--depth", "1", "origin", branch, "--quiet"])
subprocess.run(["git", "-c", "advice.detachedHead=false", "-C", checkout_dir, "checkout", "FETCH_HEAD", "--quiet"])

if chart.get('is_mixin'):
if chart.get('mixin'):
cwd = os.getcwd()

source_cwd = chart['cwd']
Expand All @@ -579,22 +591,12 @@ def main():
f.write(chart['content'])
f.close()

mixin_vars = json.dumps(chart['mixin_vars'])

print("Generating rules from %s" % mixin_file)
print("Change cwd to %s" % checkout_dir + '/' + source_cwd)
os.chdir(mixin_dir)

mixin = """
local kp =
{ prometheusAlerts+:: {}, prometheusRules+:: {}} +
(import "%s") +
%s;
kp.prometheusAlerts + kp.prometheusRules
"""
alerts = json.loads(_jsonnet.evaluate_snippet(mixin_file, chart['mixin'], import_callback=jsonnet_import_callback))

alerts = json.loads(_jsonnet.evaluate_snippet(mixin_file, mixin % (mixin_file, mixin_vars), import_callback=jsonnet_import_callback))
os.chdir(cwd)
else:
with open(checkout_dir + '/' + chart['source'], "r") as f:
Expand All @@ -610,7 +612,7 @@ def main():
print('Skipping the file, response code %s not equals 200' % response.status_code)
continue
raw_text = response.text
if chart.get('is_mixin'):
if chart.get('mixin'):
alerts = json.loads(_jsonnet.evaluate_snippet(url, raw_text + '.prometheusAlerts'))
else:
alerts = yaml.full_load(raw_text)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'alertmanager-overview' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'alertmanager-overview' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'apiserver' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'apiserver' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'cluster-total' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'cluster-total' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'controller-manager' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'controller-manager' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'grafana-overview' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'grafana-overview' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'k8s-resources-cluster' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'k8s-resources-cluster' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'k8s-resources-multicluster' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'k8s-resources-multicluster' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'k8s-resources-namespace' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'k8s-resources-namespace' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'k8s-resources-node' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'k8s-resources-node' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- /*
Generated from 'k8s-resources-pod' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/cb55161e24eee55d67f3bb7e7f1719feab66da52/manifests/grafana-dashboardDefinitions.yaml
Generated from 'k8s-resources-pod' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
Expand Down
Loading

0 comments on commit a2736d7

Please sign in to comment.