You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/07/29 07:18:21 UTC

[GitHub] [inlong] EMsnap opened a new pull request, #5276: [INLONG-5262][Sort] Add metric report for pulsar source

EMsnap opened a new pull request, #5276:
URL: https://github.com/apache/inlong/pull/5276

   - Fixes #5262
   
   ### Motivation
   
   Add metric report for pulsar source
   
   ### Modifications
   
   Add metric report for pulsar source
   
   ### Verifying this change
   
   - [ ] This change is a trivial rework/code cleanup without any test coverage.
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (no)


-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] gong commented on a diff in pull request #5276: [INLONG-5262][Sort] Add metric report for pulsar source

Posted by GitBox <gi...@apache.org>.
gong commented on code in PR #5276:
URL: https://github.com/apache/inlong/pull/5276#discussion_r935161114


##########
inlong-sort/sort-connectors/pulsar/src/main/java/org/apache/inlong/sort/pulsar/table/DynamicPulsarDeserializationSchema.java:
##########
@@ -0,0 +1,347 @@
+/*
+ *  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.inlong.sort.pulsar.table;
+
+import static org.apache.inlong.sort.base.Constants.DELIMITER;
+import static org.apache.inlong.sort.base.Constants.NUM_BYTES_IN;
+import static org.apache.inlong.sort.base.Constants.NUM_BYTES_IN_PER_SECOND;
+import static org.apache.inlong.sort.base.Constants.NUM_RECORDS_IN;
+import static org.apache.inlong.sort.base.Constants.NUM_RECORDS_IN_PER_SECOND;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.streaming.connectors.pulsar.table.PulsarDynamicTableSource;
+import org.apache.flink.streaming.util.serialization.FlinkSchema;
+import org.apache.flink.streaming.util.serialization.PulsarDeserializationSchema;
+import org.apache.flink.streaming.util.serialization.ThreadSafeDeserializationSchema;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.types.DeserializationException;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.Preconditions;
+import org.apache.inlong.sort.base.metric.SourceMetricData;
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.Schema;
+
+/**
+ * A specific {@link PulsarDeserializationSchema} for {@link PulsarDynamicTableSource}.
+ */
+class DynamicPulsarDeserializationSchema implements PulsarDeserializationSchema<RowData> {
+
+    private static final long serialVersionUID = 1L;
+
+    @Nullable
+    private final DeserializationSchema<RowData> keyDeserialization;
+
+    private final DeserializationSchema<RowData> valueDeserialization;
+
+    private final boolean hasMetadata;
+
+    private final OutputProjectionCollector outputCollector;
+
+    private final TypeInformation<RowData> producedTypeInfo;
+
+    private final boolean upsertMode;
+
+    private SourceMetricData sourceMetricData;
+
+    private String inlongMetric;
+
+    private static final ThreadLocal<SimpleCollector<RowData>> tlsCollector =
+            new ThreadLocal<SimpleCollector<RowData>>() {
+                @Override
+                public SimpleCollector initialValue() {
+                    return new SimpleCollector();
+                }
+            };
+
+    DynamicPulsarDeserializationSchema(
+            int physicalArity,
+            @Nullable DeserializationSchema<RowData> keyDeserialization,
+            int[] keyProjection,
+            DeserializationSchema<RowData> valueDeserialization,
+            int[] valueProjection,
+            boolean hasMetadata,
+            MetadataConverter[] metadataConverters,
+            TypeInformation<RowData> producedTypeInfo,
+            boolean upsertMode,
+    String inlongMetric) {
+        if (upsertMode) {
+            Preconditions.checkArgument(
+                    keyDeserialization != null && keyProjection.length > 0,
+                    "Key must be set in upsert mode for deserialization schema.");
+        }
+        this.keyDeserialization = ThreadSafeDeserializationSchema.of(keyDeserialization);
+        this.valueDeserialization = ThreadSafeDeserializationSchema.of(valueDeserialization);
+        this.hasMetadata = hasMetadata;
+        this.outputCollector = new OutputProjectionCollector(
+                physicalArity,
+                keyProjection,
+                valueProjection,
+                metadataConverters,
+                upsertMode);
+        this.producedTypeInfo = producedTypeInfo;
+        this.upsertMode = upsertMode;
+        this.inlongMetric = inlongMetric;
+    }
+
+    @Override
+    public void open(DeserializationSchema.InitializationContext context) throws Exception {
+        if (keyDeserialization != null) {
+            keyDeserialization.open(context);
+        }
+        valueDeserialization.open(context);
+
+        sourceMetricData = new SourceMetricData(context.getMetricGroup());
+        if (inlongMetric != null && !inlongMetric.isEmpty()) {
+            String[] inLongMetricArray = inlongMetric.split(DELIMITER);
+            String groupId = inLongMetricArray[0];
+            String streamId = inLongMetricArray[1];
+            String nodeId = inLongMetricArray[2];
+            sourceMetricData.registerMetricsForNumBytesIn(groupId,
+                streamId, nodeId, NUM_BYTES_IN);
+            sourceMetricData.registerMetricsForNumBytesInPerSecond(groupId,
+                streamId, nodeId, NUM_BYTES_IN_PER_SECOND);
+            sourceMetricData.registerMetricsForNumRecordsIn(groupId, streamId,
+                nodeId, NUM_RECORDS_IN);
+            sourceMetricData.registerMetricsForNumBytesInPerSecond(groupId, streamId,
+                nodeId, NUM_RECORDS_IN_PER_SECOND);
+        }
+
+    }
+
+    @Override
+    public boolean isEndOfStream(RowData nextElement) {
+        return false;
+    }
+
+    @Override
+    public RowData deserialize(Message<RowData> message) throws IOException {
+        final SimpleCollector<RowData> collector = tlsCollector.get();
+        deserialize(message, collector);
+        return collector.takeRecord();
+    }
+
+    @Override
+    public void deserialize(Message<RowData> message, Collector<RowData> collector) throws IOException {
+        // shortcut in case no output projection is required,
+        // also not for a cartesian product with the keys
+        if (keyDeserialization == null && !hasMetadata) {
+            valueDeserialization.deserialize(message.getData(), collector);
+            return;
+        }

Review Comment:
   here need add metric computing



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #5276: [INLONG-5262][Sort] Add metric report for pulsar source

Posted by GitBox <gi...@apache.org>.
healchow commented on code in PR #5276:
URL: https://github.com/apache/inlong/pull/5276#discussion_r937442995


##########
inlong-sort/sort-connectors/pulsar/src/main/java/org/apache/inlong/sort/pulsar/table/Constants.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.inlong.sort.pulsar.table;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+
+public class Constants {
+
+    public static final ConfigOption<String> INLONG_METRIC =

Review Comment:
   Is it necessary to raise a global constant for this?



##########
inlong-sort/sort-connectors/pulsar/src/main/java/org/apache/inlong/sort/pulsar/table/PulsarDynamicTableFactory.java:
##########
@@ -284,7 +287,8 @@ public DynamicTableSource createDynamicTableSource(Context context) {
                 serviceUrl,
                 adminUrl,
                 properties,
-                startupOptions);
+                startupOptions,
+            inLongMetric);

Review Comment:
   Below is an identical variable called "inlongMetric", can this be the same as it?



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] EMsnap commented on a diff in pull request #5276: [INLONG-5262][Sort] Add metric report for Pulsar source

Posted by GitBox <gi...@apache.org>.
EMsnap commented on code in PR #5276:
URL: https://github.com/apache/inlong/pull/5276#discussion_r937453707


##########
inlong-sort/sort-connectors/pulsar/src/main/java/org/apache/inlong/sort/pulsar/table/PulsarDynamicTableFactory.java:
##########
@@ -284,7 +287,8 @@ public DynamicTableSource createDynamicTableSource(Context context) {
                 serviceUrl,
                 adminUrl,
                 properties,
-                startupOptions);
+                startupOptions,
+            inLongMetric);

