You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2019/03/06 13:16:55 UTC

[GitHub] [incubator-skywalking] wu-sheng commented on a change in pull request #2321: Envoy metric support and a bug fix

wu-sheng commented on a change in pull request #2321: Envoy metric support and a bug fix
URL: https://github.com/apache/incubator-skywalking/pull/2321#discussion_r262935300
 
 

 ##########
 File path: oap-server/server-receiver-plugin/envoy-metrics-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/envoy/MetricServiceGRPCHandler.java
 ##########
 @@ -0,0 +1,153 @@
+/*
+ * 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.receiver.envoy;
+
+import io.envoyproxy.envoy.api.v2.core.Node;
+import io.envoyproxy.envoy.service.metrics.v2.*;
+import io.grpc.stub.StreamObserver;
+import io.prometheus.client.Metrics;
+import java.util.List;
+import org.apache.skywalking.apm.util.StringUtil;
+import org.apache.skywalking.oap.server.core.*;
+import org.apache.skywalking.oap.server.core.register.service.*;
+import org.apache.skywalking.oap.server.core.source.*;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.util.TimeBucketUtils;
+import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
+import org.apache.skywalking.oap.server.telemetry.api.*;
+import org.slf4j.*;
+
+/**
+ * @author wusheng
+ */
+public class MetricServiceGRPCHandler extends MetricsServiceGrpc.MetricsServiceImplBase {
+    private static final Logger logger = LoggerFactory.getLogger(MetricServiceGRPCHandler.class);
+
+    private final IServiceInventoryRegister serviceInventoryRegister;
+    private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
+    private final SourceReceiver sourceReceiver;
+    private CounterMetric counter;
+    private HistogramMetric histogram;
+
+    public MetricServiceGRPCHandler(ModuleManager moduleManager) {
+        serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
+        serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
+        sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
+        MetricCreator metricCreator = moduleManager.find(TelemetryModule.NAME).provider().getService(MetricCreator.class);
+        counter = metricCreator.createCounter("envoy_metric_in_count", "The count of envoy service metric received",
+            MetricTag.EMPTY_KEY, MetricTag.EMPTY_VALUE);
+        histogram = metricCreator.createHistogramMetric("envoy_metric_in_latency", "The process latency of service metric receiver",
+            MetricTag.EMPTY_KEY, MetricTag.EMPTY_VALUE);
+    }
+
+    @Override
+    public StreamObserver<StreamMetricsMessage> streamMetrics(StreamObserver<StreamMetricsResponse> responseObserver) {
+        return new StreamObserver<StreamMetricsMessage>() {
+            private boolean isFirst = true;
+            private String serviceName = null;
+            private int serviceId = Const.NONE;
+            private String serviceInstanceName = null;
+            private int serviceInstanceId = Const.NONE;
+
+            @Override public void onNext(StreamMetricsMessage message) {
+                if (isFirst) {
+                    isFirst = false;
+                    StreamMetricsMessage.Identifier identifier = message.getIdentifier();
+                    Node node = identifier.getNode();
+                    if (node != null) {
+                        String nodeId = node.getId();
+                        if (!StringUtil.isEmpty(nodeId)) {
+                            serviceInstanceName = nodeId;
 
 Review comment:
   @ZackButcher I am using node id in identify as the service instance name, does this make sense?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services