From 5c5274b93a5a12ebab62edea4cca7246366e992a Mon Sep 17 00:00:00 2001 From: Wan Kai Date: Tue, 12 Nov 2024 15:11:00 +0800 Subject: [PATCH] Polish mesh data dispatcher: don't generate Instance/Endpoint metrics if they are empty. (#12762) --- docs/en/changes/changes.md | 1 + .../mesh/TelemetryDataDispatcher.java | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md index 540273269152..0617ec035e67 100644 --- a/docs/en/changes/changes.md +++ b/docs/en/changes/changes.md @@ -18,6 +18,7 @@ * The index type `BanyanDB.IndexRule.IndexType#TREE` is removed. All indices are using `IndexType#INVERTED` now. * Add max query size settings to BanyanDB. * Fix "BanyanDBTraceQueryDAO.queryBasicTraces" doesn't support querying by "trace_id". +* Polish mesh data dispatcher: don't generate Instance/Endpoint metrics if they are empty. #### UI diff --git a/oap-server/server-receiver-plugin/skywalking-mesh-receiver-plugin/src/main/java/org/apache/skywalking/aop/server/receiver/mesh/TelemetryDataDispatcher.java b/oap-server/server-receiver-plugin/skywalking-mesh-receiver-plugin/src/main/java/org/apache/skywalking/aop/server/receiver/mesh/TelemetryDataDispatcher.java index 11cdf191acbc..e72f28e3685d 100644 --- a/oap-server/server-receiver-plugin/skywalking-mesh-receiver-plugin/src/main/java/org/apache/skywalking/aop/server/receiver/mesh/TelemetryDataDispatcher.java +++ b/oap-server/server-receiver-plugin/skywalking-mesh-receiver-plugin/src/main/java/org/apache/skywalking/aop/server/receiver/mesh/TelemetryDataDispatcher.java @@ -167,15 +167,21 @@ private static void dispatchTCPMetrics(TCPServiceMeshMetric.Builder metrics) { if (org.apache.skywalking.apm.network.common.v3.DetectPoint.server.equals(metrics.getDetectPoint())) { toTCPService(metrics, minuteTimeBucket); - toTCPServiceInstance(metrics, minuteTimeBucket); - toTCPServiceInstanceTraffic(metrics, minuteTimeBucket); + // Don't generate instance metrics, if no dest instance. + if (StringUtil.isNotEmpty(metrics.getDestServiceInstance())) { + toTCPServiceInstance(metrics, minuteTimeBucket); + toTCPServiceInstanceTraffic(metrics, minuteTimeBucket); + } } String sourceService = metrics.getSourceServiceName(); // Don't generate relation, if no source. if (StringUtil.isNotEmpty(sourceService)) { toTCPServiceRelation(metrics, minuteTimeBucket); - toTCPServiceInstanceRelation(metrics, minuteTimeBucket); + // Don't generate instance relation, if no source instance. + if (StringUtil.isNotEmpty(metrics.getSourceServiceInstance())) { + toTCPServiceInstanceRelation(metrics, minuteTimeBucket); + } } } @@ -184,16 +190,25 @@ static void dispatchHTTPMetrics(HTTPServiceMeshMetric.Builder metrics) { if (org.apache.skywalking.apm.network.common.v3.DetectPoint.server.equals(metrics.getDetectPoint())) { toService(metrics, minuteTimeBucket); - toServiceInstance(metrics, minuteTimeBucket); - toServiceInstanceTraffic(metrics, minuteTimeBucket); - toEndpoint(metrics, minuteTimeBucket); + // Don't generate instance metrics, if no dest instance. + if (StringUtil.isNotEmpty(metrics.getDestServiceInstance())) { + toServiceInstance(metrics, minuteTimeBucket); + toServiceInstanceTraffic(metrics, minuteTimeBucket); + } + // Don't generate endpoint metrics, if no endpoint. + if (StringUtil.isNotEmpty(metrics.getEndpoint())) { + toEndpoint(metrics, minuteTimeBucket); + } } String sourceService = metrics.getSourceServiceName(); // Don't generate relation, if no source. if (StringUtil.isNotEmpty(sourceService)) { toServiceRelation(metrics, minuteTimeBucket); - toServiceInstanceRelation(metrics, minuteTimeBucket); + // Don't generate instance relation, if no source instance. + if (StringUtil.isNotEmpty(metrics.getSourceServiceInstance())) { + toServiceInstanceRelation(metrics, minuteTimeBucket); + } } }