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

agent_prometheus: fixed promql mode (init, query quoting), API prefix… #513

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmk/special_agents/agent_prometheus.py
Expand Up @@ -1529,7 +1529,10 @@ class PrometheusAPI:

def __init__(self, session) -> None: # type:ignore[no-untyped-def]
self.session = session
self.scrape_targets_dict = self._connected_scrape_targets()

@property
def scrape_targets_dict(self) -> Dict[str, Any]:
return self._connected_scrape_targets()

def scrape_targets_attributes(self) -> Iterator[Tuple[str, Dict[str, Any]]]:
"""Format the scrape_targets_dict for information processing
Expand Down Expand Up @@ -1622,7 +1625,7 @@ def query_promql(self, promql: str) -> List[PromQLResult]:
return []

def _perform_promql_query(self, promql: str) -> List[Dict[str, Any]]:
api_query_expression = "query?query=%s" % quote(promql)
api_query_expression = "query?query=%s" % promql
result = self._process_json_request(api_query_expression)["data"]["result"]
return result

Expand Down
11 changes: 7 additions & 4 deletions cmk/special_agents/utils/prometheus.py
Expand Up @@ -43,10 +43,13 @@ def extract_connection_args(config):

address = config["host_address"] if connect_type == "ip_address" else config["host_name"]

if "path-prefix" in connect_settings:
address = f"{connect_settings['path-prefix']}{address}"
path_prefix = connect_settings.get("path-prefix", "")
if path_prefix:
path_prefix = path_prefix + "/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to ignore: This is reimplementing existing functionality inside of parse_api_url. I would change it.


connection_args.update({"address": address, "port": connect_settings.get("port")})
connection_args.update(
{"address": address, "path-prefix": path_prefix, "port": connect_settings.get("port")}
)
return connection_args


Expand All @@ -60,7 +63,7 @@ def generate_api_session(connection_options):
else:
api_url = parse_api_url(
server_address=connection_options["address"],
api_path="api/v1/",
api_path=connection_options["path-prefix"] + "api/v1/",
protocol=connection_options["protocol"],
port=connection_options["port"],
)
Expand Down