From bef284e9650c8d1ee5358f975eebe5a46d2303c9 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Fri, 18 Nov 2022 00:55:44 +0100 Subject: [PATCH] Add mon-exporter as scrape target in Prometheus The Prometheus sidecar is expected to generate the scrape targets from the config map and from the prometheus_jobs in MongoDB. MON is adding mon-exporter as prometheus_job in MongoDB. There are race conditions in the start of MON and Prometheus that prevent the sidecar to be aware of the mon-exporter being added to prometheus_jobs collection in MongoDB. This change adds mon-exporter to the default scrape-targets and reconciles the jobs in Mongo and the jobs in the configmap, prevailing the job in the configmap if duplicated. Change-Id: Ib6f1cb89723d7b4942eeb77fd0ea46a0d3493d58 Signed-off-by: garciadeblas --- docker/Prometheus/src/app.py | 13 ++++++++++++- installers/docker/osm_pods/ng-prometheus.yaml | 3 +++ installers/docker/osm_pods/prometheus.yaml | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docker/Prometheus/src/app.py b/docker/Prometheus/src/app.py index eb625557..b06f4486 100755 --- a/docker/Prometheus/src/app.py +++ b/docker/Prometheus/src/app.py @@ -70,9 +70,20 @@ def generate_prometheus_config(prometheus_jobs, config_file_path): if "scrape_configs" not in config_file_yaml: config_file_yaml["scrape_configs"] = [] + prometheus_jobs_to_be_added = [] + for prometheus_job in prometheus_jobs: cleaned_up_job = clean_up_job(prometheus_job) - config_file_yaml["scrape_configs"].append(cleaned_up_job) + job_to_be_added = True + for sc in config_file_yaml["scrape_configs"]: + if sc.get("job_name") == cleaned_up_job.get("job_name"): + job_to_be_added = False + break + if job_to_be_added: + prometheus_jobs_to_be_added.append(cleaned_up_job) + + for job in prometheus_jobs_to_be_added: + config_file_yaml["scrape_configs"].append(job) return config_file_yaml diff --git a/installers/docker/osm_pods/ng-prometheus.yaml b/installers/docker/osm_pods/ng-prometheus.yaml index 56aca67d..ebef7a9f 100644 --- a/installers/docker/osm_pods/ng-prometheus.yaml +++ b/installers/docker/osm_pods/ng-prometheus.yaml @@ -85,6 +85,9 @@ data: # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: + - job_name: 'mon_exporter' + static_configs: + - targets: ['mon:8000'] - job_name: pushgateway honor_labels: true scrape_interval: 30s diff --git a/installers/docker/osm_pods/prometheus.yaml b/installers/docker/osm_pods/prometheus.yaml index 2610710f..241ed726 100644 --- a/installers/docker/osm_pods/prometheus.yaml +++ b/installers/docker/osm_pods/prometheus.yaml @@ -73,8 +73,10 @@ data: # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. - scrape_configs: [] - # scrape_configs: + scrape_configs: + - job_name: 'mon_exporter' + static_configs: + - targets: ['mon:8000'] # Add here other external targets, e.g. a pushgateway # - job_name: 'pushgateway' # static_configs: -- 2.25.1