Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Avi-Robusta committed Mar 3, 2024
1 parent a19cd2e commit 28b3f64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
12 changes: 4 additions & 8 deletions playbooks/robusta_playbooks/version_mismatch_enricher.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ def is_results_valid(self) -> bool:
logging.error(f"Prometheus is missing the 'node' label, unable to detect node versions.")
return False

# you can have multiple versions of the api server in the metrics at once
# i.e. at the time of kubernetes upgrade both will show up in the metrics for several minutes
if len(self.api_versions) == 0:
logging.error(f"Missing api server results for version_mismatch_enricher.")
return False
return True

def results_to_node_table(self) -> List[List[str]]:
Expand Down Expand Up @@ -77,15 +72,16 @@ def version_mismatch_enricher(alert: PrometheusKubernetesAlert, params: VersionM
logging.error(f"Invalid prometheus results for version_mismatch_enricher.")
return

if len(build_infos.api_versions) > 1:
if len(build_infos.api_versions) == 0:
api_version_string = f"version is unknown"
elif len(build_infos.api_versions) > 1:
api_version_string = f"has reported versions {', '.join(build_infos.api_versions)}"
else:
else: # one build version
api_version_string = f"is version {build_infos.api_versions[0]}"

# in the case where a node is of a higher version than the api server
alert.add_enrichment(
[
MarkdownBlock(f"Automatic {alert.alert_name} investigation:"),
MarkdownBlock(f"The kubernetes api server {api_version_string}."),
TableBlock(
build_infos.results_to_node_table(),
Expand Down
16 changes: 6 additions & 10 deletions src/robusta/core/playbooks/prometheus_enrichment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,12 @@ def run_prometheus_query(prometheus_params: PrometheusParams, query: str) -> Pro
This function runs prometheus query and returns the result (usually a vector),
For graphs use run_prometheus_query_range which uses the prometheus query_range api
"""
try:
prom = get_prometheus_connect(prometheus_params)
query = __add_additional_labels(query, prometheus_params)
prom_params = {"timeout": PROMETHEUS_REQUEST_TIMEOUT_SECONDS}
prom.check_prometheus_connection(prom_params)
results = prom.safe_custom_query(query=query, params=prom_params)
return PrometheusQueryResult(results)
except Exception as e:
logging.error(f"Exception while querying prometheus.", exc_info=True)
return PrometheusQueryResult({"resultType": "error", "result": str(e)})
prom = get_prometheus_connect(prometheus_params)
query = __add_additional_labels(query, prometheus_params)
prom_params = {"timeout": PROMETHEUS_REQUEST_TIMEOUT_SECONDS}
prom.check_prometheus_connection(prom_params)
results = prom.safe_custom_query(query=query, params=prom_params)
return PrometheusQueryResult(results)


def __add_additional_labels(query: str, prometheus_params: PrometheusParams) -> str:
Expand Down

0 comments on commit 28b3f64

Please sign in to comment.