darenwkt commented on code in PR #202: URL: https://github.com/apache/flink-connector-aws/pull/202#discussion_r2134501348
########## flink-connector-aws/flink-connector-cloudwatch/src/main/java/org/apache/flink/connector/cloudwatch/sink/CloudWatchSink.java: ########## @@ -0,0 +1,172 @@ +/* + * 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.cloudwatch.sink; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.connector.base.sink.AsyncSinkBase; +import org.apache.flink.connector.base.sink.writer.BufferedRequestState; +import org.apache.flink.connector.base.sink.writer.ElementConverter; +import org.apache.flink.connector.cloudwatch.sink.client.CloudWatchAsyncClientProvider; +import org.apache.flink.connector.cloudwatch.sink.client.SdkClientProvider; +import org.apache.flink.core.io.SimpleVersionedSerializer; +import org.apache.flink.util.Preconditions; + +import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.Properties; + +/** + * A CloudWatch Sink that performs async requests against a destination CloudWatch using the + * buffering protocol specified in {@link AsyncSinkBase}. + * + * <p>The sink internally uses a {@link CloudWatchAsyncClient} to communicate with the AWS endpoint. + * + * <p>Please see the writer implementation in {@link CloudWatchSinkWriter} + * + * <p>maxBatchSize is calculated in terms of requestEntries (MetricWriteRequest). In CloudWatch, + * each PutMetricDataRequest can have maximum of 1000 MetricWriteRequest, hence the maxBatchSize + * cannot be more than 1000. + * + * <p>maxBatchSizeInBytes is calculated in terms of size of requestEntries (MetricWriteRequest). In + * CloudWatch, each PutMetricDataRequest can have maximum of 1MB of payload, hence the + * maxBatchSizeInBytes cannot be more than 1 MB. + * + * @param <InputT> Type of the elements handled by this sink + */ +@PublicEvolving +public class CloudWatchSink<InputT> extends AsyncSinkBase<InputT, MetricWriteRequest> { + + private final String namespace; + private final Properties cloudWatchClientProperties; + private transient SdkClientProvider<CloudWatchAsyncClient> asyncClientSdkClientProviderOverride; + private final InvalidMetricDataRetryMode invalidMetricDataRetryMode; + + CloudWatchSink( + ElementConverter<InputT, MetricWriteRequest> elementConverter, + Integer maxBatchSize, + Integer maxInFlightRequests, + Integer maxBufferedRequests, + Long maxBatchSizeInBytes, + Long maxTimeInBufferMS, + Long maxRecordSizeInBytes, + String namespace, + Properties cloudWatchClientProperties, + InvalidMetricDataRetryMode invalidMetricDataRetryMode) { + super( + elementConverter, + maxBatchSize, + maxInFlightRequests, + maxBufferedRequests, + maxBatchSizeInBytes, + maxTimeInBufferMS, + maxRecordSizeInBytes); + this.namespace = + Preconditions.checkNotNull( + namespace, + "The cloudWatch namespace must not be null when initializing the CloudWatch Sink."); + this.invalidMetricDataRetryMode = invalidMetricDataRetryMode; + Preconditions.checkArgument( + !this.namespace.isEmpty(), + "The cloudWatch namespace must be set when initializing the CloudWatch Sink."); + + Preconditions.checkArgument( + (this.getMaxBatchSize() <= 1000), + "The cloudWatch MaxBatchSize must not be greater than 1,000."); + + Preconditions.checkArgument( + (this.getMaxBatchSizeInBytes() <= 1000 * 1000), + "The cloudWatch MaxBatchSizeInBytes must not be greater than 1,000,000."); Review Comment: The ConfigOptions are in `AsyncSinkConnectorOptions` in `flink-connector-base`, so unfortunately we can't change them to have a cap. Hence, I think this is the next cleanest way to do it. Also, I think capping it without failure might risk misleading user to believe they managed to set a higher limit ########## flink-connector-aws/flink-sql-connector-cloudwatch/pom.xml: ########## @@ -0,0 +1,142 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flink</groupId> + <artifactId>flink-connector-aws-parent</artifactId> + <version>5.1-SNAPSHOT</version> + </parent> + + <artifactId>flink-sql-connector-cloudwatch</artifactId> + <name>Flink : Connectors : AWS : SQL : Amazon CloudWatch</name> + + <packaging>jar</packaging> + + <properties> + <japicmp.skip>true</japicmp.skip> + <aws.sdkv2.version>2.31.18</aws.sdkv2.version> Review Comment: The parent pom is `flink-connector-aws-parent` so unless we want to update this for all connectors, I think we should keep the override here ########## flink-connector-aws/flink-connector-cloudwatch/pom.xml: ########## @@ -0,0 +1,176 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flink</groupId> + <artifactId>flink-connector-aws-parent</artifactId> + <version>5.1-SNAPSHOT</version> + </parent> + + <artifactId>flink-connector-cloudwatch</artifactId> + <name>Flink : Connectors : AWS : Amazon Cloudwatch</name> + <packaging>jar</packaging> + + <properties> + <aws.sdkv2.version>2.31.18</aws.sdkv2.version> + <flink.version>1.19.0</flink.version> Review Comment: Good catch, updated -- 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