diff --git a/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/DynatraceMeterRegistry.java b/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/DynatraceMeterRegistry.java index 2d291ef5a..d808a2ace 100644 --- a/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/DynatraceMeterRegistry.java +++ b/implementations/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/DynatraceMeterRegistry.java @@ -283,6 +283,7 @@ private List createPostMessageBodies(List 0) { payload.append(','); + totalByteCount++; } payload.append(json); totalByteCount += jsonByteCount; diff --git a/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceMeterRegistryTest.java b/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceMeterRegistryTest.java index 3c5c14b58..84dafaabb 100644 --- a/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceMeterRegistryTest.java +++ b/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceMeterRegistryTest.java @@ -204,9 +204,9 @@ void splitsWhenExactlyExceedingMaxByComma() { List messages = meterRegistry.createPostMessages("my.type", // Max bytes: 15330 (excluding header/footer, 15360 with header/footer) Arrays.asList(createTimeSeriesWithDimensions(750), // 14861 bytes - createTimeSeriesWithDimensions(23, "asdfg"), // 469 bytes + createTimeSeriesWithDimensions(23, "asdfg"), // 469 bytes (overflows due to comma) createTimeSeriesWithDimensions(750), // 14861 bytes - createTimeSeriesWithDimensions(23, "asdf") // 468 bytes + createTimeSeriesWithDimensions(23, "asdf") // 468 bytes + comma )); assertThat(messages).hasSize(3); assertThat(messages.get(0).metricCount).isEqualTo(1); @@ -216,6 +216,20 @@ void splitsWhenExactlyExceedingMaxByComma() { assertThat(messages.stream().map(message -> message.payload).allMatch(DynatraceMeterRegistryTest::isJSONValid)).isTrue(); } + @Test + void countsPreviousAndNextComma() { + List messages = meterRegistry.createPostMessages("my.type", + // Max bytes: 15330 (excluding header/footer, 15360 with header/footer) + Arrays.asList(createTimeSeriesWithDimensions(750), // 14861 bytes + createTimeSeriesWithDimensions(10, "asdf"), // 234 bytes + comma + createTimeSeriesWithDimensions(10, "asdf") // 234 bytes + comma = 15331 bytes (overflow) + )); + assertThat(messages).hasSize(2); + assertThat(messages.get(0).metricCount).isEqualTo(2); + assertThat(messages.get(1).metricCount).isEqualTo(1); + assertThat(messages.stream().map(message -> message.payload).allMatch(DynatraceMeterRegistryTest::isJSONValid)).isTrue(); + } + private DynatraceTimeSeries createTimeSeriesWithDimensions(int numberOfDimensions) { return createTimeSeriesWithDimensions(numberOfDimensions, "some.metric"); }