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

Add support for service.environment #184

Merged
merged 4 commits into from
May 2, 2022
Merged

Add support for service.environment #184

merged 4 commits into from
May 2, 2022

Conversation

odin568
Copy link
Contributor

@odin568 odin568 commented Apr 29, 2022

As an extension of #168
We are hosting different environments of our applications, i.e. dev, test and of course prod.
In order to distinguish logs, we set the service.environment field. With this change it is easier to achieve.
Please review and feel free to merge.

@cla-checker-service
Copy link

cla-checker-service bot commented Apr 29, 2022

💚 CLA has been signed

@github-actions github-actions bot added agent-java community Issues and PRs created by the community triage Issues and PRs that need to be triaged labels Apr 29, 2022
@apmmachine
Copy link
Contributor

apmmachine commented Apr 29, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-05-02T08:07:44.403+0000

  • Duration: 7 min 47 sec

Test stats 🧪

Test Results
Failed 0
Passed 243
Skipped 0
Total 243

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@felixbarny
Copy link
Member

@odin568 thanks for your contribution! This makes a lot of sense to me.
Please make sure to sign the CLA so that we are able to merge the PR.

@felixbarny felixbarny changed the title Add service.Environment as dedicated field Add support for service.environment Apr 29, 2022
@odin568
Copy link
Contributor Author

odin568 commented Apr 29, 2022

@odin568 thanks for your contribution! This makes a lot of sense to me. Please make sure to sign the CLA so that we are able to merge the PR.

Hi,
yes I tried. Seems to be more complex than the change. Not sure if I submitted multiple times, did not get any mail, etc. so far.
Sorry for inconvenience then ;)

@felixbarny
Copy link
Member

Please make sure that the email address you're using to sign the CLA is also registered in your GitHub settings (https://github.com/settings/emails).

@odin568
Copy link
Contributor Author

odin568 commented Apr 29, 2022

Please make sure that the email address you're using to sign the CLA is also registered in your GitHub settings (https://github.com/settings/emails).

Valid Point. I re-signed it, no Mail so far.

@felixbarny
Copy link
Member

I can see you in the system with two different email addresses now. However, the mail used in your git config (see https://github.com/elastic/ecs-logging-java/pull/184.patch) is a different one.

@odin568
Copy link
Contributor Author

odin568 commented Apr 29, 2022

I can see you in the system with two different email addresses now. However, the mail used in your git config (see https://github.com/elastic/ecs-logging-java/pull/184.patch) is a different one.

Allright, now you should have three :)
Sorry, too many different workstations

@felixbarny felixbarny requested a review from eyalkoren April 29, 2022 15:27
Copy link
Contributor

@eyalkoren eyalkoren left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!
A couple of minor space removals, plus one request to make sure we do not add platform-specific assertion to tests

@@ -50,7 +50,7 @@ void testLogException() throws Exception {
assertThat(log.get("error.stack_trace").isArray()).isTrue();
ArrayNode arrayNode = (ArrayNode) log.get("error.stack_trace");
assertThat(arrayNode.size()).isEqualTo(4);
assertThat(arrayNode.get(0).textValue()).isEqualTo("java.lang.NumberFormatException: For input string: \"NOT_AN_INT\"");
assertThat(arrayNode.get(0).textValue()).isEqualTo("java.lang.NumberFormatException: For input string: \"NOT_AN_INT\"\r");
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks platform-specific. Does this fail for you without that?
If so, better to change to use startsWith or regex comparison instead

Copy link
Contributor

Choose a reason for hiding this comment

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

Test on CI (Ubuntu 18) fails with:

[2022-05-01T12:33:28.698Z] Failed tests: 
[2022-05-01T12:33:28.698Z]   EcsLayoutWithStackTraceAsArrayTest.testLogException:53 
[2022-05-01T12:33:28.698Z] Expecting:
[2022-05-01T12:33:28.698Z]  <"java.lang.NumberFormatException: For input string: "NOT_AN_INT"">
[2022-05-01T12:33:28.698Z] to be equal to:
[2022-05-01T12:33:28.698Z]  <"java.lang.NumberFormatException: For input string: "NOT_AN_INT"
">
[2022-05-01T12:33:28.698Z] but was not.

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 fails on Windows otherwise. Added a trim before, should be platform-independent then.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is an issue in the tests but a bug here:

private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\n");

It always splits on \n instead of depending on the platform.

Copy link
Contributor Author

@odin568 odin568 May 2, 2022

Choose a reason for hiding this comment

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

You are right. That's why I got \r at the end. Wondered about mac style... but is clear if it splitted by \n.
Generalized it in latest commit and removed the .trim() again.

@eyalkoren
Copy link
Contributor

/test

@odin568
Copy link
Contributor Author

odin568 commented May 2, 2022

I applied changes you mentioned. Thanks for feedback!

\r\n was splitted only by \n which is problematic on windows.
Generalized to use \R which matches all combinations of line breaks.
@@ -36,7 +36,7 @@ public class EcsJsonSerializer {
private static final TimestampSerializer TIMESTAMP_SERIALIZER = new TimestampSerializer();
private static final ThreadLocal<StringBuilder> messageStringBuilder = new ThreadLocal<StringBuilder>();
private static final String NEW_LINE = System.getProperty("line.separator");
private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\n");
private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\R");
Copy link
Member

Choose a reason for hiding this comment

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

\R has been introduced in Java 8 so this won't work with older Java versions which this library is compatible with.

You could either use the equivalent of \R (\u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]) or the more simple alternative "\\r?\\n" which should cover most relevant cases (ignores Mac OS 9 style \r, though).

Copy link
Contributor Author

@odin568 odin568 May 2, 2022

Choose a reason for hiding this comment

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

ah okay, was not aware that < Java 8 is supported still. Yes then let's make it right. The pattern I like as it is simple to read is \r\n|\n|\r - covers all cases for a single newline. Will update

Copy link
Member

@felixbarny felixbarny left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Contributor

@eyalkoren eyalkoren left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-java community Issues and PRs created by the community triage Issues and PRs that need to be triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants