mirror of
https://github.com/floci-io/floci.git
synced 2026-12-02 17:58:05 -05:00
fix(cloudwatch): return storedBytes on DescribeLogGroups (#4202)
* fix(cloudwatch): return storedBytes on DescribeLogGroups AWS reports log-group storedBytes as the sum of stream sizes. Floci always returned 0, which breaks SDK clients that read the field. * style(cloudwatch): import collection test helpers
This commit is contained in:
1 parent
35605937c8
commit
babb43ac3d
5 files changed
+119
-29
No files matched your search
+45
-21
@@ -7,11 +7,15 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.cloudwatch.logs.model.LogStream;
|
||||
import io.github.hectorvent.floci.services.cloudwatch.metrics.CloudWatchMetricsService;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
@@ -88,9 +92,9 @@ class CloudWatchLogsHandlerTest {
|
||||
void describeLogStreamsHonorsOrderByDescendingLimitAndReturnsNextToken() {
|
||||
service.createLogStream(GROUP, "another-stream", REGION);
|
||||
service.putLogEvents(GROUP, STREAM,
|
||||
java.util.List.of(java.util.Map.of("timestamp", 2000L, "message", "new")), REGION);
|
||||
List.of(Map.of("timestamp", 2000L, "message", "new")), REGION);
|
||||
service.putLogEvents(GROUP, "another-stream",
|
||||
java.util.List.of(java.util.Map.of("timestamp", 1000L, "message", "old")), REGION);
|
||||
List.of(Map.of("timestamp", 1000L, "message", "old")), REGION);
|
||||
ObjectNode request = MAPPER.createObjectNode()
|
||||
.put("logGroupName", GROUP)
|
||||
.put("orderBy", "LastEventTime")
|
||||
@@ -126,6 +130,26 @@ class CloudWatchLogsHandlerTest {
|
||||
assertFalse(group.has("createdTime"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeLogGroupsReturnsStoredBytesSummedAcrossStreams() {
|
||||
service.createLogStream(GROUP, "second-stream", REGION);
|
||||
service.putLogEvents(GROUP, STREAM,
|
||||
List.of(Map.of("timestamp", 1L, "message", "alpha")), REGION);
|
||||
service.putLogEvents(GROUP, "second-stream",
|
||||
List.of(Map.of("timestamp", 2L, "message", "beta")), REGION);
|
||||
|
||||
long expected = service.describeLogStreams(GROUP, null, REGION).stream()
|
||||
.mapToLong(LogStream::getStoredBytes)
|
||||
.sum();
|
||||
|
||||
JsonNode group = ((JsonNode) handler.handle("DescribeLogGroups",
|
||||
MAPPER.createObjectNode().put("logGroupNamePrefix", GROUP), REGION).getEntity())
|
||||
.path("logGroups").get(0);
|
||||
|
||||
assertTrue(expected > 0);
|
||||
assertEquals(expected, group.path("storedBytes").asLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeLogStreamsReturnsCreationTimeNotCreatedTime() {
|
||||
ObjectNode request = MAPPER.createObjectNode().put("logGroupName", GROUP);
|
||||
@@ -355,7 +379,7 @@ class CloudWatchLogsHandlerTest {
|
||||
void getLogEventsByLogGroupIdentifierArnAndLogStreamArn() {
|
||||
long now = System.currentTimeMillis();
|
||||
service.putLogEvents(GROUP, STREAM,
|
||||
java.util.List.of(java.util.Map.of("timestamp", now, "message", "via arn")),
|
||||
List.of(Map.of("timestamp", now, "message", "via arn")),
|
||||
REGION);
|
||||
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
@@ -375,9 +399,9 @@ class CloudWatchLogsHandlerTest {
|
||||
@Test
|
||||
void filterLogEventsByLogGroupIdentifierArnAndStreamArns() {
|
||||
long now = System.currentTimeMillis();
|
||||
service.putLogEvents(GROUP, STREAM, java.util.List.of(
|
||||
java.util.Map.of("timestamp", now, "message", "ERROR: kaboom"),
|
||||
java.util.Map.of("timestamp", now + 1, "message", "INFO: fine")
|
||||
service.putLogEvents(GROUP, STREAM, List.of(
|
||||
Map.of("timestamp", now, "message", "ERROR: kaboom"),
|
||||
Map.of("timestamp", now + 1, "message", "INFO: fine")
|
||||
), REGION);
|
||||
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
@@ -403,11 +427,11 @@ class CloudWatchLogsHandlerTest {
|
||||
service.createLogStream(GROUP, otherStream, REGION);
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
service.putLogEvents(GROUP, STREAM, java.util.List.of(
|
||||
java.util.Map.of("timestamp", now, "message", "ERROR: from first")
|
||||
service.putLogEvents(GROUP, STREAM, List.of(
|
||||
Map.of("timestamp", now, "message", "ERROR: from first")
|
||||
), REGION);
|
||||
service.putLogEvents(GROUP, otherStream, java.util.List.of(
|
||||
java.util.Map.of("timestamp", now + 1, "message", "ERROR: from second")
|
||||
service.putLogEvents(GROUP, otherStream, List.of(
|
||||
Map.of("timestamp", now + 1, "message", "ERROR: from second")
|
||||
), REGION);
|
||||
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
@@ -428,8 +452,8 @@ class CloudWatchLogsHandlerTest {
|
||||
// OutputLogEvent has no logStreamName in real AWS: the caller named the stream in the
|
||||
// request, so echoing it back would be a shape floci invents.
|
||||
long now = System.currentTimeMillis();
|
||||
service.putLogEvents(GROUP, STREAM, java.util.List.of(
|
||||
java.util.Map.of("timestamp", now, "message", "only one stream here")
|
||||
service.putLogEvents(GROUP, STREAM, List.of(
|
||||
Map.of("timestamp", now, "message", "only one stream here")
|
||||
), REGION);
|
||||
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
@@ -447,9 +471,9 @@ class CloudWatchLogsHandlerTest {
|
||||
@Test
|
||||
void filterLogEventsByLogGroupIdentifierArnWithoutStreamFilter() {
|
||||
long now = System.currentTimeMillis();
|
||||
service.putLogEvents(GROUP, STREAM, java.util.List.of(
|
||||
java.util.Map.of("timestamp", now, "message", "a"),
|
||||
java.util.Map.of("timestamp", now + 1, "message", "b")
|
||||
service.putLogEvents(GROUP, STREAM, List.of(
|
||||
Map.of("timestamp", now, "message", "a"),
|
||||
Map.of("timestamp", now + 1, "message", "b")
|
||||
), REGION);
|
||||
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
@@ -467,12 +491,12 @@ class CloudWatchLogsHandlerTest {
|
||||
// response, goes out on the next request, and the second page carries the matches the
|
||||
// first one capped off.
|
||||
long now = System.currentTimeMillis();
|
||||
service.putLogEvents(GROUP, STREAM, java.util.List.of(
|
||||
java.util.Map.of("timestamp", now, "message", "msg-0"),
|
||||
java.util.Map.of("timestamp", now + 1, "message", "msg-1"),
|
||||
java.util.Map.of("timestamp", now + 2, "message", "msg-2"),
|
||||
java.util.Map.of("timestamp", now + 3, "message", "msg-3"),
|
||||
java.util.Map.of("timestamp", now + 4, "message", "msg-4")
|
||||
service.putLogEvents(GROUP, STREAM, List.of(
|
||||
Map.of("timestamp", now, "message", "msg-0"),
|
||||
Map.of("timestamp", now + 1, "message", "msg-1"),
|
||||
Map.of("timestamp", now + 2, "message", "msg-2"),
|
||||
Map.of("timestamp", now + 3, "message", "msg-3"),
|
||||
Map.of("timestamp", now + 4, "message", "msg-4")
|
||||
), REGION);
|
||||
|
||||
ObjectNode firstRequest = MAPPER.createObjectNode();
|
||||
|
||||
+24
@@ -802,6 +802,30 @@ class CloudWatchLogsServiceTest {
|
||||
assertEquals(2, result.events().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getStoredBytesForLogGroupSumsStreamBytesAndIgnoresOtherGroups() {
|
||||
service.createLogGroup("/app/logs", null, null, REGION);
|
||||
service.createLogStream("/app/logs", "stream-1", REGION);
|
||||
service.createLogStream("/app/logs", "stream-2", REGION);
|
||||
service.createLogGroup("/app/other", null, null, REGION);
|
||||
service.createLogStream("/app/other", "stream-1", REGION);
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
service.putLogEvents("/app/logs", "stream-1",
|
||||
List.of(Map.of("timestamp", now, "message", "one")), REGION);
|
||||
service.putLogEvents("/app/logs", "stream-2",
|
||||
List.of(Map.of("timestamp", now + 1, "message", "two")), REGION);
|
||||
service.putLogEvents("/app/other", "stream-1",
|
||||
List.of(Map.of("timestamp", now + 2, "message", "other")), REGION);
|
||||
|
||||
long expected = service.describeLogStreams("/app/logs", null, REGION).stream()
|
||||
.mapToLong(LogStream::getStoredBytes)
|
||||
.sum();
|
||||
assertTrue(expected > 0);
|
||||
assertEquals(expected, service.getStoredBytesForLogGroup("/app/logs", REGION));
|
||||
assertEquals(0, service.getStoredBytesForLogGroup("/app/empty", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putLogEventsUpdatesStreamMetadata() {
|
||||
service.createLogGroup("/app/logs", null, null, REGION);
|
||||
|
||||
Reference in new issue
Block a user