Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a possible_prometheus_urls parameter to the OpenMetrics base check #9573

Merged
merged 12 commits into from
Jun 30, 2021
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# (C) Datadog, Inc. 2018-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from copy import deepcopy

import requests
from six import PY2

from ...errors import CheckException
Expand Down Expand Up @@ -97,7 +100,27 @@ def __init__(self, *args, **kwargs):

if instances is not None:
for instance in instances:
self.get_scraper_config(instance)
possible_urls = instance.get('prometheus_possible_urls')
if possible_urls is not None:
for url in possible_urls:
try:
new_instance = deepcopy(instance)
new_instance.update({'prometheus_url': url})
scraper_config = self.get_scraper_config(new_instance)
response = self.send_request(url, scraper_config)
response.raise_for_status()
instance['prometheus_url'] = url
self.get_scraper_config(instance)
break
except (IOError, requests.HTTPError, requests.exceptions.SSLError) as e:
self.log.info("Couldn't connect to %s: %s, trying next possible URL.", url, str(e))
else:
self.log.error(
"The agent could connect to none of the following URL: %s.",
str(instance['prometheus_possible_urls']),
)
else:
self.get_scraper_config(instance)

def check(self, instance):
# Get the configuration for this specific instance
Expand Down