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 2022/03/15 07:11:22 UTC

[GitHub] [skywalking] kezhenxu94 opened a new pull request #8680: Polish Zipkin HTTP receiver with Armeria APIs

kezhenxu94 opened a new pull request #8680:
URL: https://github.com/apache/skywalking/pull/8680


   <!--
       ⚠️ Please make sure to read this template first, pull requests that don't accord with this template
       maybe closed without notice.
       Texts surrounded by `<` and `>` are meant to be replaced by you, e.g. <framework name>, <issue number>.
       Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]`
   -->
   
   <!-- ==== 🐛 Remove this line WHEN AND ONLY WHEN you're fixing a bug, follow the checklist 👇 ====
   ### Fix <bug description or the bug issue number or bug issue link>
   - [ ] Add a unit test to verify that the fix works.
   - [ ] Explain briefly why the bug exists and how to fix it.
        ==== 🐛 Remove this line WHEN AND ONLY WHEN you're fixing a bug, follow the checklist 👆 ==== -->
   
   <!-- ==== 📈 Remove this line WHEN AND ONLY WHEN you're improving the performance, follow the checklist 👇 ====
   ### Improve the performance of <class or module or ...>
   - [ ] Add a benchmark for the improvement, refer to [the existing ones](https://github.com/apache/skywalking/blob/master/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/LinkedArrayBenchmark.java)
   - [ ] The benchmark result.
   ```text
   <Paste the benchmark results here>
   ```
   - [ ] Links/URLs to the theory proof or discussion articles/blogs. <links/URLs here>
        ==== 📈 Remove this line WHEN AND ONLY WHEN you're improving the performance, follow the checklist 👆 ==== -->
   
   <!-- ==== 🆕 Remove this line WHEN AND ONLY WHEN you're adding a new feature, follow the checklist 👇 ====
   ### <Feature description>
   - [ ] If this is non-trivial feature, paste the links/URLs to the design doc.
   - [ ] Update the documentation to include this new feature.
   - [ ] Tests(including UT, IT, E2E) are added to verify the new feature.
   - [ ] If it's UI related, attach the screenshots below.
        ==== 🆕 Remove this line WHEN AND ONLY WHEN you're adding a new feature, follow the checklist 👆 ==== -->
   
   - [x] If this pull request closes/resolves/fixes an existing issue, replace the issue number. Follow up #8673.
   - [x] Update the [`CHANGES` log](https://github.com/apache/skywalking/blob/master/CHANGES.md).
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] kezhenxu94 commented on a change in pull request #8680: Polish Zipkin HTTP receiver with Armeria APIs

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #8680:
URL: https://github.com/apache/skywalking/pull/8680#discussion_r826689472



##########
File path: oap-server/server-receiver-plugin/zipkin-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/zipkin/handler/ZipkinSpanHTTPHandler.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.zipkin.handler;
+
+import com.linecorp.armeria.common.HttpData;
+import com.linecorp.armeria.common.HttpRequest;
+import com.linecorp.armeria.common.HttpResponse;
+import com.linecorp.armeria.common.HttpStatus;
+import com.linecorp.armeria.server.ServiceRequestContext;
+import com.linecorp.armeria.server.annotation.ConsumesJson;
+import com.linecorp.armeria.server.annotation.ConsumesProtobuf;
+import com.linecorp.armeria.server.annotation.Post;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.config.NamingControl;
+import org.apache.skywalking.oap.server.core.source.SourceReceiver;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.receiver.zipkin.ZipkinReceiverConfig;
+import org.apache.skywalking.oap.server.receiver.zipkin.trace.SpanForward;
+import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
+import org.apache.skywalking.oap.server.telemetry.api.CounterMetrics;
+import org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics;
+import org.apache.skywalking.oap.server.telemetry.api.MetricsCreator;
+import org.apache.skywalking.oap.server.telemetry.api.MetricsTag;
+import zipkin2.Span;
+import zipkin2.codec.SpanBytesDecoder;
+
+import static java.util.Objects.nonNull;
+
+@Slf4j
+public class ZipkinSpanHTTPHandler {
+    private final ZipkinReceiverConfig config;
+    private final SourceReceiver sourceReceiver;
+    private final NamingControl namingControl;
+    private final HistogramMetrics histogram;
+    private final CounterMetrics errorCounter;
+
+    public ZipkinSpanHTTPHandler(ZipkinReceiverConfig config, ModuleManager manager) {
+        sourceReceiver = manager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
+        namingControl = manager.find(CoreModule.NAME).provider().getService(NamingControl.class);
+        this.config = config;
+        MetricsCreator metricsCreator = manager.find(TelemetryModule.NAME)
+                                               .provider()
+                                               .getService(MetricsCreator.class);
+        histogram = metricsCreator.createHistogramMetric(
+            "trace_in_latency", "The process latency of trace data",
+            new MetricsTag.Keys("protocol"), new MetricsTag.Values("zipkin")
+        );
+        errorCounter = metricsCreator.createCounter(
+            "trace_analysis_error_count", "The error number of trace analysis",
+            new MetricsTag.Keys("protocol"), new MetricsTag.Values("zipkin")
+        );
+    }
+
+    @Post("/api/v2/spans")
+    public HttpResponse collectV2Spans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V2, ctx, req);
+    }
+
+    @Post("/api/v2/spans")
+    @ConsumesJson
+    public HttpResponse collectV2JsonSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V2, ctx, req);
+    }
+
+    @Post("/api/v2/spans")
+    @ConsumesProtobuf
+    public HttpResponse collectV2ProtobufSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.PROTO3, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    public HttpResponse collectV1Spans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V1, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    @ConsumesJson
+    public HttpResponse collectV1JsonSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V1, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    @ConsumesThrift

Review comment:
       Here we are using the annotation `@Consumes**` to route the different protocols to responding decoder.




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] kezhenxu94 merged pull request #8680: Polish Zipkin HTTP receiver with Armeria APIs

Posted by GitBox <gi...@apache.org>.
kezhenxu94 merged pull request #8680:
URL: https://github.com/apache/skywalking/pull/8680


   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] kezhenxu94 commented on a change in pull request #8680: Polish Zipkin HTTP receiver with Armeria APIs

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #8680:
URL: https://github.com/apache/skywalking/pull/8680#discussion_r826687744



##########
File path: oap-server/server-receiver-plugin/zipkin-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/zipkin/handler/ZipkinSpanHTTPHandler.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.zipkin.handler;
+
+import com.linecorp.armeria.common.HttpData;
+import com.linecorp.armeria.common.HttpRequest;
+import com.linecorp.armeria.common.HttpResponse;
+import com.linecorp.armeria.common.HttpStatus;
+import com.linecorp.armeria.server.ServiceRequestContext;
+import com.linecorp.armeria.server.annotation.ConsumesJson;
+import com.linecorp.armeria.server.annotation.ConsumesProtobuf;
+import com.linecorp.armeria.server.annotation.Post;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.config.NamingControl;
+import org.apache.skywalking.oap.server.core.source.SourceReceiver;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.receiver.zipkin.ZipkinReceiverConfig;
+import org.apache.skywalking.oap.server.receiver.zipkin.trace.SpanForward;
+import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
+import org.apache.skywalking.oap.server.telemetry.api.CounterMetrics;
+import org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics;
+import org.apache.skywalking.oap.server.telemetry.api.MetricsCreator;
+import org.apache.skywalking.oap.server.telemetry.api.MetricsTag;
+import zipkin2.Span;
+import zipkin2.codec.SpanBytesDecoder;
+
+import static java.util.Objects.nonNull;
+
+@Slf4j
+public class ZipkinSpanHTTPHandler {
+    private final ZipkinReceiverConfig config;
+    private final SourceReceiver sourceReceiver;
+    private final NamingControl namingControl;
+    private final HistogramMetrics histogram;
+    private final CounterMetrics errorCounter;
+
+    public ZipkinSpanHTTPHandler(ZipkinReceiverConfig config, ModuleManager manager) {
+        sourceReceiver = manager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
+        namingControl = manager.find(CoreModule.NAME).provider().getService(NamingControl.class);
+        this.config = config;
+        MetricsCreator metricsCreator = manager.find(TelemetryModule.NAME)
+                                               .provider()
+                                               .getService(MetricsCreator.class);
+        histogram = metricsCreator.createHistogramMetric(
+            "trace_in_latency", "The process latency of trace data",
+            new MetricsTag.Keys("protocol"), new MetricsTag.Values("zipkin")
+        );
+        errorCounter = metricsCreator.createCounter(
+            "trace_analysis_error_count", "The error number of trace analysis",
+            new MetricsTag.Keys("protocol"), new MetricsTag.Values("zipkin")
+        );
+    }
+
+    @Post("/api/v2/spans")
+    public HttpResponse collectV2Spans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V2, ctx, req);
+    }
+
+    @Post("/api/v2/spans")
+    @ConsumesJson
+    public HttpResponse collectV2JsonSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V2, ctx, req);
+    }
+
+    @Post("/api/v2/spans")
+    @ConsumesProtobuf
+    public HttpResponse collectV2ProtobufSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.PROTO3, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    public HttpResponse collectV1Spans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V1, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    @ConsumesJson
+    public HttpResponse collectV1JsonSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V1, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    @ConsumesThrift

Review comment:
       You can see there are several methods mapped to the same endpoint `@Post("/api/v1/spans")`, this annotation `@ConsumesThrift` means only those requests with http header `Content-Type: application/x-thrift` will be handled by this method, meaning only thrift stream will be decoded by this method, correctly.




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [skywalking] wu-sheng commented on a change in pull request #8680: Polish Zipkin HTTP receiver with Armeria APIs

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #8680:
URL: https://github.com/apache/skywalking/pull/8680#discussion_r826685214



##########
File path: oap-server/server-receiver-plugin/zipkin-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/zipkin/handler/ZipkinSpanHTTPHandler.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.zipkin.handler;
+
+import com.linecorp.armeria.common.HttpData;
+import com.linecorp.armeria.common.HttpRequest;
+import com.linecorp.armeria.common.HttpResponse;
+import com.linecorp.armeria.common.HttpStatus;
+import com.linecorp.armeria.server.ServiceRequestContext;
+import com.linecorp.armeria.server.annotation.ConsumesJson;
+import com.linecorp.armeria.server.annotation.ConsumesProtobuf;
+import com.linecorp.armeria.server.annotation.Post;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.config.NamingControl;
+import org.apache.skywalking.oap.server.core.source.SourceReceiver;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.receiver.zipkin.ZipkinReceiverConfig;
+import org.apache.skywalking.oap.server.receiver.zipkin.trace.SpanForward;
+import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
+import org.apache.skywalking.oap.server.telemetry.api.CounterMetrics;
+import org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics;
+import org.apache.skywalking.oap.server.telemetry.api.MetricsCreator;
+import org.apache.skywalking.oap.server.telemetry.api.MetricsTag;
+import zipkin2.Span;
+import zipkin2.codec.SpanBytesDecoder;
+
+import static java.util.Objects.nonNull;
+
+@Slf4j
+public class ZipkinSpanHTTPHandler {
+    private final ZipkinReceiverConfig config;
+    private final SourceReceiver sourceReceiver;
+    private final NamingControl namingControl;
+    private final HistogramMetrics histogram;
+    private final CounterMetrics errorCounter;
+
+    public ZipkinSpanHTTPHandler(ZipkinReceiverConfig config, ModuleManager manager) {
+        sourceReceiver = manager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
+        namingControl = manager.find(CoreModule.NAME).provider().getService(NamingControl.class);
+        this.config = config;
+        MetricsCreator metricsCreator = manager.find(TelemetryModule.NAME)
+                                               .provider()
+                                               .getService(MetricsCreator.class);
+        histogram = metricsCreator.createHistogramMetric(
+            "trace_in_latency", "The process latency of trace data",
+            new MetricsTag.Keys("protocol"), new MetricsTag.Values("zipkin")
+        );
+        errorCounter = metricsCreator.createCounter(
+            "trace_analysis_error_count", "The error number of trace analysis",
+            new MetricsTag.Keys("protocol"), new MetricsTag.Values("zipkin")
+        );
+    }
+
+    @Post("/api/v2/spans")
+    public HttpResponse collectV2Spans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V2, ctx, req);
+    }
+
+    @Post("/api/v2/spans")
+    @ConsumesJson
+    public HttpResponse collectV2JsonSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V2, ctx, req);
+    }
+
+    @Post("/api/v2/spans")
+    @ConsumesProtobuf
+    public HttpResponse collectV2ProtobufSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.PROTO3, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    public HttpResponse collectV1Spans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V1, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    @ConsumesJson
+    public HttpResponse collectV1JsonSpans(ServiceRequestContext ctx, HttpRequest req) {
+        return doCollectSpans(SpanBytesDecoder.JSON_V1, ctx, req);
+    }
+
+    @Post("/api/v1/spans")
+    @ConsumesThrift

Review comment:
       Could you point out the doc to explain this? I think `x-thrift` is just a decoding process in Zipkin. Why does this relate to HTTP server?




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org