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 (#4460)

* [kube-prometheus-stack] Update mixins, switch to kube-prometheus mixin and fix label aggregation in TargetDown alert

Signed-off-by: Jan-Otto Kröpke <[email protected]>

* update mixins

Signed-off-by: Jan-Otto Kröpke <[email protected]>

---------

Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke authored Jun 28, 2024
1 parent b59b5d6 commit c3d8bc6
Show file tree
Hide file tree
Showing 64 changed files with 182 additions and 154 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: 61.0.0
version: 61.1.0
appVersion: v0.75.0
kubeVersion: ">=1.19.0-0"
home: https://github.com/prometheus-operator/kube-prometheus
Expand Down
4 changes: 2 additions & 2 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': '65922b9fd8c3869c06686b44f5f3aa9f96560666',
'ref.kube-prometheus': 'b5b59bc0b45508b85647eb7a84b96dc167be15f1',
# https://github.com/kubernetes-monitoring/kubernetes-mixin
'ref.kubernetes-mixin': 'de834e9a291b49396125768f041e2078763f48b5',
# https://github.com/etcd-io/etcd
'ref.etcd': 'bb701b9265f31d61db5906325e0a7e2abf7d3627',
'ref.etcd': '1c22e7b36bc5d8543f1646212f2960f9fe503b8c',
}

# Source files list
Expand Down
114 changes: 58 additions & 56 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': '65922b9fd8c3869c06686b44f5f3aa9f96560666',
'ref.kube-prometheus': 'b5b59bc0b45508b85647eb7a84b96dc167be15f1',
# https://github.com/kubernetes-monitoring/kubernetes-mixin
'ref.kubernetes-mixin': 'de834e9a291b49396125768f041e2078763f48b5',
# https://github.com/etcd-io/etcd
'ref.etcd': 'bb701b9265f31d61db5906325e0a7e2abf7d3627',
'ref.etcd': '1c22e7b36bc5d8543f1646212f2960f9fe503b8c',
}

# 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
4 changes: 2 additions & 2 deletions charts/kube-prometheus-stack/hack/update_mixins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ for REPO_PATH in "${SCRIPT_DIR}/tmp/"*; do
SHA=$(git -C "$REPO_PATH" log -1 --pretty=format:"%H")
REPO_NAME=$(basename "$REPO_PATH")
echo "Updating $REPO_NAME to $SHA"
sed -i '' -e "s/'ref.$REPO_NAME'.*:.*'.*'/'ref.$REPO_NAME': '$SHA'/" "${SCRIPT_DIR}/sync_grafana_dashboards.py"
sed -i '' -e "s/'ref.$REPO_NAME'.*:.*'.*'/'ref.$REPO_NAME': '$SHA'/" "${SCRIPT_DIR}/sync_prometheus_rules.py"
sed -i -e "s/'ref.$REPO_NAME'.*:.*'.*'/'ref.$REPO_NAME': '$SHA'/" "${SCRIPT_DIR}/sync_grafana_dashboards.py"
sed -i -e "s/'ref.$REPO_NAME'.*:.*'.*'/'ref.$REPO_NAME': '$SHA'/" "${SCRIPT_DIR}/sync_prometheus_rules.py"
done

export PIP_DISABLE_PIP_VERSION_CHECK=1
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/65922b9fd8c3869c06686b44f5f3aa9f96560666/manifests/grafana-dashboardDefinitions.yaml
Generated from 'alertmanager-overview' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/b5b59bc0b45508b85647eb7a84b96dc167be15f1/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 c3d8bc6

Please sign in to comment.