未验证 提交 8c51043d 编写于 作者: Z Zhenxu Ke 提交者: GitHub

Remove duplicate codes in Envoy ALS handler (#6263)

上级 7b1c63de
......@@ -76,6 +76,7 @@ Release Notes.
* Add node information from the Openensus proto to the labels of the samples, to support the identification of the source of the Metric data.
* Fix bug that the same sample name in one MAL expression caused `IllegalArgumentException` in `Analyzer.analyse`.
* Add the text analyzer for querying log in the es storage.
* Chore: Remove duplicate codes in Envoy ALS handler
#### UI
* Fix un-removed tags in trace query.
......
......@@ -31,12 +31,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.meter.analyzer.prometheus.PrometheusMetricConverter;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.analysis.meter.MeterSystem;
import org.apache.skywalking.oap.server.core.analysis.NodeType;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceUpdate;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.module.ModuleStartException;
import org.apache.skywalking.oap.server.library.util.prometheus.metrics.Metric;
......@@ -51,13 +46,11 @@ import org.apache.skywalking.oap.server.telemetry.api.MetricsTag;
@Slf4j
public class MetricServiceGRPCHandler extends MetricsServiceGrpc.MetricsServiceImplBase {
private final SourceReceiver sourceReceiver;
private final CounterMetrics counter;
private final HistogramMetrics histogram;
private final List<PrometheusMetricConverter> converters;
public MetricServiceGRPCHandler(final ModuleManager moduleManager, final EnvoyMetricReceiverConfig config) throws ModuleStartException {
sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
MetricsCreator metricsCreator = moduleManager.find(TelemetryModule.NAME)
.provider()
.getService(MetricsCreator.class);
......@@ -102,13 +95,10 @@ public class MetricServiceGRPCHandler extends MetricsServiceGrpc.MetricsServiceI
if (service != null && StringUtil.isNotEmpty(service.getServiceName()) && StringUtil.isNotEmpty(service.getServiceInstanceName())) {
List<Metrics.MetricFamily> list = message.getEnvoyMetricsList();
boolean needHeartbeatUpdate = true;
for (final Metrics.MetricFamily metricFamily : list) {
counter.inc();
final String serviceId = IDManager.ServiceID.buildId(service.getServiceName(), NodeType.Normal);
try (final HistogramMetrics.Timer ignored = histogram.createTimer()) {
final ProtoMetricFamily2MetricsAdapter adapter = new ProtoMetricFamily2MetricsAdapter(metricFamily);
final Stream<Metric> metrics = adapter.adapt().peek(it -> {
......@@ -116,18 +106,6 @@ public class MetricServiceGRPCHandler extends MetricsServiceGrpc.MetricsServiceI
it.getLabels().putIfAbsent("instance", service.getServiceInstanceName());
});
converters.forEach(converter -> converter.toMeter(metrics));
if (needHeartbeatUpdate && list.get(0).getMetricCount() > 0) {
final long timestamp = adapter.adaptTimestamp(list.get(0).getMetric(0));
// Send heartbeat
ServiceInstanceUpdate serviceInstanceUpdate = new ServiceInstanceUpdate();
serviceInstanceUpdate.setName(service.getServiceInstanceName());
serviceInstanceUpdate.setServiceId(serviceId);
serviceInstanceUpdate.setTimeBucket(TimeBucket.getMinuteTimeBucket(timestamp));
sourceReceiver.receive(serviceInstanceUpdate);
needHeartbeatUpdate = false;
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册