You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by pn...@apache.org on 2023/12/11 13:19:11 UTC

(flink) 03/06: [FLINK-33696][metrics] Add Slf4jTraceReporter

This is an automated email from the ASF dual-hosted git repository.

pnowojski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 7db2ecad165009312dfbd35c15f42b61d98ad2fe
Author: Piotr Nowojski <pi...@gmail.com>
AuthorDate: Wed Dec 6 16:22:10 2023 +0100

    [FLINK-33696][metrics] Add Slf4jTraceReporter
---
 .../flink/traces/slf4j/Slf4jTraceReporter.java     | 45 ++++++++++++++++++++++
 .../traces/slf4j/Slf4jTraceReporterFactory.java    | 32 +++++++++++++++
 ...ache.flink.traces.reporter.TraceReporterFactory | 16 ++++++++
 3 files changed, 93 insertions(+)

diff --git a/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/traces/slf4j/Slf4jTraceReporter.java b/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/traces/slf4j/Slf4jTraceReporter.java
new file mode 100644
index 00000000000..d867a58cbbd
--- /dev/null
+++ b/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/traces/slf4j/Slf4jTraceReporter.java
@@ -0,0 +1,45 @@
+/*
+ * 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.flink.traces.slf4j;
+
+import org.apache.flink.metrics.MetricConfig;
+import org.apache.flink.traces.Span;
+import org.apache.flink.traces.reporter.TraceReporter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link TraceReporter} that exports {@link org.apache.flink.traces.Span Spans} via SLF4J {@link
+ * Logger}.
+ */
+public class Slf4jTraceReporter implements TraceReporter {
+    private static final Logger LOG = LoggerFactory.getLogger(Slf4jTraceReporter.class);
+
+    @Override
+    public void notifyOfAddedSpan(Span span) {
+        LOG.info("Reported span: {}", span);
+    }
+
+    @Override
+    public void open(MetricConfig metricConfig) {}
+
+    @Override
+    public void close() {}
+}
diff --git a/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/traces/slf4j/Slf4jTraceReporterFactory.java b/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/traces/slf4j/Slf4jTraceReporterFactory.java
new file mode 100644
index 00000000000..dd2a7ddb15b
--- /dev/null
+++ b/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/traces/slf4j/Slf4jTraceReporterFactory.java
@@ -0,0 +1,32 @@
+/*
+ * 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.flink.traces.slf4j;
+
+import org.apache.flink.traces.reporter.TraceReporter;
+import org.apache.flink.traces.reporter.TraceReporterFactory;
+
+import java.util.Properties;
+
+/** {@link TraceReporterFactory} for {@link Slf4jTraceReporter}. */
+public class Slf4jTraceReporterFactory implements TraceReporterFactory {
+
+    @Override
+    public TraceReporter createTraceReporter(Properties properties) {
+        return new Slf4jTraceReporter();
+    }
+}
diff --git a/flink-metrics/flink-metrics-slf4j/src/main/resources/META-INF/services/org.apache.flink.traces.reporter.TraceReporterFactory b/flink-metrics/flink-metrics-slf4j/src/main/resources/META-INF/services/org.apache.flink.traces.reporter.TraceReporterFactory
new file mode 100644
index 00000000000..5716cdd1da3
--- /dev/null
+++ b/flink-metrics/flink-metrics-slf4j/src/main/resources/META-INF/services/org.apache.flink.traces.reporter.TraceReporterFactory
@@ -0,0 +1,16 @@
+# 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.
+
+org.apache.flink.traces.slf4j.Slf4jTraceReporterFactory