Review Comment:
   I guess it's nessary to create a Constant for connectors.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] gong commented on a diff in pull request #5276: [INLONG-5262][Sort] Add metric report for pulsar source

Posted by GitBox <gi...@apache.org>.
gong commented on code in PR #5276:
URL: https://github.com/apache/inlong/pull/5276#discussion_r937333519


##########
inlong-sort/sort-connectors/pulsar/pom.xml:
##########
@@ -54,6 +54,11 @@
             <groupId>org.apache.flink</groupId>
             <artifactId>flink-avro</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.inlong</groupId>
+            <artifactId>sort-connector-base</artifactId>
+            <version>${project.version}</version>
+        </dependency>

Review Comment:
   Add `<include>org.apache.inlong:*</include>`. Because now packaging will lost class file of connector-base.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] EMsnap commented on a diff in pull request #5276: [INLONG-5262][Sort] Add metric report for Pulsar source

Posted by GitBox <gi...@apache.org>.
EMsnap commented on code in PR #5276:
URL: https://github.com/apache/inlong/pull/5276#discussion_r937453182


##########
inlong-sort/sort-connectors/pulsar/src/main/java/org/apache/inlong/sort/pulsar/table/Constants.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.inlong.sort.pulsar.table;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+
+public class Constants {
+
+    public static final ConfigOption<String> INLONG_METRIC =

Review Comment:
   sure



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] EMsnap merged pull request #5276: [INLONG-5262][Sort] Add metric report for Pulsar source

Posted by GitBox <gi...@apache.org>.
EMsnap merged PR #5276:
URL: https://github.com/apache/inlong/pull/5276


-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] gong commented on a diff in pull request #5276: [INLONG-5262][Sort] Add metric report for pulsar source

Posted by GitBox <gi...@apache.org>.
gong commented on code in PR #5276:
URL: https://github.com/apache/inlong/pull/5276#discussion_r935154064


