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

Change Prometheus configuration from 'host' to 'url' #273

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/supremm/datasource/prometheus/prominterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class PromClient():
""" Client class to interface with Prometheus """

def __init__(self, resconf):
self._url = "http://{}".format(resconf['prom_host'])
self._url = "{}".format(resconf['prom_url'])

self._client = requests.Session()
self._client.mount(self._url, self._client.get_adapter(self._url))
self._client.headers.update({'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'})

if resconf["prom_user"] == "":
if resconf['prom_user'] == "":
self._client.auth = (None, None)
else:
self._client.auth = (resconf['prom_user'], resconf['prom_password'])
Expand All @@ -37,7 +37,7 @@ def build_info(client, test_url):
""" Query server build info. Test connection to server. """

endpoint = "/api/v1/status/buildinfo"
url = urlparse.urljoin(test_url, endpoint)
url = "".join([test_url, endpoint])

r = client.get(url)
if r.status_code != 200:
Expand All @@ -60,7 +60,7 @@ def query(self, query, time):
}

endpoint = "/api/v1/query"
url = urlparse.urljoin(self._url, endpoint)
url = "".join([self._url, endpoint])

r = self._client.get(url, params=params)
if r.status_code != 200:
Expand All @@ -80,7 +80,7 @@ def query_range(self, query, start, end):
}

endpoint = "/api/v1/query_range"
url = urlparse.urljoin(self._url, endpoint)
url = "".join([self._url, endpoint])

r = self._client.get(url, params=params)
if r.status_code != 200:
Expand All @@ -100,7 +100,7 @@ def ispresent(self, match, start, end):

endpoint = "/api/v1/series"
urlparse.urlencode(params, doseq=True)
url = urlparse.urljoin(self._url, endpoint)
url = "".join([self._url, endpoint])
logging.debug('Prometheus QUERY SERIES META, start=%s end=%s', start, end)

r = self._client.get(url, params=params)
Expand All @@ -122,7 +122,8 @@ def label_val(self, match, label, start, end):
}

urlparse.urlencode(params, doseq=True)
url = urlparse.urljoin(self._url, "/api/v1/label/%s/values" % label)
endpoint = "/api/v1/label/{}/values".format(label)
url = "".join([self._url, endpoint])
logging.debug('Prometheus QUERY LABEL VALUES, start=%s end=%s', start, end)

# Query data
Expand All @@ -147,7 +148,7 @@ def cgroup_info(self, uid, jobid, start, end):
}

urlparse.urlencode(params, doseq=True)
url = urlparse.urljoin(self._url, "/api/v1/label/cgroup/values")
url = "".join([self._url, "/api/v1/label/cgroup/values"])
logging.debug('Prometheus QUERY CGROUP, start=%s end=%s', start, end)

# Query data
Expand Down
18 changes: 9 additions & 9 deletions src/supremm/supremm_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def configure_resource(display, resource_id, resource, defaults):
"host_name_ext": get_hostname_ext(),
"datasource": "pcp",
"pcp_log_dir": "/data/" + resource + "/pcp-logs",
"prom_host": "localhost:9090",
"prom_url": "localhost",
"prom_user": "username",
"prom_password": "password",
"batchscript.path": "/data/" + resource + "/jobscripts",
Expand All @@ -274,7 +274,7 @@ def configure_resource(display, resource_id, resource, defaults):
"host_name_ext": "domain name for resource",
"datasource": "Data collector backend (pcp or prometheus)",
"pcp_log_dir": "Directory containing node-level PCP archives",
"prom_host": "Hostname for Prometheus server",
"prom_url": "URL for Prometheus server",
"prom_user": "Username for basic authentication to Prometheus server (enter [space] for none)",
"prom_password": "Password for basic authentication to Prometheus server",
"batchscript.path": "Directory containing job launch scripts (enter [space] for none)",
Expand Down Expand Up @@ -315,12 +315,12 @@ def configure_resource(display, resource_id, resource, defaults):
WARNING The directory {0} does not exist. Make sure to create and populate this
directory before running the summarization software.
""".format(setting[key]))
del setting["prom_host"]
del setting["prom_url"]
break

elif setting[key] == "prometheus":
key = "prom_host"
del setting["pcp_log_dir"]
key = "prom_url"
setting[key] = display.prompt_input(descriptions[key], resdefault.get(key, setting[key]))

key = "prom_user"
Expand All @@ -333,14 +333,14 @@ def configure_resource(display, resource_id, resource, defaults):
setting["prom_password"] = ""

# Naive test connection to prometheus
url = "http://{}/api/v1/status/buildinfo".format(setting["prom_host"])
url = "{}/api/v1/status/buildinfo".format(setting["prom_url"])
try:
build_info = requests.get(url, auth=(setting["prom_user"], setting["prom_password"]))
except requests.exceptions.RequestException as exc:
display.print_warning("""
WARNING Unable to reach prometheus server at http://{}.
WARNING Unable to reach prometheus server at {}.
Make sure the server is running and is accessible before running the summarization software.
""".format(setting["prom_host"]))
""".format(url))
break

if build_info.status_code == 401:
Expand All @@ -352,8 +352,8 @@ def configure_resource(display, resource_id, resource, defaults):

elif build_info.status_code != 200:
display.print_warning("""
WARNING Status code {} returned from Prometheus at http://{}.
""".format(build_info.status_code, setting["prom_host"]))
WARNING Status code {} returned from Prometheus at {}.
""".format(build_info.status_code, setting["prom_url"]))
break

display.print_text("""
Expand Down