Skip to content

Commit

Permalink
Fix MQE top_n global query. (#12163)
Browse files Browse the repository at this point in the history
  • Loading branch information
wankai123 authored Apr 26, 2024
1 parent 9b2cca9 commit a38628f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
13 changes: 11 additions & 2 deletions docs/en/api/metrics-query-expression.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,15 @@ round(service_cpm / 60 , 2)
The different operators could impact the `ExpressionResultType`, please refer to the above table.

## TopN Operation
TopN Operation takes an expression and performs TopN calculation on its results.
TopN Operation takes an expression and performs calculation to get the TopN of Services/Instances/Endpoints.
The result depends on the `entity` condition in the query.
- Global TopN:
- The `entity` is empty.
- The result is the topN Services/Instances/Endpoints in the whole traffics.
- **Notice**: If query the Endpoints metric, the global candidate set could be huge, please use it carefully.
- Service's Instances/Endpoints TopN:
- The `serviceName` in the `entity` is not empty.
- The result is the topN Instances/Endpoints of the service.

Expression:
```text
Expand All @@ -229,7 +237,8 @@ top_n(<metric_name>, <top_number>, <order>)
`order` is the order of the top results. The value of `order` can be `asc` or `des`.

For example:
If we want to query the top 10 services with the highest `service_cpm` metric value, we can use the following expression:
If we want to query the current service's top 10 instances with the highest `service_instance_cpm` metric value, we can use the following expression
under specific service:

```text
top_n(service_instance_cpm, 10, des)
Expand Down
1 change: 1 addition & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
* Support DoubleValue,IntValue,BoolValue in OTEL metrics attributes.
* [Break Change] gGRPC metrics exporter unified the metric value type and support labeled metrics.
* Add component definition(ID=152) for `c3p0`(JDBC3 Connection and Statement Pooling).
* Fix MQE `top_n` global query.

#### UI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ public List<SelectedRecord> sortMetrics(TopNCondition condition, Duration durati
final String valueCName = ValueColumnMetadata.INSTANCE.getValueCName(condition.getName());
List<KeyValue> additionalConditions = null;
if (StringUtil.isNotEmpty(condition.getParentService())) {
if (condition.getNormal() == null) {
return Collections.emptyList();
}
additionalConditions = new ArrayList<>(1);
final String serviceId = IDManager.ServiceID.buildId(condition.getParentService(), condition.isNormal());
final String serviceId = IDManager.ServiceID.buildId(condition.getParentService(), condition.getNormal());
additionalConditions.add(new KeyValue(InstanceTraffic.SERVICE_ID, serviceId));
}
final List<SelectedRecord> selectedRecords = getAggregationQueryDAO().sortMetrics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public RecordCondition(TopNCondition condition) {
final Entity entity = new Entity();
entity.setScope(condition.getScope() == null ? Scope.Service : condition.getScope());
entity.setServiceName(condition.getParentService());
entity.setNormal(condition.isNormal());
entity.setNormal(condition.getNormal());
this.parentEntity = entity;
}
this.topN = condition.getTopN();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TopNCondition {
* Normal service is the service having installed agent or metrics reported directly. Unnormal service is
* conjectural service, usually detected by the agent.
*/
private boolean normal;
private Boolean normal;
/**
* Indicate the metrics entity scope. Because this is a top list, don't need to set the Entity like the
* MetricsCondition. Only accept scope = {@link Scope#Service} {@link Scope#ServiceInstance} and {@link
Expand Down

0 comments on commit a38628f

Please sign in to comment.