Skip to content

Commit

Permalink
add additionalScrapeJobs for prometheus (#2144)
Browse files Browse the repository at this point in the history
* add additionalScrapeJobs for prometheus

Co-authored-by: Daniel Hoherd <daniel.hoherd@gmail.com>
  • Loading branch information
guerremdq and danielhoherd committed Feb 22, 2024
1 parent 5b3bd5d commit 53e30bd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions charts/prometheus/templates/prometheus-config-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -723,3 +723,7 @@ data:
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
{{- with .Values.additionalScrapeJobs }}
{{- toYaml . | nindent 6 }}
{{- end }}
17 changes: 17 additions & 0 deletions charts/prometheus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ additionalAlerts:
# annotations:
# summary: "The Astronomer Helm release {{ .Release.Name }} is failing task instances {{ printf \"%.2f\" $value }}% of the time over the past 30 minutes"
# description: Task instances failing above threshold
additionalScrapeJobs: {}
# Example:
# additionalScrapeJobs:
# - job_name: 'my-job'
# kubernetes_sd_configs:
# - role: endpoints
# relabel_configs:
# - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
# action: keep
# regex: true
# - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
# action: replace
# target_label: __scheme__
# regex: (https?)
# - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
# action: replace
#

# Prometheus config file remote_write stanza
# https://prometheus.io/docs/prometheus/latest/configuration/configuration/
Expand Down
36 changes: 36 additions & 0 deletions tests/chart_tests/test_prometheus_config_configmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,39 @@ def assert_relabel_config_for_non_auto_generated_namesaces(self, chart):
]
assert metric_relabel_config_search_result[1]["replacement"] == "$1"
assert metric_relabel_config_search_result[1]["target_label"] == "release"

def test_additional_scrape_jobs(self, kube_version):
static_job = {
"job_name": "example-static-job",
"static_configs": [{"targets": ["localhost:9090"]}],
}
kubernetes_job = {
"job_name": "example-kubernetes-job",
"kubernetes_sd_configs": [
{
"role": "endpoints",
"namespaces": {"names": ["default"]},
}
],
}
doc = render_chart(
kube_version=kube_version,
show_only=self.show_only,
name="astronomer",
values={
"prometheus": {
"additionalScrapeJobs": [
static_job,
kubernetes_job,
]
}
},
)[0]
scrape_configs = yaml.safe_load(doc["data"]["config"])["scrape_configs"]

assert (
static_job in scrape_configs
), "Static job not found in rendered ConfigMap"
assert (
kubernetes_job in scrape_configs
), "Kubernetes job not found in rendered ConfigMap"

0 comments on commit 53e30bd

Please sign in to comment.