Skip to content

Commit

Permalink
Add metrics value owner for metrics topN query result (apache#12737)
Browse files Browse the repository at this point in the history
  • Loading branch information
wankai123 authored Nov 1, 2024
1 parent 9e5fb8f commit 39b579f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Support Kong monitoring.
* Support adding additional attr[0-4] for service level metrics.
* Support async-profiler feature for performance analysis.
* Add metrics value owner for metrics topN query result.

#### UI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
package org.apache.skywalking.mqe.rt.type;

import lombok.Data;
import org.apache.skywalking.oap.server.core.query.type.Owner;

@Data
public class MQEValue {
private String id;
private Owner owner;
private String value;
private String traceID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.skywalking.oap.server.core.query.type.Owner;
import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingSpan;
import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext;
import org.apache.skywalking.oap.server.library.util.StringUtil;
Expand Down Expand Up @@ -72,38 +73,56 @@ private List<SelectedRecord> invokeSortMetrics(TopNCondition condition, Duration
final List<SelectedRecord> selectedRecords = getAggregationQueryDAO().sortMetricsDebuggable(
condition, valueCName, duration, additionalConditions);
selectedRecords.forEach(selectedRecord -> {
Owner owner = new Owner();
owner.setScope(condition.getScope());
selectedRecord.setOwner(owner);
switch (condition.getScope()) {
case Service:
selectedRecord.setName(IDManager.ServiceID.analysisId(selectedRecord.getId()).getName());
final IDManager.ServiceID.ServiceIDDefinition serviceIDDefinition
= IDManager.ServiceID.analysisId(selectedRecord.getId());
selectedRecord.setName(serviceIDDefinition.getName());
owner.setServiceID(selectedRecord.getId());
owner.setServiceName(serviceIDDefinition.getName());
owner.setNormal(serviceIDDefinition.isReal());
break;
case ServiceInstance:
final IDManager.ServiceInstanceID.InstanceIDDefinition instanceIDDefinition
= IDManager.ServiceInstanceID.analysisId(selectedRecord.getId());
final IDManager.ServiceID.ServiceIDDefinition instanceServiceIDDefinition =
IDManager.ServiceID.analysisId(instanceIDDefinition.getServiceId());
/*
* Add the service name into the name if this is global top N.
*/
if (StringUtil.isEmpty(condition.getParentService())) {
IDManager.ServiceID.ServiceIDDefinition serviceIDDefinition =
IDManager.ServiceID.analysisId(instanceIDDefinition.getServiceId());
selectedRecord.setName(serviceIDDefinition.getName() + " - " + instanceIDDefinition.getName());
selectedRecord.setName(instanceServiceIDDefinition.getName() + " - " + instanceIDDefinition.getName());
} else {
selectedRecord.setName(instanceIDDefinition.getName());
}
owner.setServiceID(instanceIDDefinition.getServiceId());
owner.setServiceName(instanceServiceIDDefinition.getName());
owner.setNormal(instanceServiceIDDefinition.isReal());
owner.setServiceInstanceID(selectedRecord.getId());
owner.setServiceInstanceName(instanceIDDefinition.getName());
break;
case Endpoint:
final IDManager.EndpointID.EndpointIDDefinition endpointIDDefinition
= IDManager.EndpointID.analysisId(selectedRecord.getId());
final IDManager.ServiceID.ServiceIDDefinition endpointServiceIDDefinition =
IDManager.ServiceID.analysisId(endpointIDDefinition.getServiceId());
/*
* Add the service name into the name if this is global top N.
*/
if (StringUtil.isEmpty(condition.getParentService())) {
IDManager.ServiceID.ServiceIDDefinition serviceIDDefinition =
IDManager.ServiceID.analysisId(endpointIDDefinition.getServiceId());
selectedRecord.setName(serviceIDDefinition.getName()
selectedRecord.setName(endpointServiceIDDefinition.getName()
+ " - " + endpointIDDefinition.getEndpointName());
} else {
selectedRecord.setName(endpointIDDefinition.getEndpointName());
}
owner.setServiceID(endpointIDDefinition.getServiceId());
owner.setServiceName(endpointServiceIDDefinition.getName());
owner.setNormal(endpointServiceIDDefinition.isReal());
owner.setEndpointID(selectedRecord.getId());
owner.setEndpointName(endpointIDDefinition.getEndpointName());
break;
default:
selectedRecord.setName(Const.UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.
*
*/

package org.apache.skywalking.oap.server.core.query.type;

import lombok.Data;
import org.apache.skywalking.oap.server.core.query.enumeration.Scope;

@Data
public class Owner {
private Scope scope;
private String serviceID;
private String serviceName;
private Boolean normal;
private String serviceInstanceID;
private String serviceInstanceName;
private String endpointID;
private String endpointName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public class SelectedRecord {
* Have value, Only if the record has related trace id. UI should show this as an attached value.
*/
private String refId;
/**
* The owner entity of this record.
*/
private Owner owner;
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private void querySortMetrics(String metricName,
mqeValue.setId(selectedRecord.getName());
mqeValue.setEmptyValue(false);
mqeValue.setDoubleValue(Double.parseDouble(selectedRecord.getValue()));
mqeValue.setOwner(selectedRecord.getOwner());
mqeValueList.add(mqeValue);
});
MQEValues mqeValues = new MQEValues();
Expand Down

0 comments on commit 39b579f

Please sign in to comment.