Skip to content

Commit

Permalink
Fix: Incorrect /query API documentation (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajerin authored Apr 12, 2024
1 parent 8f86ad4 commit 42a4978
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions dataplane-webserver/src/routes/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,36 @@ use reqwest::Client;
context_path = "/{namespace}/metrics",
params(
("namespace" = String, Path, example="org-coredb-inst-control-plane-dev", description = "Instance namespace"),
("query" = inline(String), Query, example="(sum by (namespace) (max_over_time(pg_stat_activity_count{namespace=\"org-coredb-inst-control-plane-dev\"}[1h])))", description = "PromQL range query, must include a 'namespace' label matching the query path"),
("query" = inline(String), Query, example="(sum by (namespace) (max_over_time(cnpg_backends_total{namespace=\"org-coredb-inst-control-plane-dev\"}[1h])))", description = "PromQL range query, must include a 'namespace' label matching the query path"),
("start" = inline(u64), Query, example="1686780828", description = "Range start, unix timestamp"),
("end" = inline(Option<u64>), Query, example="1686862041", description = "Range end, unix timestamp. Default is now."),
("step" = inline(Option<String>), Query, example="60s", description = "Step size duration string, defaults to 60s"),
),
responses(
(status = 200, description = "Success range query to Prometheus, please see Prometheus documentation for response format details. https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries", body = Value,
example = json!({"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","job":"prometheus","instance":"localhost:9090"},"values":[[1435781430.781,"1"],[1435781445.781,"1"],[1435781460.781,"1"]]},{"metric":{"__name__":"up","job":"node","instance":"localhost:9091"},"values":[[1435781430.781,"0"],[1435781445.781,"0"],[1435781460.781,"1"]]}]}})
example = json!({
"data": {
"result": [
{
"metric": {
"namespace": "org-uc-ceas-inst-set"
},
"values": [
[
1435781430,
"2"
],
[
1435781445,
"2"
]
]
}
],
"resultType": "matrix"
},
"status": "success"
}),
),
(status = 400, description = "Parameters are missing or incorrect"),
(status = 403, description = "Not authorized for query"),
Expand All @@ -41,11 +63,27 @@ pub async fn query_range(
context_path = "/{namespace}/metrics",
params(
("namespace" = String, Path, example="org-coredb-inst-control-plane-dev", description = "Instance namespace"),
("query" = inline(String), Query, example="(sum by (namespace) (max_over_time(pg_stat_activity_count{namespace=\"org-coredb-inst-control-plane-dev\"}[1h])))", description = "PromQL range query, must include a 'namespace' label matching the query path"),
("query" = inline(String), Query, example="(sum by (namespace) (max_over_time(cnpg_backends_total{namespace=\"org-coredb-inst-control-plane-dev\"}[1h])))", description = "PromQL range query, must include a 'namespace' label matching the query path"),
),
responses(
(status = 200, description = "Success range query to Prometheus, please see Prometheus documentation for response format details. https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries", body = Value,
example = json!({"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"up","job":"prometheus","instance":"localhost:9090"},"values":[[1435781430.781,"1"],[1435781445.781,"1"],[1435781460.781,"1"]]},{"metric":{"__name__":"up","job":"node","instance":"localhost:9091"},"values":[[1435781430.781,"0"],[1435781445.781,"0"],[1435781460.781,"1"]]}]}})
(status = 200, description = "Success range query to Prometheus, please see Prometheus documentation for response format details. https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries", body = Value,
example = json!({
"data": {
"result": [
{
"metric": {
"namespace": "org-coredb-inst-control-plane-dev"
},
"value": [
1435781430,
"2"
]
}
],
"resultType": "vector"
},
"status": "success"
}),
),
(status = 400, description = "Parameters are missing or incorrect"),
(status = 403, description = "Not authorized for query"),
Expand Down

0 comments on commit 42a4978

Please sign in to comment.