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 logstash into spring autoconfiguration and provide logstash raw marker config possibility #811

Merged
merged 1 commit into from
Aug 15, 2020

Conversation

pbouillet
Copy link
Contributor

Description

2 changes overall:

  • Provide a possibility to change the logstash raw marker field name which contains all the information about the requests and responses
  • Add a Spring configuration possibility to use the logstash sink and configure the raw marker field name

Motivation and Context

The first change is motivated by an issue in our logging environment (ELK). As we use it for many applications, the http field name clashes with an already existing one which is indexed and defined as a different type. Because of this, we cannot even see the requests and responses logged by logbook. For this, I introduced a possibility to change this field name.
The second change is more of a convenient change for Spring autoconfiguration. Currently, we need to define an own Spring bean to be able to use this Logstash sink. I'm not sure if you have some requirements on if and how configuration changes should be for your framework, so feedback is pretty much appreciated (and if needed, I could roll back the second change if you don't feel this is a good way)
I added both changes in a way that the defaults are as before and no breaking changes are introduced.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@pbouillet
Copy link
Contributor Author

Seems like there is new identified vulnerability in the kotlin-stdlib library that is used by logbook-okhttp: https://nvd.nist.gov/vuln/detail/CVE-2020-15824. As this is not related to my PR, I leave it as it is right now. Guess there is a change needed to either ignore or update to a newer version.

@whiskeysierra
Copy link
Collaborator

whiskeysierra commented Aug 12, 2020 via email

@whiskeysierra
Copy link
Collaborator

@pbouillet I fixed the CVE issue in master. If you rebase onto the latest version the build error should be gone. I'll take a look at the code now.

@pbouillet
Copy link
Contributor Author

@whiskeysierra done, thanks!

@@ -17,22 +16,32 @@

import static org.apiguardian.api.API.Status.EXPERIMENTAL;

@AllArgsConstructor
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd leave that in, so you don't have to implement it by hand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fine for me with your suggestion! Thanks

@API(status = EXPERIMENTAL)
public final class LogstashLogbackSink implements Sink {

private final static Logger log = LoggerFactory.getLogger(Logbook.class);

private final HttpLogFormatter formatter;

private String baseField = "http";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
private String baseField = "http";
private final String fieldName;

private String baseField = "http";

public LogstashLogbackSink(final HttpLogFormatter formatter) {
this.formatter = formatter;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
this.formatter = formatter;
this(formatter, "http");

public LogstashLogbackSink(final HttpLogFormatter formatter, final String baseField) {
this.formatter = formatter;
this.baseField = baseField;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
public LogstashLogbackSink(final HttpLogFormatter formatter, final String baseField) {
this.formatter = formatter;
this.baseField = baseField;
}

@@ -245,12 +246,22 @@ public Strategy withoutBody() {
@API(status = INTERNAL)
@Bean
@ConditionalOnMissingBean(Sink.class)
public Sink sink(
@ConditionalOnProperty(value = "logbook.sink.style", havingValue = "default", matchIfMissing = true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd move this to a separate PR. Until now the only way to configure Sinks is programmatically, by registering a bean. I have to think about whether we can (and should?) offer that also for other Sink implementations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(By this, I'm referring to the whole Spring Boot Auto Configuration support aspect of this PR.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, will do

@pbouillet
Copy link
Contributor Author

PR has been updated to only focus the change in the logback sink. Let me know if more needs to be changed!

@whiskeysierra
Copy link
Collaborator

👍

@whiskeysierra whiskeysierra merged commit 2142418 into zalando:master Aug 15, 2020
@whiskeysierra
Copy link
Collaborator

Thank you for your contribution! 🎉
I'm planning on releasing on Monday the latest.

@whiskeysierra
Copy link
Collaborator

I released it as 2.2.0 just now. Should be available in central soon.

@pbouillet
Copy link
Contributor Author

Awesome, thank you! Let me know if you need the other part as a PR in the future!

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