-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider job inclusion/exclusion setting when tracking logs (#432)
- Loading branch information
1 parent
e5b5871
commit aa51fc8
Showing
13 changed files
with
147 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...s/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-blacklistEntry.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div> | ||
<p>A comma-separated list of regex used to exclude job names from monitoring, for example: "susans-job,johns-.*,prod_folder/prod_release".</p> | ||
<p>Please note that for wildcards regular expressions should be used, and not glob patterns (see the example above).</p> | ||
<p>This setting affects all aspects of the plugin: events, metrics, logs, CI visibility.</p> | ||
</div> |
5 changes: 5 additions & 0 deletions
5
...s/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration/help-whitelistEntry.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div> | ||
<p>A comma-separated list of regex used to include job names for monitoring, for example: "susans-job,johns-.*,prod_folder/prod_release".</p> | ||
<p>Please note that for wildcards regular expressions should be used, and not glob patterns (see the example above).</p> | ||
<p>This setting affects all aspects of the plugin: events, metrics, logs, CI visibility.</p> | ||
</div> |
64 changes: 64 additions & 0 deletions
64
src/test/java/org/datadog/jenkins/plugins/datadog/logs/DatadogConsoleLogFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.datadog.jenkins.plugins.datadog.logs; | ||
|
||
import static org.junit.Assert.assertSame; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import hudson.model.Run; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
import org.datadog.jenkins.plugins.datadog.DatadogGlobalConfiguration; | ||
import org.datadog.jenkins.plugins.datadog.DatadogUtilities; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class DatadogConsoleLogFilterTest { | ||
|
||
@ClassRule | ||
public static JenkinsRule JENKINS = new JenkinsRule(); | ||
|
||
|
||
@Test | ||
public void testExcludedJobsAreNotDecorated() { | ||
String jobName = "my-job"; | ||
givenJobIsExcludedFromTracking(jobName); | ||
WorkflowRun run = givenBuildNamed(jobName); | ||
|
||
OutputStream originalStream = new ByteArrayOutputStream(); | ||
DatadogConsoleLogFilter filter = new DatadogConsoleLogFilter(); | ||
OutputStream decoratedStream = filter.decorateLogger(run, originalStream); | ||
|
||
assertSame(originalStream, decoratedStream); | ||
} | ||
|
||
@Test | ||
public void testExcludedJobsProvidedViaConstructorAreNotDecorated() { | ||
String jobName = "my-job"; | ||
givenJobIsExcludedFromTracking(jobName); | ||
WorkflowRun run = givenBuildNamed(jobName); | ||
|
||
OutputStream originalStream = new ByteArrayOutputStream(); | ||
DatadogConsoleLogFilter filter = new DatadogConsoleLogFilter(run); | ||
OutputStream decoratedStream = filter.decorateLogger((Run) null, originalStream); | ||
|
||
assertSame(originalStream, decoratedStream); | ||
} | ||
|
||
private static void givenJobIsExcludedFromTracking(String jobName) { | ||
DatadogGlobalConfiguration cfg = DatadogUtilities.getDatadogGlobalDescriptor(); | ||
cfg.setExcluded(jobName); | ||
} | ||
|
||
private static @NotNull WorkflowRun givenBuildNamed(String jobName) { | ||
WorkflowJob job = mock(WorkflowJob.class); | ||
when(job.getFullName()).thenReturn(jobName); | ||
|
||
WorkflowRun run = mock(WorkflowRun.class); | ||
when(run.getParent()).thenReturn(job); | ||
return run; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters