Fix PromQL HTTP API `/api/v1/labels` response missing `service` label. (#10579)

This commit is contained in:
Wan Kai 2023-03-23 16:40:05 +08:00 committed by GitHub
parent 0de087a100
commit d88d887a32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 11 deletions

View File

@ -2,10 +2,10 @@
PromQL([Prometheus Query Language](https://prometheus.io/docs/prometheus/latest/querying/basics/)) Service
exposes Prometheus Querying HTTP APIs including the bundled PromQL expression system.
Third-party systems or visualization platforms that already support PromQL (such as Grafana),
could obtain metrics through PromeQL Service.
could obtain metrics through PromQL Service.
As SkyWalking and Prometheus have fundamental differences in metrics classification, format, storage, etc.
The PromQL Service supported will be a subset of the complete PromQL
The PromQL Service supported will be a subset of the complete PromQL.
## Details Of Supported Protocol
The following doc describes the details of the supported protocol and compared it to the PromQL official documentation.
@ -286,7 +286,7 @@ Result:
"status": "success",
"data": [
"layer",
"scope",
"service",
"top_n",
"order",
"service_instance",
@ -382,7 +382,7 @@ Result:
## Metrics Type For Query
### Supported Metrics [Scope](../../../oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/enumeration/Scope.java)(Catalog)
All scopes are not supported completely, please check the following table:
Not all scopes are supported for now, please check the following table:
| Scope | Support |
|-------------------------|---------|

View File

@ -18,6 +18,7 @@
* Support collect process level related metrics.
* Fix K8sRetag reads the wrong k8s service from the cache due to a possible namespace mismatch.
* [Breaking Change] Support cross-thread trace profiling. The data structure and query APIs are changed.
* Fix PromQL HTTP API `/api/v1/labels` response missing `service` label.
#### UI
* Revert: cpm5d function. This feature is cancelled from backend.

View File

@ -459,7 +459,7 @@ public class PromQLApiHandler {
Column.ValueDataType dataType) {
List<LabelName> labelNames = new ArrayList<>();
labelNames.add(LabelName.LAYER);
labelNames.add(LabelName.SCOPE);
labelNames.add(LabelName.SERVICE);
labelNames.add(LabelName.TOP_N);
labelNames.add(LabelName.ORDER);
if (Column.ValueDataType.LABELED_VALUE == dataType) {

View File

@ -179,7 +179,7 @@ public class PromQLExprQueryVisitor extends PromQLParserBaseVisitor<ParseResult>
try {
String metricName = ctx.metricName().getText();
Optional<ValueColumnMetadata.ValueColumn> valueColumn = getValueColumn(metricName);
if (!valueColumn.isPresent()) {
if (valueColumn.isEmpty()) {
result.setErrorType(ErrorType.BAD_DATA);
result.setErrorInfo("Metric: [" + metricName + "] dose not exist.");
return result;
@ -261,9 +261,9 @@ public class PromQLExprQueryVisitor extends PromQLParserBaseVisitor<ParseResult>
LabelName... labelNames) throws IllegalExpressionException {
StringBuilder missLabels = new StringBuilder();
int j = 0;
for (int i = 0; i < labelNames.length; i++) {
String labelName = labelNames[i].toString();
if (labelMap.get(labelNames[i]) == null) {
for (final LabelName name : labelNames) {
String labelName = name.toString();
if (labelMap.get(name) == null) {
missLabels.append(j++ > 0 ? "," : "").append(labelName);
}
}
@ -335,12 +335,12 @@ public class PromQLExprQueryVisitor extends PromQLParserBaseVisitor<ParseResult>
MetricsCondition metricsCondition = buildMetricsCondition(metricName, layer, scope, labelMap);
Map<String, String> relabelMap = new HashMap<>();
String queryLabels = labelMap.get(LabelName.LABELS);
List<String> queryLabelList = Collections.EMPTY_LIST;
List<String> queryLabelList = Collections.emptyList();
if (StringUtil.isNotBlank(queryLabels)) {
queryLabelList = Arrays.asList(queryLabels.split(Const.COMMA));
String relabels = labelMap.get(LabelName.RELABELS);
List<String> relabelList = Collections.EMPTY_LIST;
List<String> relabelList = Collections.emptyList();
if (StringUtil.isNotBlank(relabels)) {
relabelList = Arrays.asList(relabels.split(Const.COMMA));
}