Skip to content

Commit

Permalink
Move buildspecs to S3 bucket (#113)
Browse files Browse the repository at this point in the history
* rm buildspecs
* style improvements & code debt
  • Loading branch information
Mark Kuhn authored Aug 23, 2022
1 parent c5a78d4 commit f8d6cf7
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 226 deletions.
21 changes: 0 additions & 21 deletions buildspecs/buildspec.canary.yml

This file was deleted.

17 changes: 0 additions & 17 deletions buildspecs/buildspec.release.yml

This file was deleted.

21 changes: 0 additions & 21 deletions buildspecs/buildspec.yml

This file was deleted.

4 changes: 2 additions & 2 deletions examples/lambda/src/main/java/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import java.util.HashMap;
import java.util.Map;

public class Handler implements RequestHandler<Map<String,String>, String> {
public class Handler implements RequestHandler<Map<String, String>, String> {

@Override
public String handleRequest(Map<String,String> event, Context context) {
public String handleRequest(Map<String, String> event, Context context) {
String response = "200 OK";
MetricsLogger logger = new MetricsLogger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

/** A wrapper class that can be used to mock 'System.getenv' with PowerMock. */
public class SystemWrapper {
private SystemWrapper() {
throw new IllegalStateException("Utility class");
}

public static String getenv(String name) {
return System.getenv(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class AgentBasedEnvironment implements Environment {
private final Configuration config;
private ISink sink;

public AgentBasedEnvironment(Configuration config) {
protected AgentBasedEnvironment(Configuration config) {
this.config = config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void setDefaultDimensions(DimensionSet dimensionSet) {
}

public boolean hasDefaultDimensions() {
return getDefaultDimensions().getDimensionKeys().size() > 0;
return !getDefaultDimensions().getDimensionKeys().isEmpty();
}

/**
Expand Down Expand Up @@ -258,7 +258,7 @@ public List<String> serialize() throws JsonProcessingException {
Map<String, MetricDefinition> metrics = new HashMap<>();
Queue<MetricDefinition> metricDefinitions =
new LinkedList<>(rootNode.metrics().values());
while (metricDefinitions.size() > 0) {
while (!metricDefinitions.isEmpty()) {
MetricDefinition metric = metricDefinitions.poll();

if (metrics.size() == Constants.MAX_METRICS_PER_EVENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package software.amazon.cloudwatchlogs.emf.serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
Expand All @@ -35,8 +34,7 @@ public class InstantSerializer extends StdSerializer<Instant> {

@Override
public void serialize(Instant value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {

throws IOException {
jgen.writeNumber(value.toEpochMilli());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package software.amazon.cloudwatchlogs.emf.serializers;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
Expand All @@ -34,11 +33,8 @@ public class UnitDeserializer extends StdDeserializer<Unit> {
}

@Override
public Unit deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {

public Unit deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
String value = jp.getValueAsString();
Unit unit = Unit.fromValue(value);
return unit;
return Unit.fromValue(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package software.amazon.cloudwatchlogs.emf.serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
Expand All @@ -35,8 +34,7 @@ public class UnitSerializer extends StdSerializer<Unit> {

@Override
public void serialize(Unit value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {

throws IOException {
String str = value.toString();
jgen.writeString(str);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import org.slf4j.Logger;

public class IOUtils {
private IOUtils() {
throw new IllegalStateException("Utility class");
}

private static final int BUFFER_SIZE = 1024 * 4;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import software.amazon.cloudwatchlogs.emf.exception.EMFClientException;

public class Jackson {
private Jackson() {
throw new IllegalStateException("Utility class");
}

private static final ObjectMapper objectMapper = new ObjectMapper();
private static final ObjectWriter writer = objectMapper.writer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package software.amazon.cloudwatchlogs.emf.util;

public class StringUtils {
private StringUtils() {
throw new IllegalStateException("Utility class");
}

public static boolean isNullOrEmpty(String value) {
return value == null || value.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public void testReturnEmptyOrDefaultIfNotSet() {
assertFalse(config.getServiceType().isPresent());
assertFalse(config.getServiceName().isPresent());

assertEquals(config.getEnvironmentOverride(), Environments.Unknown);
assertEquals(config.getAsyncBufferSize(), 100);
assertEquals(Environments.Unknown, config.getEnvironmentOverride());
assertEquals(100, config.getAsyncBufferSize());
}

@Test
Expand All @@ -60,7 +60,7 @@ public void testReturnEmptyIfStringValueIsBlank() {
assertFalse(config.getLogStreamName().isPresent());
assertFalse(config.getServiceType().isPresent());
assertFalse(config.getServiceName().isPresent());
assertEquals(config.getEnvironmentOverride(), Environments.Unknown);
assertEquals(Environments.Unknown, config.getEnvironmentOverride());
}

@Test
Expand All @@ -81,12 +81,12 @@ public void testReturnCorrectValueAfterSet() {
config.setEnvironmentOverride(expectedEnvironment);
config.setAsyncBufferSize(expectedAsyncBufferSize);

assertEquals(config.getAgentEndpoint().get(), expectedEndpoint);
assertEquals(config.getLogGroupName().get(), expectedLogGroupName);
assertEquals(config.getLogStreamName().get(), expectedLogStreamName);
assertEquals(config.getServiceType().get(), expectedServiceType);
assertEquals(config.getServiceName().get(), expectedServiceName);
assertEquals(config.getEnvironmentOverride(), expectedEnvironment);
assertEquals(config.getAsyncBufferSize(), expectedAsyncBufferSize);
assertEquals(expectedEndpoint, config.getAgentEndpoint().get());
assertEquals(expectedLogGroupName, config.getLogGroupName().get());
assertEquals(expectedLogStreamName, config.getLogStreamName().get());
assertEquals(expectedServiceType, config.getServiceType().get());
assertEquals(expectedServiceName, config.getServiceName().get());
assertEquals(expectedEnvironment, config.getEnvironmentOverride());
assertEquals(expectedAsyncBufferSize, config.getAsyncBufferSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public void getGetConfig() {

Configuration config = EnvironmentConfigurationProvider.createConfig();

assertEquals(config.getServiceName().get(), "TestServiceName");
assertEquals(config.getServiceType().get(), "TestServiceType");
assertEquals(config.getLogGroupName().get(), "TestLogGroup");
assertEquals(config.getLogStreamName().get(), "TestLogStream");
assertEquals(config.getAgentEndpoint().get(), "Endpoint");
assertEquals(config.getEnvironmentOverride(), Environments.Agent);
assertEquals(config.getAsyncBufferSize(), 9999);
assertEquals("TestServiceName", config.getServiceName().get());
assertEquals("TestServiceType", config.getServiceType().get());
assertEquals("TestLogGroup", config.getLogGroupName().get());
assertEquals("TestLogStream", config.getLogStreamName().get());
assertEquals("Endpoint", config.getAgentEndpoint().get());
assertEquals(Environments.Agent, config.getEnvironmentOverride());
assertEquals(9999, config.getAsyncBufferSize());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,55 +39,55 @@ public void setUp() {
public void testGetName() {
String serviceName = "TestService";
when(configuration.getServiceName()).thenReturn(Optional.of(serviceName));
assertEquals(environment.getName(), serviceName);
assertEquals(serviceName, environment.getName());
}

@Test
public void testGetNameWhenNotConfigured() {
when(configuration.getServiceName()).thenReturn(Optional.empty());
assertEquals(environment.getName(), "Unknown");
assertEquals("Unknown", environment.getName());
}

@Test
public void testGetType() {
String serviceType = "TestServiceType";
when(configuration.getServiceType()).thenReturn(Optional.of(serviceType));
assertEquals(environment.getType(), serviceType);
assertEquals(serviceType, environment.getType());
}

@Test
public void testGetTypeWhenNotConfigured() {
when(configuration.getServiceType()).thenReturn(Optional.empty());
assertEquals(environment.getType(), "Unknown");
assertEquals("Unknown", environment.getType());
}

@Test
public void testGetLogStreamName() {
String logStream = "TestLogStream";
when(configuration.getLogStreamName()).thenReturn(Optional.of(logStream));
assertEquals(environment.getLogStreamName(), logStream);
assertEquals(logStream, environment.getLogStreamName());
}

@Test
public void testGetLogStreamNameWhenNotConfigured() {
String serviceName = "TestService";
when(configuration.getLogStreamName()).thenReturn(Optional.empty());
when(configuration.getServiceName()).thenReturn(Optional.of(serviceName));
assertEquals(environment.getLogStreamName(), "");
assertEquals("", environment.getLogStreamName());
}

@Test
public void testGetLogGroupName() {
String logGroup = "TestLogGroup";
when(configuration.getLogGroupName()).thenReturn(Optional.of(logGroup));
assertEquals(environment.getLogGroupName(), logGroup);
assertEquals(logGroup, environment.getLogGroupName());
}

@Test
public void testGetLogLogNameWhenNotConfigured() {
String serviceName = "TestService";
when(configuration.getLogGroupName()).thenReturn(Optional.empty());
when(configuration.getServiceName()).thenReturn(Optional.of(serviceName));
assertEquals(environment.getLogGroupName(), serviceName + "-metrics");
assertEquals(serviceName + "-metrics", environment.getLogGroupName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testProbeReturnTrue() {
public void testGetTypeWhenNoMetadata() {
when(fetcher.fetch(any(), any())).thenThrow(new EMFClientException("Invalid URL"));
environment.probe();
assertEquals(environment.getType(), Constants.UNKNOWN);
assertEquals(Constants.UNKNOWN, environment.getType());
}

@Test
Expand All @@ -78,7 +78,7 @@ public void testGetTypeReturnDefined() {
when(fetcher.fetch(any(), any(), (Class<Object>) any(), any()))
.thenReturn(new EC2Environment.EC2Metadata());
environment.probe();
assertEquals(environment.getType(), "AWS::EC2::Instance");
assertEquals("AWS::EC2::Instance", environment.getType());
}

@Test
Expand All @@ -87,7 +87,7 @@ public void testGetTypeFromConfiguration() {
environment.probe();
String testType = faker.letterify("???");
when(config.getServiceType()).thenReturn(Optional.of(testType));
assertEquals(environment.getType(), testType);
assertEquals(testType, environment.getType());
}

@Test
Expand All @@ -101,11 +101,11 @@ public void testConfigureContext() {
MetricsContext context = new MetricsContext();
environment.configureContext(context);

assertEquals(context.getProperty("imageId"), metadata.getImageId());
assertEquals(context.getProperty("instanceId"), metadata.getInstanceId());
assertEquals(context.getProperty("instanceType"), metadata.getInstanceType());
assertEquals(context.getProperty("privateIp"), metadata.getPrivateIp());
assertEquals(context.getProperty("availabilityZone"), metadata.getAvailabilityZone());
assertEquals(metadata.getImageId(), context.getProperty("imageId"));
assertEquals(metadata.getInstanceId(), context.getProperty("instanceId"));
assertEquals(metadata.getInstanceType(), context.getProperty("instanceType"));
assertEquals(metadata.getPrivateIp(), context.getProperty("privateIp"));
assertEquals(metadata.getAvailabilityZone(), context.getProperty("availabilityZone"));
}

private void getRandomMetadata(EC2Environment.EC2Metadata metadata) {
Expand Down
Loading

0 comments on commit f8d6cf7

Please sign in to comment.