You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "kezhenxu94 (via GitHub)" <gi...@apache.org> on 2023/01/22 01:40:25 UTC

[GitHub] [skywalking] kezhenxu94 commented on a diff in pull request #10300: Add aws-firehose-receiver to support collecting AWS CloudWatch metric(OpenTelemetry format)

kezhenxu94 commented on code in PR #10300:
URL: https://github.com/apache/skywalking/pull/10300#discussion_r1083377844


##########
oap-server/server-receiver-plugin/aws-firehose-receiver/src/main/java/org/apache/skywalking/oap/server/receiver/aws/firehose/FirehoseHTTPHandler.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.aws.firehose;
+
+import com.linecorp.armeria.server.annotation.ConsumesJson;
+import com.linecorp.armeria.server.annotation.Post;
+import com.linecorp.armeria.server.annotation.ProducesJson;
+import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Base64;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.receiver.otel.otlp.OpenTelemetryMetricRequestProcessor;
+
+@Slf4j
+@AllArgsConstructor
+public class FirehoseHTTPHandler {
+    @Post("/aws/firehose/metrics")
+    @ConsumesJson
+    @ProducesJson
+    public FirehoseRes collectMetrics(final FirehoseReq firehoseReq) {
+        try {
+            for (RequestData record : firehoseReq.getRecords()) {
+                final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
+                    Base64.getDecoder().decode(record.getData()));
+                ExportMetricsServiceRequest request;
+                while ((request = ExportMetricsServiceRequest.parseDelimitedFrom(byteArrayInputStream)) != null) {
+                    OpenTelemetryMetricRequestProcessor.INSTANCE.processMetricsRequest(request);
+                }
+            }
+        } catch (IOException e) {
+            log.warn("Only OpenTelemetry format is accepted", e);
+            return new FirehoseRes(firehoseReq.getRequestId(), System.currentTimeMillis(),
+                                   "Only OpenTelemetry format is accepted"

Review Comment:
   In such case I don't think you want to return an error to AWS, they will retry to send the same records later according to their spec. You need to just omit the records and return a success. 
   
   > In all error cases the Kinesis Data Firehose server reattempts delivery of the same batch of records using an exponential back-off algorithm.



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