Skip to content

Commit

Permalink
metric token support added for retrieve metrics function
Browse files Browse the repository at this point in the history
  • Loading branch information
sametd committed Dec 20, 2023
1 parent 03aebe7 commit 7032e59
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def __init__(self, config: Config, msg_receiver=None):
self.monitor_servers = config.monitor_servers
self.msg_receiver = msg_receiver
self.token = {}
if config.kube_state_metrics["ssl_enabled"]:
self.metric_ssl_enabled = True
self.metric_token = config.kube_state_metrics["token"]

def ms_authenticate(self, m_server):
"""
Expand Down Expand Up @@ -199,16 +202,19 @@ def aggregate_unique_counter_tlms(tlms):
}
return agg_tlm

def retrieve_metrics(metric_servers, req_timeout):
def retrieve_metrics(self, metric_servers, req_timeout):
"""
This methods retrieves the metrics provided by specific metric servers using a Prometheus interface.
"""
raw_tlms = {}
for u in metric_servers:
url = u + "/metrics"
logger.debug(f"Retrieving metrics from {url}...")
headers = {}
try:
resp = requests.get(url, verify=False, timeout=req_timeout)
if self.metric_ssl_enabled:
headers["Authorization"] = f"Bearer {self.metric_token}"
resp = requests.get(url, verify=False, timeout=req_timeout, headers=headers)
except Exception as e:
logger.exception(f"Not able to get metrics from {url}, error {e}")
raw_tlms[u] = None
Expand Down

0 comments on commit 7032e59

Please sign in to comment.