|
| 1 | +package org.apache.flink.connector.prometheus.sink.aws; |
| 2 | + |
| 3 | +import org.apache.flink.configuration.Configuration; |
| 4 | +import org.apache.flink.connector.prometheus.sink.PrometheusRequestSigner; |
| 5 | +import org.apache.flink.connector.prometheus.table.PrometheusConfig; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.BeforeEach; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.junit.jupiter.params.ParameterizedTest; |
| 10 | +import org.junit.jupiter.params.provider.Arguments; |
| 11 | +import org.junit.jupiter.params.provider.MethodSource; |
| 12 | + |
| 13 | +import java.util.stream.Stream; |
| 14 | + |
| 15 | +import static org.apache.flink.connector.prometheus.table.PrometheusConnectorOption.METRIC_REMOTE_WRITE_URL; |
| 16 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 18 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 19 | + |
| 20 | +class AmazonManagedPrometheusWriteRequestSignerFactoryTest { |
| 21 | + private AmazonManagedPrometheusWriteRequestSignerFactory factory; |
| 22 | + |
| 23 | + @BeforeEach |
| 24 | + public void setup() { |
| 25 | + factory = new AmazonManagedPrometheusWriteRequestSignerFactory(); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + void testIdentifier() { |
| 30 | + assertEquals(factory.requestSignerIdentifer(), "amazon-managed-prometheus"); |
| 31 | + } |
| 32 | + |
| 33 | + @ParameterizedTest |
| 34 | + @MethodSource("provideAMPEndpoint") |
| 35 | + void testCreateRequestSigner(final String endpoint, final String expectedRegion) { |
| 36 | + Configuration config = new Configuration(); |
| 37 | + config.set(METRIC_REMOTE_WRITE_URL, endpoint); |
| 38 | + |
| 39 | + PrometheusRequestSigner requestSigner = |
| 40 | + factory.getRequestSigner(new PrometheusConfig(config)); |
| 41 | + |
| 42 | + assertInstanceOf(AmazonManagedPrometheusWriteRequestSigner.class, requestSigner); |
| 43 | + assertEquals( |
| 44 | + ((AmazonManagedPrometheusWriteRequestSigner) requestSigner).getAwsRegion(), |
| 45 | + expectedRegion); |
| 46 | + } |
| 47 | + |
| 48 | + private static Stream<Arguments> provideAMPEndpoint() { |
| 49 | + // Extracted from https://docs.aws.amazon.com/general/latest/gr/prometheus-service.html |
| 50 | + return Stream.of( |
| 51 | + Arguments.of("https://aps.us-east-2.amazonaws.com", "us-east-2"), |
| 52 | + Arguments.of("https://aps-workspaces.us-east-2.amazonaws.com", "us-east-2"), |
| 53 | + Arguments.of("https://aps-workspaces-fips.us-east-2.amazonaws.com", "us-east-2"), |
| 54 | + Arguments.of("https://aps-workspaces-fips.us-east-2.api.aws", "us-east-2"), |
| 55 | + Arguments.of("https://aps-workspaces.us-east-2.api.aws", "us-east-2"), |
| 56 | + Arguments.of("https://aps-fips.us-east-2.amazonaws.com", "us-east-2"), |
| 57 | + Arguments.of("https://aps.us-east-2.api.aws", "us-east-2"), |
| 58 | + Arguments.of("https://aps-fips.us-east-2.api.aws", "us-east-2"), |
| 59 | + Arguments.of("https://aps.us-east-1.amazonaws.com", "us-east-1"), |
| 60 | + Arguments.of("https://aps-workspaces.us-east-1.amazonaws.com", "us-east-1"), |
| 61 | + Arguments.of("https://aps-workspaces-fips.us-east-1.amazonaws.com", "us-east-1"), |
| 62 | + Arguments.of("https://aps-workspaces-fips.us-east-1.api.aws", "us-east-1"), |
| 63 | + Arguments.of("https://aps-workspaces.us-east-1.api.aws", "us-east-1"), |
| 64 | + Arguments.of("https://aps-fips.us-east-1.amazonaws.com", "us-east-1"), |
| 65 | + Arguments.of("https://aps.us-east-1.api.aws", "us-east-1"), |
| 66 | + Arguments.of("https://aps-fips.us-east-1.api.aws", "us-east-1"), |
| 67 | + Arguments.of("https://aps.us-west-2.amazonaws.com", "us-west-2"), |
| 68 | + Arguments.of("https://aps-workspaces.us-west-2.amazonaws.com", "us-west-2"), |
| 69 | + Arguments.of("https://aps-workspaces-fips.us-west-2.amazonaws.com", "us-west-2"), |
| 70 | + Arguments.of("https://aps-workspaces-fips.us-west-2.api.aws", "us-west-2"), |
| 71 | + Arguments.of("https://aps-workspaces.us-west-2.api.aws", "us-west-2"), |
| 72 | + Arguments.of("https://aps-fips.us-west-2.amazonaws.com", "us-west-2"), |
| 73 | + Arguments.of("https://aps.us-west-2.api.aws", "us-west-2"), |
| 74 | + Arguments.of("https://aps-fips.us-west-2.api.aws", "us-west-2"), |
| 75 | + Arguments.of("https://aps.ap-south-1.amazonaws.com", "ap-south-1"), |
| 76 | + Arguments.of("https://aps-workspaces.ap-south-1.amazonaws.com", "ap-south-1"), |
| 77 | + Arguments.of("https://aps-workspaces.ap-south-1.api.aws", "ap-south-1"), |
| 78 | + Arguments.of("https://aps.ap-south-1.api.aws", "ap-south-1"), |
| 79 | + Arguments.of("https://aps.ap-northeast-2.amazonaws.com", "ap-northeast-2"), |
| 80 | + Arguments.of( |
| 81 | + "https://aps-workspaces.ap-northeast-2.amazonaws.com", "ap-northeast-2"), |
| 82 | + Arguments.of("https://aps-workspaces.ap-northeast-2.api.aws", "ap-northeast-2"), |
| 83 | + Arguments.of("https://aps.ap-northeast-2.api.aws ", "ap-northeast-2"), |
| 84 | + Arguments.of("https://aps.ap-southeast-1.amazonaws.com", "ap-southeast-1"), |
| 85 | + Arguments.of( |
| 86 | + "https://aps-workspaces.ap-southeast-1.amazonaws.com", "ap-southeast-1"), |
| 87 | + Arguments.of("https://aps-workspaces.ap-southeast-1.api.aws", "ap-southeast-1"), |
| 88 | + Arguments.of("https://aps.ap-southeast-1.api.aws", "ap-southeast-1"), |
| 89 | + Arguments.of("https://aps.ap-southeast-2.amazonaws.com", "ap-southeast-2"), |
| 90 | + Arguments.of( |
| 91 | + "https://aps-workspaces.ap-southeast-2.amazonaws.com", "ap-southeast-2"), |
| 92 | + Arguments.of("https://aps-workspaces.ap-southeast-2.api.aws", "ap-southeast-2"), |
| 93 | + Arguments.of("https://aps.ap-southeast-2.api.aws", "ap-southeast-2"), |
| 94 | + Arguments.of("https://aps.ap-northeast-1.amazonaws.com", "ap-northeast-1"), |
| 95 | + Arguments.of( |
| 96 | + "https://aps-workspaces.ap-northeast-1.amazonaws.com", "ap-northeast-1"), |
| 97 | + Arguments.of("https://aps-workspaces.ap-northeast-1.api.aws", "ap-northeast-1"), |
| 98 | + Arguments.of("https://aps.ap-northeast-1.api.aws", "ap-northeast-1"), |
| 99 | + Arguments.of("https://aps.eu-central-1.amazonaws.com", "eu-central-1"), |
| 100 | + Arguments.of("https://aps-workspaces.eu-central-1.amazonaws.com", "eu-central-1"), |
| 101 | + Arguments.of("https://aps-workspaces.eu-central-1.api.aws", "eu-central-1"), |
| 102 | + Arguments.of("https://aps.eu-central-1.api.aws", "eu-central-1"), |
| 103 | + Arguments.of("https://aps.eu-west-1.amazonaws.com", "eu-west-1"), |
| 104 | + Arguments.of("https://aps-workspaces.eu-west-1.amazonaws.com", "eu-west-1"), |
| 105 | + Arguments.of("https://aps-workspaces.eu-west-1.api.aws", "eu-west-1"), |
| 106 | + Arguments.of("https://aps.eu-west-1.api.aws", "eu-west-1"), |
| 107 | + Arguments.of("https://aps.eu-west-2.amazonaws.com", "eu-west-2"), |
| 108 | + Arguments.of("https://aps-workspaces.eu-west-2.amazonaws.com", "eu-west-2"), |
| 109 | + Arguments.of("https://aps-workspaces.eu-west-2.api.aws", "eu-west-2"), |
| 110 | + Arguments.of("https://aps.eu-west-2.api.aws", "eu-west-2"), |
| 111 | + Arguments.of("https://aps.eu-west-3.amazonaws.com", "eu-west-3"), |
| 112 | + Arguments.of("https://aps-workspaces.eu-west-3.amazonaws.com", "eu-west-3"), |
| 113 | + Arguments.of("https://aps-workspaces.eu-west-3.api.aws", "eu-west-3"), |
| 114 | + Arguments.of("https://aps.eu-west-3.api.aws", "eu-west-3"), |
| 115 | + Arguments.of("https://aps.eu-north-1.amazonaws.com", "eu-north-1"), |
| 116 | + Arguments.of("https://aps-workspaces.eu-north-1.amazonaws.com", "eu-north-1"), |
| 117 | + Arguments.of("https://aps-workspaces.eu-north-1.api.aws", "eu-north-1"), |
| 118 | + Arguments.of("https://aps.eu-north-1.api.aws", "eu-north-1"), |
| 119 | + Arguments.of("https://aps.sa-east-1.amazonaws.com", "sa-east-1"), |
| 120 | + Arguments.of("https://aps-workspaces.sa-east-1.amazonaws.com", "sa-east-1"), |
| 121 | + Arguments.of("https://aps-workspaces.sa-east-1.api.aws", "sa-east-1"), |
| 122 | + Arguments.of("https://aps.sa-east-1.api.aws", "sa-east-1")); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + void testCreateRequestSignerFailsWithInvalidRegion() { |
| 127 | + Configuration config = new Configuration(); |
| 128 | + config.set(METRIC_REMOTE_WRITE_URL, "https://invalid-endpoint"); |
| 129 | + |
| 130 | + assertThrows( |
| 131 | + IllegalArgumentException.class, |
| 132 | + () -> factory.getRequestSigner(new PrometheusConfig(config))); |
| 133 | + } |
| 134 | +} |
0 commit comments