Skip to content

Add log collection#44

Merged
gzussa merged 12 commits into
masterfrom
gzu/logs
Feb 21, 2020
Merged

Add log collection#44
gzussa merged 12 commits into
masterfrom
gzu/logs

Conversation

@gzussa

@gzussa gzussa commented Feb 13, 2020

Copy link
Copy Markdown
Contributor

What does this PR do?

Adding log collection and better exception logging when the plugin is misconfigured.

Description of the Change

Created a package to hold the log logic. It contains 3 classes:

  • DatadogConsoleLogFilter that extends ConsoleLogFilter. All it does is decorate the log outputStream with a custom DatadogOutputStream if needed.
  • DatadogOutputStream extends LineTransformationOutputStream and mainly clean log lines from Jenkins Notes. It then uses a DatadogWriter class to submit logs.
  • DatadogWriter gets contextual information to prepare the log message to be sent to Datadog.
    • As a side effect, i had to refactor the BuildData in order to be able to retrieve a maximum of tags/contextual info even when a listener is not provided to the constructor. In turn, i had to make changes to some methods in DatadogUtilities in order to be more permissive.

Added new configs:

  • logIntakeUrl when submitting log using the Datadog API directly.
  • logCollectionPort when submitting log using the Datadog Agent.
  • collectBuildLogs to turn the collection on and off (default is off).

Env variable loading is not overriding the saved config anymore, hence simplifying the loading logic a little.

I also made changes regarding exception loggings. Before, if the plugin was misconfigured it would print out stack trace exceptions in stdout. It would do so repetitively because of all Publisher classes.

We no longer throw exceptions when calling getInstance on a client implementation.
Even if params are not valid (null or empty), we return null. As a consequence, I had to add null checks everywhere in order to return from the calling method. Now user will see clean severe level error message in their logs.
I also added connection broken attributes (defaultIntakeConnectionBroken and logIntakeConnectionBroken) in order to prevent making bad http calls to Datadog all the time and especially when we know the connection is broken after validation.
As a consequence, i had to refactor the validate http client method is order to be static and independent from the current client instance singleton.

Possible Drawbacks

When enable, log submission may have some perf implications but i haven't done any load testing at this point and it is kinda inevitable anyway.

Verification Process

Review and manual testing mainly.

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@gzussa gzussa changed the title Gzu/logs Add log collection Feb 13, 2020
@github-actions github-actions Bot added the documentation Documentation related changes label Feb 13, 2020
@timja timja mentioned this pull request Feb 13, 2020
6 tasks
Comment thread DEVELOPMENT.md Outdated
Comment thread README.md Outdated
Comment on lines +377 to +391
if(StringUtils.isNotBlank(portStr)){
if(StringUtils.isNumeric(portStr)) {
this.setTargetPort(formData.getInt("targetPort"));
}
}else{
this.setTargetPort(null);
}
String logCollectionPortStr = formData.getString("targetLogCollectionPort");
if(StringUtils.isNotBlank(logCollectionPortStr)){
if(StringUtils.isNumeric(logCollectionPortStr)){
this.setTargetLogCollectionPort(formData.getInt("targetLogCollectionPort"));
}
}else{
this.setTargetLogCollectionPort(null);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isn't it supposed to be validated by validateTargetPort ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes and it is happening below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess I don’t understand why we do the type checking here as well

Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/DatadogUtilities.java Outdated
Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogHttpClient.java Outdated
Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogHttpClient.java Outdated
Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/logs/DatadogWriter.java Outdated
@gzussa
gzussa merged commit 25c2679 into master Feb 21, 2020
@gzussa
gzussa deleted the gzu/logs branch February 21, 2020 15:00
@gzussa gzussa added the changelog/Added Added features results into a minor version bump label Feb 21, 2020
@kaykay88

kaykay88 commented Apr 7, 2020

Copy link
Copy Markdown

@gzussa
In which release is this change added ? I am asking because for 1.1.0 plugin verion, I am still seeing the following error.

2020-04-07 08:07:20.770+0000 [id=39]	SEVERE	o.d.j.p.d.c.DatadogHttpClient#getInstance: Datadog API Key is not set properly

2020-04-07 08:07:23.213+0000 [id=43]	SEVERE	o.d.j.p.d.c.DatadogHttpClient#getInstance: Datadog API Key is not set properly

2020-04-07 08:07:23.245+0000 [id=39]	SEVERE	o.d.j.p.d.c.DatadogHttpClient#getInstance: Datadog API Key is not set properly

2020-04-07 08:07:23.364+0000 [id=41]	SEVERE	o.d.j.p.d.c.DatadogHttpClient#getInstance: Datadog API Key is not set properly

2020-04-07 08:07:23.398+0000 [id=42]	SEVERE	o.d.j.p.d.c.DatadogHttpClient#getInstance: Datadog API Key is not set properly

@gzussa

gzussa commented Apr 7, 2020

Copy link
Copy Markdown
Contributor Author

Hey @kaykay88, it seems like a plugin configuration issue. Another issue has been open #55. We will follow up there.

DatadogUtilities.severe(logger, null, String.format("Datadog/%s/jenkins Java/%s Jenkins/%s",
getDatadogPluginVersion(),
getJavaRuntimeVersion(),
getJenkinsVersion()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this supposed to be here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Definitely not and still on master, I'll remove it now 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Added Added features results into a minor version bump documentation Documentation related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants