Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default environment #3

Merged
merged 4 commits into from
Jul 22, 2020
Merged

Default environment #3

merged 4 commits into from
Jul 22, 2020

Conversation

yaozhaoy
Copy link
Contributor

Issue #, if available:

Description of changes:

  • Added a default environment
  • Added a TCP client
  • Added agent-based sink
  • Added environment provider

TODO:

  • Add a UDP client
  • Add a integration test

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@yaozhaoy yaozhaoy requested a review from jaredcnance July 21, 2020 20:22

/**
* The LogGroup name to use. This will be ignored when using the
* Lambda scope.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you probably copied this from the other repos, but we can be explicit in the javadocs and say that this is really just for the CWAgent.

@@ -0,0 +1,7 @@
package software.amazon.awssdk.services.cloudwatchlogs.emf.config;

class SystemWrapper {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Configuration is a singleton and is created by EnvironmentConfigurationProvider. The Provider reads environment variables from System. It's difficult to mock the System to test the EnvironmentConfigurationProvider, so I used SystemWrapper to make it possible to mock System.

@@ -65,4 +67,9 @@ void putMetric(String key, double value) {
}
return dimensions;
}

String serialize() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to create an ObjectMapper every time? Also, recommend looking at this issue: awslabs/aws-embedded-metrics-node#50

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Added a property filter to filter out the _aws if no metrics have been defined.

/**
* Establish a connection to a socket
*/
void connect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this on the interface? The socket client needs to manage some state anyways and connect can probably be encapsulated rather than require the sink to call it before sendMessage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this issue


@Override
public void sendMessage(String message) {
if (socket.isClosed() || shouldConnect) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a thread safe operation. Is this class used across threads?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's possible that this class is used across threads.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Python lib, we address this using 2 instance-level locks for writes and connecting. https://github.com/awslabs/aws-embedded-metrics-python/blob/master/aws_embedded_metrics/sinks/tcp_client.py#L35

- Filter out '_aws' metadata object if no metrics have been added
- Add lock for sendMessage method
@yaozhaoy yaozhaoy merged commit 1a27fcb into awslabs:master Jul 22, 2020
@yaozhaoy yaozhaoy deleted the default_environment branch August 17, 2020 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants