[Feature] Support to query relation metrics through PromQL. (#12316)

This commit is contained in:
yswdqz 2024-06-16 14:46:22 +08:00 committed by GitHub
parent a6c7c71663
commit bef9eec44b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 75 additions and 8 deletions

View File

@ -389,8 +389,9 @@ Not all scopes are supported for now, please check the following table:
| Service | yes |
| ServiceInstance | yes |
| Endpoint | yes |
| ServiceRelation | no |
| ServiceInstanceRelation | no |
| ServiceRelation | yes |
| ServiceInstanceRelation | yes |
| EndpointRelation | yes |
| Process | no |
| ProcessRelation | no |
@ -398,11 +399,14 @@ Not all scopes are supported for now, please check the following table:
Each metric contains general labels: [layer](../../../oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/Layer.java).
Different metrics will have different labels depending on their Scope and metric value type.
| Query Labels | Scope | Expression Example |
|----------------------------------|-----------------|------------------------------------------------------------------------------------------------|
| layer, service | Service | service_cpm{service='$service', layer='$layer'} |
| layer, service, service_instance | ServiceInstance | service_instance_cpm{service='$service', service_instance='$service_instance', layer='$layer'} |
| layer, service, endpoint | Endpoint | endpoint_cpm{service='$service', endpoint='$endpoint', layer='$layer'} |
| Query Labels | Scope | Expression Example |
|-----------------------------------------------------------------------------------|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| layer, service | Service | service_cpm{service='$service', layer='$layer'} |
| layer, service, service_instance | ServiceInstance | service_instance_cpm{service='$service', service_instance='$service_instance', layer='$layer'} |
| layer, service, endpoint | Endpoint | endpoint_cpm{service='$service', endpoint='$endpoint', layer='$layer'} |
| layer, service, dest_service, dest_layer | ServiceRelation | service_relation_metric{service='$service', layer='$layer', dest_layer='$dest_layer', dest_service='$dest_service'} |
| layer, service, dest_service, dest_layer, service_instance, dest_service_instance | ServiceInstanceRelation | service_instance_relation_metric{service='$service', layer='$layer', dest_layer='$dest_layer', dest_service='$dest_service', dest_service_instance='$dest_service_instance', service_instance='$service_instance'} |
| layer, service, dest_service, dest_layer, endpoint, dest_endpoint | EndpointRelation | endpoint_relation_metric{service='$service', endpoint='$endpoint', layer='$layer', dest_layer='$dest_layer', dest_service='$dest_service', dest_endpoint='$dest_endpoint'} |

View File

@ -10,6 +10,7 @@
* Add Golang as a supported language for Elasticsearch.
* Remove unnecessary BanyanDB flushing logs(info).
* Increase `SW_CORE_GRPC_MAX_MESSAGE_SIZE` to 50MB.
* Support to query relation metrics through PromQL.
#### UI

View File

@ -44,7 +44,14 @@ public enum LabelName {
RECORD("record"),
//For endpoint_traffic
LIMIT("limit"),
KEYWORD("keyword");
KEYWORD("keyword"),
//for service_relation_traffic
DEST_SERVICE("dest_service"),
DEST_LAYER("dest_layer"),
//for service_instance_relation_traffic
DEST_SERVICE_INSTANCE("dest_service_instance"),
//for endpoint_relation
DEST_ENDPOINT("dest_endpoint");
final String label;

View File

@ -440,6 +440,25 @@ public class PromQLExprQueryVisitor extends PromQLParserBaseVisitor<ParseResult>
checkLabels(labelMap, LabelName.ENDPOINT);
entity.setEndpointName(labelMap.get(LabelName.ENDPOINT));
break;
case ServiceRelation:
checkLabels(labelMap, LabelName.DEST_SERVICE, LabelName.DEST_LAYER);
entity.setDestServiceName(labelMap.get(LabelName.DEST_SERVICE));
entity.setDestNormal(Layer.nameOf(labelMap.get(LabelName.DEST_LAYER)).isNormal());
break;
case ServiceInstanceRelation:
checkLabels(labelMap, LabelName.DEST_SERVICE, LabelName.SERVICE_INSTANCE, LabelName.DEST_SERVICE_INSTANCE, LabelName.DEST_LAYER);
entity.setDestServiceName(labelMap.get(LabelName.DEST_SERVICE));
entity.setServiceInstanceName(labelMap.get(LabelName.SERVICE_INSTANCE));
entity.setDestServiceInstanceName(labelMap.get(LabelName.DEST_SERVICE_INSTANCE));
entity.setDestNormal(Layer.nameOf(labelMap.get(LabelName.DEST_LAYER)).isNormal());
break;
case EndpointRelation:
checkLabels(labelMap, LabelName.DEST_SERVICE, LabelName.ENDPOINT, LabelName.DEST_ENDPOINT, LabelName.DEST_LAYER);
entity.setDestServiceName(labelMap.get(LabelName.DEST_SERVICE));
entity.setEndpointName(labelMap.get(LabelName.ENDPOINT));
entity.setDestEndpointName(labelMap.get(LabelName.DEST_ENDPOINT));
entity.setDestNormal(Layer.nameOf(labelMap.get(LabelName.DEST_LAYER)).isNormal());
break;
}
return entity;
}

View File

@ -0,0 +1,27 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
status: success
data:
resultType: vector
result:
{{- contains .data.result }}
- metric:
__name__: {{ .metric.__name__}}
layer: GENERAL
value:
- {{ index .value 0 }}
- {{ index .value 1 }}
{{- end}}

View File

@ -92,3 +92,12 @@ cases:
expected: expected/endpoint-metric-labeled-matrix.yml
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query_range -d 'query=endpoint_cpm{parent_service="e2e-service-consumer", layer="GENERAL",top_n="10", order="DES"}&start='$(($(date +%s)-1800))'&end='$(date +%s)
expected: expected/endpoint-metric-sort-matrix.yml
## ServiceRelation
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 'query=service_relation_client_cpm{service="e2e-service-consumer", dest_service="e2e-service-provider",layer="GENERAL", dest_layer="GENERAL"}'
expected: expected/relation-metric-vector.yml
## ServiceInstanceRelation
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 'query=service_instance_relation_client_cpm{service="e2e-service-consumer", dest_service="e2e-service-provider",layer="GENERAL", dest_layer="GENERAL",dest_service_instance="provider1",service_instance="consumer1"}'
expected: expected/relation-metric-vector.yml
## EndPointRelation
- query: curl -X GET http://${oap_host}:${oap_9090}/api/v1/query -d 'query=endpoint_relation_cpm{service="e2e-service-consumer", dest_service="e2e-service-provider",layer="GENERAL", dest_layer="GENERAL",dest_endpoint="POST:/users",endpoint="POST:/users"}'
expected: expected/relation-metric-vector.yml