Skip to content

Commit

Permalink
Added logic for replacing colon in log group name and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Bao committed Aug 9, 2022
1 parent bbd2097 commit 7619866
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ 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
if (serviceName.indexOf(':') != -1) {
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 7619866

Please sign in to comment.