nicusX commented on code in PR #22:
URL: 
https://github.com/apache/flink-connector-prometheus/pull/22#discussion_r2111971912


##########
flink-connector-prometheus-request-signer-amp/src/main/java/org/apache/flink/connector/prometheus/sink/aws/AmazonManagedPrometheusWriteRequestSignerFactory.java:
##########
@@ -0,0 +1,36 @@
+package org.apache.flink.connector.prometheus.sink.aws;
+
+import org.apache.flink.connector.prometheus.sink.PrometheusRequestSigner;
+import org.apache.flink.connector.prometheus.table.PrometheusConfig;
+import 
org.apache.flink.connector.prometheus.table.PrometheusDynamicRequestSignerFactory;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class AmazonManagedPrometheusWriteRequestSignerFactory

Review Comment:
   I'd be interested to see how this is used to set up the request signer 
declaratively in SQL



##########
flink-connector-prometheus/src/main/java/org/apache/flink/connector/prometheus/table/RowDataToPrometheusTimeSeriesConverter.java:
##########
@@ -0,0 +1,116 @@
+/*
+ *  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.connector.prometheus.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.prometheus.sink.PrometheusTimeSeries;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.DataType;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/**
+ * Converts from Flink Table API internal type of {@link RowData} to {@link 
PrometheusTimeSeries}.
+ */
+@Internal
+public class RowDataToPrometheusTimeSeriesConverter {
+
+    private final DataType physicalDataType;
+    private final PrometheusConfig prometheusConfig;
+
+    public RowDataToPrometheusTimeSeriesConverter(
+            DataType physicalDataType, PrometheusConfig prometheusConfig) {
+        this.physicalDataType = physicalDataType;
+        this.prometheusConfig = prometheusConfig;
+    }
+
+    public PrometheusTimeSeries convertRowData(RowData row) {
+        List<DataTypes.Field> fields = DataType.getFields(physicalDataType);
+
+        PrometheusTimeSeries.Builder builder = PrometheusTimeSeries.builder();
+        Double sampleValue = null;
+        Long sampleTimestamp = null;
+
+        for (int i = 0; i < fields.size(); i++) {
+            DataTypes.Field field = fields.get(i);
+            RowData.FieldGetter fieldGetter =
+                    
createFieldGetter(fields.get(i).getDataType().getLogicalType(), i);
+            FieldValue fieldValue = new 
FieldValue(fieldGetter.getFieldOrNull(row));
+            String fieldName = field.getName();
+
+            if (fieldName.equals(prometheusConfig.getMetricName())) {
+                builder.withMetricName(fieldValue.getStringValue());
+            } else if 
(fieldName.equals(prometheusConfig.getMetricSampleKey())) {
+                sampleValue = fieldValue.getDoubleValue();
+            } else if (prometheusConfig.getLabelKeys().contains(fieldName)) {

Review Comment:
   LGTM
   Just thinking out loud: the Label name is the field name and the value is 
the content.
   No issue as label names must follow `[a-zA-Z_]([a-zA-Z0-9_])*` which is a 
subset of possible column names.
   This limits the usage a bit compared to DataStream because all metrics 
represented by a table must have the same set of Label names. 
   But I do not think anything different is possible with a table abstraction



##########
flink-connector-prometheus/src/main/java/org/apache/flink/connector/prometheus/table/RowDataToPrometheusTimeSeriesConverter.java:
##########
@@ -0,0 +1,116 @@
+/*
+ *  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.connector.prometheus.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.prometheus.sink.PrometheusTimeSeries;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.DataType;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/**
+ * Converts from Flink Table API internal type of {@link RowData} to {@link 
PrometheusTimeSeries}.
+ */
+@Internal
+public class RowDataToPrometheusTimeSeriesConverter {
+
+    private final DataType physicalDataType;
+    private final PrometheusConfig prometheusConfig;
+
+    public RowDataToPrometheusTimeSeriesConverter(
+            DataType physicalDataType, PrometheusConfig prometheusConfig) {
+        this.physicalDataType = physicalDataType;
+        this.prometheusConfig = prometheusConfig;
+    }
+
+    public PrometheusTimeSeries convertRowData(RowData row) {
+        List<DataTypes.Field> fields = DataType.getFields(physicalDataType);
+
+        PrometheusTimeSeries.Builder builder = PrometheusTimeSeries.builder();
+        Double sampleValue = null;
+        Long sampleTimestamp = null;
+
+        for (int i = 0; i < fields.size(); i++) {
+            DataTypes.Field field = fields.get(i);
+            RowData.FieldGetter fieldGetter =
+                    
createFieldGetter(fields.get(i).getDataType().getLogicalType(), i);
+            FieldValue fieldValue = new 
FieldValue(fieldGetter.getFieldOrNull(row));
+            String fieldName = field.getName();
+
+            if (fieldName.equals(prometheusConfig.getMetricName())) {
+                builder.withMetricName(fieldValue.getStringValue());
+            } else if 
(fieldName.equals(prometheusConfig.getMetricSampleKey())) {
+                sampleValue = fieldValue.getDoubleValue();
+            } else if (prometheusConfig.getLabelKeys().contains(fieldName)) {
+                builder.addLabel(fieldName, fieldValue.getStringValue());
+            } else if 
(fieldName.equals(prometheusConfig.getMetricSampleTimestamp())) {
+                sampleTimestamp = fieldValue.getLongValue();
+            } else {
+                throw new IllegalArgumentException(

Review Comment:
   It would be really nice to move this validation to the builder or the sink 
constructor. This would cause the job to fail when created, instead of failing 
when the first record is processed (putting the job in a fail-and-restart loop).
   A more user friendly behaviour considering this is a misconfiguration rather 
than a runtime problem.



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to