##########
inlong-sort/sort-connectors/pulsar/src/main/java/org/apache/inlong/sort/pulsar/table/DynamicPulsarDeserializationSchema.java:
##########
@@ -0,0 +1,347 @@
+/*
+ *  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.inlong.sort.pulsar.table;
+
+import static org.apache.inlong.sort.base.Constants.DELIMITER;
+import static org.apache.inlong.sort.base.Constants.NUM_BYTES_IN;
+import static org.apache.inlong.sort.base.Constants.NUM_BYTES_IN_PER_SECOND;
+import static org.apache.inlong.sort.base.Constants.NUM_RECORDS_IN;
+import static org.apache.inlong.sort.base.Constants.NUM_RECORDS_IN_PER_SECOND;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.flink.api.common.serialization.DeserializationSchema;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.streaming.connectors.pulsar.table.PulsarDynamicTableSource;
+import org.apache.flink.streaming.util.serialization.FlinkSchema;
+import org.apache.flink.streaming.util.serialization.PulsarDeserializationSchema;
+import org.apache.flink.streaming.util.serialization.ThreadSafeDeserializationSchema;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.types.DeserializationException;
+import org.apache.flink.types.RowKind;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.Preconditions;
+import org.apache.inlong.sort.base.metric.SourceMetricData;
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.Schema;
+
+/**
+ * A specific {@link PulsarDeserializationSchema} for {@link PulsarDynamicTableSource}.
+ */
+class DynamicPulsarDeserializationSchema implements PulsarDeserializationSchema<RowData> {
+
+    private static final long serialVersionUID = 1L;
+
+    @Nullable
+    private final DeserializationSchema<RowData> keyDeserialization;
+
+    private final DeserializationSchema<RowData> valueDeserialization;
+
+    private final boolean hasMetadata;
+
+    private final OutputProjectionCollector outputCollector;
+
+    private final TypeInformation<RowData> producedTypeInfo;
+
+    private final boolean upsertMode;
+
+    private SourceMetricData sourceMetricData;
+
+    private String inlongMetric;
+
+    private static final ThreadLocal<SimpleCollector<RowData>> tlsCollector =
+            new ThreadLocal<SimpleCollector<RowData>>() {
+                @Override
+                public SimpleCollector initialValue() {
+                    return new SimpleCollector();
+                }
+            };
+
+    DynamicPulsarDeserializationSchema(
+            int physicalArity,
+            @Nullable DeserializationSchema<RowData> keyDeserialization,
+            int[] keyProjection,
+            DeserializationSchema<RowData> valueDeserialization,
+            int[] valueProjection,
+            boolean hasMetadata,
+            MetadataConverter[] metadataConverters,
+            TypeInformation<RowData> producedTypeInfo,
+            boolean upsertMode,
+    String inlongMetric) {
+        if (upsertMode) {
+            Preconditions.checkArgument(
+                    keyDeserialization != null && keyProjection.length > 0,
+                    "Key must be set in upsert mode for deserialization schema.");
+        }
+        this.keyDeserialization = ThreadSafeDeserializationSchema.of(keyDeserialization);
+        this.valueDeserialization = ThreadSafeDeserializationSchema.of(valueDeserialization);
+        this.hasMetadata = hasMetadata;
+        this.outputCollector = new OutputProjectionCollector(
+                physicalArity,
+                keyProjection,
+                valueProjection,
+                metadataConverters,
+                upsertMode);
+        this.producedTypeInfo = producedTypeInfo;
+        this.upsertMode = upsertMode;
+        this.inlongMetric = inlongMetric;
+    }
+
+    @Override
+    public void open(DeserializationSchema.InitializationContext context) throws Exception {
+        if (keyDeserialization != null) {
+            keyDeserialization.open(context);
+        }
+        valueDeserialization.open(context);
+
+        sourceMetricData = new SourceMetricData(context.getMetricGroup());
+        if (inlongMetric != null && !inlongMetric.isEmpty()) {
+            String[] inLongMetricArray = inlongMetric.split(DELIMITER);
+            String groupId = inLongMetricArray[0];
+            String streamId = inLongMetricArray[1];
+            String nodeId = inLongMetricArray[2];
+            sourceMetricData.registerMetricsForNumBytesIn(groupId,
+                streamId, nodeId, NUM_BYTES_IN);
+            sourceMetricData.registerMetricsForNumBytesInPerSecond(groupId,
+                streamId, nodeId, NUM_BYTES_IN_PER_SECOND);
+            sourceMetricData.registerMetricsForNumRecordsIn(groupId, streamId,
+                nodeId, NUM_RECORDS_IN);
+            sourceMetricData.registerMetricsForNumBytesInPerSecond(groupId, streamId,
+                nodeId, NUM_RECORDS_IN_PER_SECOND);

Review Comment:
   modify `registerMetricsForNumBytesInPerSecond` to `registerMetricsForNumRecordsInPerSecond`



-- 
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: commits-unsubscribe@inlong.apache.org

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