Skip to content

Commit

Permalink
Merge pull request awslabs#110 from Stephen-Bao/ecs-loggroupname-fix
Browse files Browse the repository at this point in the history
Added logic for replacing colon in log group name and unit test
  • Loading branch information
Stephen-Bao authored Aug 10, 2022
2 parents a49c96e + 60dd16b commit 4c242fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ public String getName() {

@Override
public String getLogGroupName() {
return config.getLogGroupName().orElse(getName() + "-metrics");
if (config.getLogGroupName().isPresent()) {
return config.getLogGroupName().get();
} else {
String serviceName = getName();
// for ECS services, replace "repo:tag" format with "repo-tag" to satisfy
// log group regex
serviceName = serviceName.replaceAll(":", "-");
return serviceName + "-metrics";
}
}

public String getLogStreamName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public void testGetLogGroupNameReturnNonEmpty() {
assertEquals(environment.getLogGroupName(), Constants.UNKNOWN + "-metrics");
}

@Test
public void testGetLogGroupNameReplaceColon() {
String serviceName = "testRepo:testTag";
when(config.getServiceName()).thenReturn(Optional.of(serviceName));

assertEquals(environment.getLogGroupName(), "testRepo-testTag-metrics");
}

@Test
public void testConfigureContext() throws UnknownHostException {
PowerMockito.mockStatic(SystemWrapper.class);
Expand Down

0 comments on commit 4c242fc

Please sign in to comment.