|
46 | 46 | import java.io.ByteArrayOutputStream; |
47 | 47 | import java.io.IOException; |
48 | 48 | import java.nio.charset.StandardCharsets; |
| 49 | +import java.util.UUID; |
49 | 50 | import java.util.Base64; |
50 | 51 | import java.util.List; |
51 | 52 | import java.util.Map; |
@@ -355,6 +356,72 @@ void httpRequest_requestBodyIsTooLarge_returns413() throws InvalidProtocolBuffer |
355 | 356 | .join(); |
356 | 357 | } |
357 | 358 |
|
| 359 | + @Test |
| 360 | + void httpRequest_compressedPayloadDecompressesTooLarge_incrementsRequestsTooLargeMetric() throws Exception { |
| 361 | + configureSource(createDefaultConfigBuilder() |
| 362 | + .httpPath(CONFIG_HTTP_PATH) |
| 363 | + .compression(CompressionOption.GZIP) |
| 364 | + .maxRequestLength(ByteCount.ofBytes(250)) |
| 365 | + .build()); |
| 366 | + SOURCE.start(buffer); |
| 367 | + |
| 368 | + // ~720 bytes uncompressed, compresses well — compressed fits under maxRequestLength |
| 369 | + // but decompressed exceeds 250 bytes, triggering ContentTooLargeException |
| 370 | + String largePayload = UUID.randomUUID().toString().repeat(20); |
| 371 | + byte[] compressedPayload = createGZipCompressedPayload(largePayload); |
| 372 | + |
| 373 | + WebClient.of().execute( |
| 374 | + getDefaultRequestHeadersBuilder() |
| 375 | + .add(HttpHeaderNames.CONTENT_ENCODING, "gzip") |
| 376 | + .build(), |
| 377 | + HttpData.copyOf(compressedPayload)) |
| 378 | + .aggregate() |
| 379 | + .whenComplete((response, throwable) -> { |
| 380 | + assertThat("Http Response Throwable", throwable, is(nullValue())); |
| 381 | + assertThat("Expected 413 or 507 for too-large decompressed payload", |
| 382 | + response.status().code() == 413 || response.status().code() == 507, is(true)); |
| 383 | + }) |
| 384 | + .join(); |
| 385 | + |
| 386 | + Thread.sleep(200); |
| 387 | + |
| 388 | + List<Measurement> measurements = MetricsTestUtil.getMeasurementList( |
| 389 | + "pipeline.otel_logs.requestsTooLarge"); |
| 390 | + Measurement countMeasurement = MetricsTestUtil.getMeasurementFromList( |
| 391 | + measurements, Statistic.COUNT); |
| 392 | + assertEquals(1.0, countMeasurement.getValue()); |
| 393 | + } |
| 394 | + |
| 395 | + @Test |
| 396 | + void httpRequest_compressedPayloadWithinLimit_doesNotIncrementRequestsTooLargeMetric() throws Exception { |
| 397 | + configureSource(createDefaultConfigBuilder() |
| 398 | + .httpPath(CONFIG_HTTP_PATH) |
| 399 | + .compression(CompressionOption.GZIP) |
| 400 | + .build()); |
| 401 | + SOURCE.start(buffer); |
| 402 | + |
| 403 | + byte[] compressedPayload = createGZipCompressedPayload( |
| 404 | + JsonFormat.printer().print(createLogsServiceRequest())); |
| 405 | + |
| 406 | + WebClient.of().execute( |
| 407 | + getDefaultRequestHeadersBuilder() |
| 408 | + .add(HttpHeaderNames.CONTENT_ENCODING, "gzip") |
| 409 | + .build(), |
| 410 | + compressedPayload) |
| 411 | + .aggregate() |
| 412 | + .whenComplete((response, throwable) -> |
| 413 | + assertSecureResponseWithStatusCode(response, HttpStatus.OK, throwable)) |
| 414 | + .join(); |
| 415 | + |
| 416 | + Thread.sleep(200); |
| 417 | + |
| 418 | + List<Measurement> measurements = MetricsTestUtil.getMeasurementList( |
| 419 | + "pipeline.otel_logs.requestsTooLarge"); |
| 420 | + Measurement countMeasurement = MetricsTestUtil.getMeasurementFromList( |
| 421 | + measurements, Statistic.COUNT); |
| 422 | + assertEquals(0.0, countMeasurement.getValue()); |
| 423 | + } |
| 424 | + |
358 | 425 | static class BufferExceptionToStatusArgumentsProvider implements ArgumentsProvider { |
359 | 426 | @Override |
360 | 427 | public Stream<? extends Arguments> provideArguments(final ExtensionContext context) { |
@@ -389,7 +456,7 @@ private ExportLogsServiceRequest createExportLogsRequest() { |
389 | 456 | private void assertSecureResponseWithStatusCode(final AggregatedHttpResponse response, |
390 | 457 | final HttpStatus expectedStatus, |
391 | 458 | final Throwable throwable) { |
392 | | - assertThat("Http Status", response.status(), equalTo(expectedStatus)); |
| 459 | + assertThat("Http Status", response.status(), equalTo(expectedStatus)); |
393 | 460 | assertThat("Http Response Throwable", throwable, is(nullValue())); |
394 | 461 |
|
395 | 462 | final List<String> headerKeys = response.headers() |
|
0 commit comments