sonatype-lift[bot] commented on code in PR #9817:
URL: https://github.com/apache/skywalking/pull/9817#discussion_r1000234391


##########
oap-server/exporter/src/main/java/org/apache/skywalking/oap/server/exporter/provider/kafka/log/KafkaLogExporter.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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.exporter.provider.kafka.log;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+import java.util.List;
+import java.util.Properties;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.skywalking.apm.network.logging.v3.JSONLog;
+import org.apache.skywalking.apm.network.logging.v3.LogData;
+import org.apache.skywalking.apm.network.logging.v3.LogDataBody;
+import org.apache.skywalking.apm.network.logging.v3.LogTags;
+import org.apache.skywalking.apm.network.logging.v3.TextLog;
+import org.apache.skywalking.apm.network.logging.v3.TraceContext;
+import org.apache.skywalking.apm.network.logging.v3.YAMLLog;
+import org.apache.skywalking.oap.server.core.UnexpectedException;
+import org.apache.skywalking.oap.server.core.analysis.IDManager;
+import org.apache.skywalking.oap.server.core.analysis.manual.log.LogRecord;
+import org.apache.skywalking.oap.server.core.exporter.LogExportService;
+import org.apache.skywalking.oap.server.core.query.type.ContentType;
+import org.apache.skywalking.oap.server.exporter.provider.ExporterSetting;
+import 
org.apache.skywalking.oap.server.exporter.provider.kafka.KafkaExportProducer;
+import org.apache.skywalking.oap.server.library.datacarrier.DataCarrier;
+import 
org.apache.skywalking.oap.server.library.datacarrier.buffer.BufferStrategy;
+import org.apache.skywalking.oap.server.library.datacarrier.consumer.IConsumer;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.util.StringUtil;
+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.MetricsCreator;
+import org.apache.skywalking.oap.server.telemetry.api.MetricsTag;
+
+@Slf4j
+public class KafkaLogExporter extends KafkaExportProducer implements 
LogExportService, IConsumer<LogRecord> {
+    private DataCarrier<LogRecord> exportBuffer;
+    private CounterMetrics successCounter;
+    private CounterMetrics errorCounter;
+    private final ModuleManager moduleManager;
+
+    public KafkaLogExporter(ModuleManager manager, ExporterSetting setting) {
+        super(setting);
+        this.moduleManager = manager;
+    }
+
+    @Override
+    public void start() {
+        super.getProducer();
+        exportBuffer = new DataCarrier<>(
+            "KafkaLogExporter", "KafkaLogExporter", 
setting.getBufferChannelNum(), setting.getBufferChannelSize(),
+            BufferStrategy.IF_POSSIBLE
+        );
+        exportBuffer.consume(this, 1, 200);
+        MetricsCreator metricsCreator = 
moduleManager.find(TelemetryModule.NAME)
+                                                     .provider()
+                                                     
.getService(MetricsCreator.class);
+        successCounter = metricsCreator.createCounter(
+            "kafka_exporter_log_success_count", "The success number of log 
exported by kafka exporter.",
+            new MetricsTag.Keys("protocol"),
+            new MetricsTag.Values("kafka")
+        );
+        errorCounter = metricsCreator.createCounter(
+            "kafka_exporter_log_error_count", "The error number of log 
exported by kafka exporter",
+            new MetricsTag.Keys("protocol"), new MetricsTag.Values("kafka")
+        );
+    }
+
+    @Override
+    public void export(final LogRecord logRecord) {
+        if (logRecord != null) {
+            exportBuffer.produce(logRecord);
+        }
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return setting.isEnableKafkaLog();
+    }
+
+    @Override
+    public void init(final Properties properties) {
+
+    }
+
+    @Override
+    public void consume(final List<LogRecord> data) {
+        for (LogRecord logRecord : data) {
+            if (logRecord != null) {
+                try {
+                    LogData logData = transLogData(logRecord);
+                    ProducerRecord<String, Bytes> record = new 
ProducerRecord<>(
+                        setting.getKafkaTopicLog(),
+                        logRecord.id(),
+                        Bytes.wrap(logData.toByteArray())
+                    );
+                    super.getProducer().send(record, (metadata, ex) -> {

Review Comment:
   
*[FutureReturnValueIgnored](https://errorprone.info/bugpattern/FutureReturnValueIgnored):*
  Return value of methods returning Future must be checked. Ignoring returned 
Futures suppresses exceptions thrown from the code that completes the Future.
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=346683672&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=346683672&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=346683672&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=346683672&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=346683672&lift_comment_rating=5)
 ]



##########
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/exporter/TraceExportService.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.core.exporter;
+
+import 
org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
+import org.apache.skywalking.oap.server.library.module.Service;
+
+/**
+ * Export the traces from metrics through this service.
+ */
+public interface TraceExportService extends Service, 
ExporterService<SegmentRecord> {
+
+    void export(SegmentRecord segmentRecord);

Review Comment:
   *[MissingOverride](https://errorprone.info/bugpattern/MissingOverride):*  
export implements method in ExporterService; expected @Override
   
   ---
   
   
   ```suggestion
       @Override void export(SegmentRecord segmentRecord);
   ```
   
   
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=346683555&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=346683555&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=346683555&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=346683555&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=346683555&lift_comment_rating=5)
 ]



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to