|
76 | 76 | import static org.hamcrest.CoreMatchers.equalTo; |
77 | 77 | import static org.hamcrest.CoreMatchers.hasItem; |
78 | 78 | import static org.hamcrest.MatcherAssert.assertThat; |
| 79 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
79 | 80 |
|
80 | 81 | import java.net.URLEncoder; |
81 | 82 | import java.nio.charset.StandardCharsets; |
@@ -119,6 +120,8 @@ public class PrometheusSinkAMPIT { |
119 | 120 | @Mock |
120 | 121 | private AwsCredentialsSupplier awsCredentialsSupplier; |
121 | 122 | @Mock |
| 123 | + private AwsCredentialsSupplier awsQueryCredentialsSupplier; |
| 124 | + @Mock |
122 | 125 | private Counter metricsSuccessCounter; |
123 | 126 | @Mock |
124 | 127 | private Counter metricsFailedCounter; |
@@ -161,6 +164,8 @@ void setUp() { |
161 | 164 |
|
162 | 165 | .build(); |
163 | 166 |
|
| 167 | + awsCredentialsSupplier = mock(AwsCredentialsSupplier.class); |
| 168 | + awsQueryCredentialsSupplier = mock(AwsCredentialsSupplier.class); |
164 | 169 | eventHandle = mock(EventHandle.class); |
165 | 170 | pipelineDescription = mock(PipelineDescription.class); |
166 | 171 | awsCredentialsProvider = DefaultCredentialsProvider.create(); |
@@ -204,6 +209,7 @@ void setUp() { |
204 | 209 | String remoteWriteUrl = url + "api/v1/remote_write"; |
205 | 210 | queryUrl = url + "api/v1/query"; |
206 | 211 | when(awsCredentialsSupplier.getProvider(any())).thenAnswer(options -> DefaultCredentialsProvider.create()); |
| 212 | + lenient().when(awsQueryCredentialsSupplier.getProvider(any())).thenAnswer(options -> DefaultCredentialsProvider.create()); |
207 | 213 | thresholdConfig = mock(PrometheusSinkThresholdConfig.class); |
208 | 214 | when(thresholdConfig.getMaxEvents()).thenReturn(NUM_RECORDS); |
209 | 215 | when(thresholdConfig.getMaxRequestSizeBytes()).thenReturn(100000L); |
@@ -254,7 +260,7 @@ private void getMetricsFromAMP(final String metricName, final String qs) throws |
254 | 260 | String encodedQuery = URLEncoder.encode(query, StandardCharsets.UTF_8); |
255 | 261 | String getUrlQuery = "query=" + query + "&start="+testStartTime+"&end="+endTime+"&step=1s"; |
256 | 262 | String getUrl = queryRangeUrl+"?query=" + encodedQuery + "&start="+testStartTime+"&end="+endTime+"&step=1s"; |
257 | | - PrometheusSigV4Signer signer = new PrometheusSigV4Signer(awsCredentialsSupplier, prometheusSinkConfig, baseUrl + queryRangeUrl); |
| 263 | + PrometheusSigV4Signer signer = new PrometheusSigV4Signer(awsQueryCredentialsSupplier, prometheusSinkConfig, baseUrl + queryRangeUrl); |
258 | 264 | final SdkHttpFullRequest signedRequest = signer.signQueryRequest(getUrlQuery); |
259 | 265 |
|
260 | 266 | final RequestHeadersBuilder headersBuilder = RequestHeaders.builder() |
@@ -911,4 +917,25 @@ private Collection<Record<Event>> getExponentialHistogramRecordList(int numberOf |
911 | 917 | return records; |
912 | 918 | } |
913 | 919 |
|
| 920 | + @Test |
| 921 | + void testToVerifyLackOfCredentialsResultInFailure() throws Exception { |
| 922 | + |
| 923 | + AwsCredentialsProvider provider = mock(AwsCredentialsProvider.class); |
| 924 | + when(awsCredentialsSupplier.getProvider(any())).thenReturn(provider); |
| 925 | + lenient().when(thresholdConfig.getFlushInterval()).thenReturn(1L); |
| 926 | + when(thresholdConfig.getMaxEvents()).thenReturn(1); |
| 927 | + PrometheusSink sink = createObjectUnderTest(); |
| 928 | + Collection<Record<Event>> records = getHistogramRecordList(NUM_RECORDS); |
| 929 | + sink.doOutput(records); |
| 930 | + |
| 931 | + long startTimeSeconds = testStartTime.getEpochSecond(); |
| 932 | + assertThrows( org.awaitility.core.ConditionTimeoutException.class, () -> await().atMost(Duration.ofSeconds(2)) |
| 933 | + .untilAsserted(() -> { |
| 934 | + metricsInAMP = 0; |
| 935 | + getMetricsFromAMP(histogramMetricName, "histogram"); |
| 936 | + assertThat(metricsInAMP, greaterThanOrEqualTo(1)); |
| 937 | + })); |
| 938 | + |
| 939 | + verify(metricsSuccessCounter, times(0)).increment(NUM_RECORDS); |
| 940 | + } |
914 | 941 | } |
0 commit comments