Skip to content

[FLINK-37688] Implement Amazon CloudWatch Metric Sink Connector #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

darenwkt
Copy link
Contributor

@darenwkt darenwkt commented Apr 21, 2025

Purpose of the change

Implement Amazon CloudWatch Metric Sink Connector based on FLIP-524 (https://cwiki.apache.org/confluence/display/FLINK/FLIP-524:+CloudWatch+Metric+Sink+Connector) which includes following:

  • DataStream and TableAPI support
  • Integration Test with LocalStack container

Verifying this change

This change added tests and can be verified as follows:

Unit Test

  • Added unit tests

IT Test - Added integration tests for end-to-end deployment

  • Ran IT test locally
mvn clean verify -Prun-end-to-end-tests -DdistDir=/Users/darenwkt/Downloads/flink-1.19.2
  • Verified test pass for DataStream and TableAPI
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 71.197 s - in org.apache.flink.connector.cloudwatch.table.test.CloudWatchTableAPIITCase
[INFO] Running org.apache.flink.connector.cloudwatch.sink.test.CloudWatchSinkITCase
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 34.422 s - in org.apache.flink.connector.cloudwatch.sink.test.CloudWatchSinkITCase
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

DataStream API Manual Test - Manually verified by running the CloudWatch connector on a local Flink cluster.

  • Create Flink job code
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        final Map<String, Properties> applicationParameters = loadApplicationProperties(env);

        env.fromSource(createDataGeneratorSource(applicationParameters.get("DataGen")), WatermarkStrategy.noWatermarks(), "DataGen")
                .uid("data-gen")
                .setParallelism(1)
                .disableChaining()
                .sinkTo(CloudWatchSink.<TemperatureSample>builder()
                        .setNamespace("CloudWatchSinkTest")
                        .setCloudWatchClientProperties(applicationParameters.get("CloudWatchSink"))
                        .setElementConverter(new MetricWriteRequestElementConverter<>() {
                            @Override
                            public MetricWriteRequest apply(TemperatureSample value, SinkWriter.Context context) {
                                return MetricWriteRequest.builder()
                                        .withMetricName("temperature")
                                        .addDimension("roomId", "testRoomId")
                                        .addDimension("sensorId", "testSensorId")
                                        .addValue(value.getTemperature())
                                        .addCount(1d)
                                        .withTimestamp(Instant.ofEpochMilli(value.getTimestamp()))
                                        .build();
                            }
                        })
                        .build())
                .uid("cloudwatch-sink").name("CloudWatchSink");

        env.enableCheckpointing(5000);

        env.execute("CloudWatch sink example");
  • Build jar and submitted job
./bin/flink run cloudwatch-connector-example-1.0.jar
Job has been submitted with JobID f417eccc9d9204604ec51eeed24196e0
  • Verified job is running and checkpointing successfully
    Screenshot 2025-04-21 at 21 29 12

  • Verified CloudWatch received the metric successfully
    Screenshot 2025-04-21 at 21 31 09

TableAPI Manual Test - Manually verified by running the CloudWatch connector on a local Flink cluster.

  • Built SQL jar and started sql-client with it
./bin/sql-client.sh --jar flink-sql-connector-cloudwatch-5.1-SNAPSHOT.jar
  • Created Sink Table
Flink SQL>
> CREATE TABLE CloudWatchTable
> (
>     `my_metric_name`   STRING,
>     `my_dim` STRING,
>     `sample_value` DOUBLE,
>     `sample_count` DOUBLE,
>     `unit`             STRING,
>     `storage_res`      INT,
>     `stats_max` DOUBLE,
>     `stats_min` DOUBLE,
>     `stats_sum` DOUBLE,
>     `stats_count` DOUBLE
> )
>     WITH (
>         'connector' = 'cloudwatch',
>         'aws.region' = 'us-east-1',
>         'metric.namespace' = 'cw_connector_namespace',
>         'metric.name.key' = 'my_metric_name',
>         'metric.dimension.keys' = 'my_dim',
>         'metric.value.key' = 'sample_value',
>         'metric.count.key' = 'sample_count',
>         'metric.unit.key' = 'unit',
>         'metric.storage-resolution.key' = 'storage_res',
>         'metric.statistic.max.key' = 'stats_max',
>         'metric.statistic.min.key' = 'stats_min',
>         'metric.statistic.sum.key' = 'stats_sum',
>         'metric.statistic.sample-count.key' = 'stats_count',
>         'sink.invalid-metric.retry-mode' = 'RETRY'
>         );
[INFO] Execute statement succeed.
  • Inserted sample value into table
Flink SQL> INSERT INTO CloudWatchTable VALUES ('test_metric', 'dim_1', 123, 1, 'Seconds', 60, 999, 1, 10, 1
1);
[INFO] Submitting SQL update statement to the cluster...
[INFO] SQL update statement has been successfully submitted to the cluster:
Job ID: 90d19a75e7326575b4ea3f4d883091a7
  • Verified job entered FINISHED state successfully
    Screenshot 2025-04-21 at 21 09 59

  • Verified Cloudwatch received the metric successfully
    Screenshot 2025-04-21 at 21 10 25

Significant changes

(Please check any boxes [x] if the answer is "yes". You can first publish the PR and check them afterwards, for convenience.)

  • Dependencies have been added or upgraded
  • Public API has been changed (Public API is any class annotated with @Public(Evolving))
  • Serializers have been changed
  • New feature has been introduced
    • If yes, how is this documented? (JavaDocs)

@darenwkt darenwkt force-pushed the cloudwatch branch 3 times, most recently from aa7efc3 to 2d0309c Compare April 24, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant