Commit 3440dd3c authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'fix-avs-grafanads-format-result' into 'master'

Fix default format result on grafanads services query.

See merge request noc/noc!6309
parents f3084089 b99bfdf6
......@@ -231,12 +231,8 @@ class JsonDSAPI(object):
except ClickhouseError as e:
self.logger.error("Clickhouse query error: %s", e)
raise HTTPException(status_code=500, detail=e)
r += self.format_result(
request_metrics={qc.alias or qc.metric_type for qc in query_configs},
return r
r += [(query_configs, orjson.loads(result))]
return self.format_result(r, result_type=req.result_type)
def get_query(
......@@ -301,28 +297,35 @@ class JsonDSAPI(object):
def format_result(
cls, result, result_type: str = "timeseries", request_metrics: Set["str"] = None
Formatting output
:param result:
:param result_type:
:param request_metrics: Set requested metric
r = []
for row in result["data"]:
def format_time_series(cls, results: List[Tuple[List["QueryConfig"], Dict[str, Any]]]):
result = []
for query_configs, data in results:
request_metrics = {qc.alias or qc.metric_type for qc in query_configs}
for row in data["data"]:
for field in row:
if field == "target":
r.append({"target": f"{field} | {row['target']}", "datapoints": row[field]})
{"target": f"{field} | {row['target']}", "datapoints": row[field]}
if field in request_metrics:
# Add metrics without data
for rm_name in request_metrics:
r.append({"target": f"{rm_name}", "datapoints": []})
return r
result.append({"target": f"{rm_name}", "datapoints": []})
return result
def format_result(
results: List[Tuple[List["QueryConfig"], Dict[str, Any]]],
result_type: str = "time_series",
if not hasattr(cls, f"format_{result_type}"):
raise HTTPException(
status_code=404, detail=f"Requested format '{result_type}' not supported"
return getattr(cls, f"format_{result_type}")(results)
def get_target_expression(table_name: str = None) -> Tuple[str, Optional[str]]:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment