Skip to content

Commit

Permalink
Updated branch with new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Bao committed Aug 10, 2022
2 parents 7619866 + a49c96e commit 60dd16b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ allprojects {
targetCompatibility = '1.8'
}

version = '2.0.0-beta-1'
version = '3.0.0-beta-1'
}

java {
Expand Down
2 changes: 1 addition & 1 deletion canarytests/agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:8-jdk-slim
FROM openjdk:11-jdk-slim
RUN mkdir /app
COPY build/libs/*.jar /app/agent.jar
ENV JAVA_OPTS=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Constants {

public static final int MAX_METRICS_PER_EVENT = 100;

public static final int MAX_DIMENSION_SET_SIZE = 30;

public static final int MAX_DATAPOINTS_PER_METRIC = 100;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public String getLogGroupName() {
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(":", "-");
}
serviceName = serviceName.replaceAll(":", "-");
return serviceName + "-metrics";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package software.amazon.cloudwatchlogs.emf.exception;

import software.amazon.cloudwatchlogs.emf.Constants;

public class DimensionSetExceededException extends RuntimeException {

public DimensionSetExceededException() {
super(
"Maximum number of dimensions allowed are "
+ Constants.MAX_DIMENSION_SET_SIZE
+ ". Account for default dimensions if not using setDimensions.");
}

public DimensionSetExceededException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import software.amazon.cloudwatchlogs.emf.Constants;
import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException;

/** A combination of dimension values. */
public class DimensionSet {
Expand Down Expand Up @@ -149,6 +151,10 @@ private static DimensionEntry entryOf(String key, String value) {
* @param value Value of the dimension
*/
public void addDimension(String dimension, String value) {
if (this.getDimensionKeys().size() >= Constants.MAX_DIMENSION_SET_SIZE) {
throw new DimensionSetExceededException();
}

this.getDimensionRecords().put(dimension, value);
}

Expand All @@ -161,6 +167,12 @@ public void addDimension(String dimension, String value) {
*/
public DimensionSet add(DimensionSet other) {
DimensionSet mergedDimensionSet = new DimensionSet();
int mergedDimensionSetSize =
this.getDimensionKeys().size() + other.dimensionRecords.keySet().size();
if (mergedDimensionSetSize > Constants.MAX_DIMENSION_SET_SIZE) {
throw new DimensionSetExceededException();
}

mergedDimensionSet.dimensionRecords.putAll(dimensionRecords);
mergedDimensionSet.dimensionRecords.putAll(other.dimensionRecords);
return mergedDimensionSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package software.amazon.cloudwatchlogs.emf.model;

import static org.junit.Assert.*;

import org.junit.Test;
import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException;

public class DimensionSetTest {
@Test
public void testAddDimension() {
int dimensionsToBeAdded = 30;
DimensionSet dimensionSet = generateDimensionSet(dimensionsToBeAdded);

assertEquals(dimensionsToBeAdded, dimensionSet.getDimensionKeys().size());
}

@Test
public void testAddDimensionLimitExceeded() {
Exception exception =
assertThrows(
DimensionSetExceededException.class,
() -> {
int dimensionSetSize = 33;
generateDimensionSet(dimensionSetSize);
});

String expectedMessage = "Maximum number of dimensions";
String actualMessage = exception.getMessage();

assertTrue(actualMessage.contains(expectedMessage));
}

@Test
public void testMergeDimensionSets() {
Exception exception =
assertThrows(
DimensionSetExceededException.class,
() -> {
int dimensionSetSize = 28;
int otherDimensionSetSize = 5;
DimensionSet dimensionSet = generateDimensionSet(dimensionSetSize);
DimensionSet otherDimensionSet =
generateDimensionSet(otherDimensionSetSize);
dimensionSet.add(otherDimensionSet);
});
String expectedMessage = "Maximum number of dimensions";
String actualMessage = exception.getMessage();

assertTrue(actualMessage.contains(expectedMessage));
}

private DimensionSet generateDimensionSet(int numOfDimensions) {
DimensionSet dimensionSet = new DimensionSet();

for (int i = 0; i < numOfDimensions; i++) {
dimensionSet.addDimension("Dimension" + i, "value" + i);
}

return dimensionSet;
}
}

0 comments on commit 60dd16b

Please sign in to comment.