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

Filtering Events Feature Request #353

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ target/*
nb-configuration.xml
.idea
*.iml
docker-compose.yaml
/.vscode/
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
</dependencyManagement>

<dependencies>

<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>jnr-posix-api</artifactId>
Expand All @@ -101,6 +100,12 @@
<version>3.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ public Event.Priority toEventPriority(){

public Map<String, Set<String>> getTags();

public String getEventName();

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1064,4 +1064,19 @@ public static String getCatchErrorResult(BlockStartNode startNode) {
}
return null;
}

/**
* Checks to see if event can be sent to client
* @param event - the event to check
* @return true if event is can be sent to client
*/
public static boolean canSendEventToClient(DatadogEvent event) {
dawitgirm marked this conversation as resolved.
Show resolved Hide resolved
DatadogGlobalConfiguration cfg = getDatadogGlobalDescriptor();

if (cfg == null) { // sometimes null for tests, so default is to send all events
return true;
}

return cfg.getListOfIncludedEvents().contains(event.getEventName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class AbstractDatadogEvent implements DatadogEvent {
private String aggregationKey;
private Long date;
private Map<String, Set<String>> tags;
protected String eventName;

@Override
public String getTitle() {
Expand Down Expand Up @@ -123,6 +124,10 @@ public void setTags(Map<String, Set<String>> tags) {
this.tags = tags;
}

public String getEventName() {
return this.eventName;
}

protected String getLocationDetails(){
String hostMsg = "Host: unknown";
String instanceMsg = "Jenkins URL: unknown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.datadog.jenkins.plugins.datadog.model.BuildData;

public class BuildAbortedEventImpl extends AbstractDatadogBuildEvent {

public BuildAbortedEventImpl(BuildData buildData) {
super(buildData);

Expand All @@ -51,5 +51,6 @@ public BuildAbortedEventImpl(BuildData buildData) {

setPriority(Priority.LOW);
setAlertType(AlertType.INFO);
this.eventName = "BuildAborted";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ public BuildFinishedEventImpl(BuildData buildData) {
setPriority(Priority.NORMAL);
setAlertType(AlertType.WARNING);
}

this.eventName = "BuildCompleted";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ of this software and associated documentation files (the "Software"), to deal
* the right message for Datadog.
*/
public class BuildStartedEventImpl extends AbstractDatadogBuildEvent {

public BuildStartedEventImpl(BuildData buildData) {
super(buildData);

Expand All @@ -55,5 +55,7 @@ public BuildStartedEventImpl(BuildData buildData) {

setPriority(Priority.LOW);
setAlertType(AlertType.INFO);

this.eventName = "BuildStarted";
dawitgirm marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ public ComputerLaunchFailedEventImpl(Computer computer, TaskListener listener, M

setPriority(Priority.NORMAL);
setAlertType(AlertType.ERROR);

this.eventName = "ComputerLaunchFailure";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ of this software and associated documentation files (the "Software"), to deal

public class ComputerOfflineEventImpl extends AbstractDatadogSimpleEvent {

private boolean isTemporarily;

public ComputerOfflineEventImpl(Computer computer, OfflineCause cause, Map<String, Set<String>> tags, boolean isTemporarily) {
super(tags);
String nodeName = DatadogUtilities.getNodeName(computer);
Expand All @@ -49,5 +51,12 @@ public ComputerOfflineEventImpl(Computer computer, OfflineCause cause, Map<Strin

setPriority(Priority.NORMAL);
setAlertType(AlertType.WARNING);

this.isTemporarily = isTemporarily;
this.eventName = "Computer" + (isTemporarily ? "Temporarily" : "") + "Offline";
}

public boolean isTemporarily() {
return this.isTemporarily;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ of this software and associated documentation files (the "Software"), to deal

public class ComputerOnlineEventImpl extends AbstractDatadogSimpleEvent {

private boolean isTemporarily;

public ComputerOnlineEventImpl(Computer computer, TaskListener listener, Map<String, Set<String>> tags, boolean isTemporarily) {
super(tags);

Expand All @@ -49,5 +51,12 @@ public ComputerOnlineEventImpl(Computer computer, TaskListener listener, Map<Str

setPriority(Priority.LOW);
setAlertType(AlertType.SUCCESS);

this.isTemporarily = isTemporarily;
this.eventName = "Computer" + (isTemporarily ? "Temporarily" : "") + "Online";
}

public boolean isTemporarily() {
return this.isTemporarily;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ItemCRUDEventImpl extends AbstractDatadogSimpleEvent {
public final static String UPDATED = "Updated";
public final static String DELETED = "Deleted";

private String action;

public ItemCRUDEventImpl(Item item, String action, Map<String, Set<String>> tags) {
super(tags);

Expand All @@ -57,5 +59,12 @@ public ItemCRUDEventImpl(Item item, String action, Map<String, Set<String>> tags

setPriority(Priority.NORMAL);
setAlertType(AlertType.INFO);

this.action = action;
this.eventName = "Item" + this.action;
}

public String getAction() {
return this.action;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ public ItemCopiedEventImpl(Item src, Item item, Map<String, Set<String>> tags) {

setPriority(Priority.NORMAL);
setAlertType(AlertType.INFO);

this.eventName = "ItemCopied";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ public ItemLocationChangedEventImpl(Item item, String oldFullName, String newFul

setPriority(Priority.NORMAL);
setAlertType(AlertType.INFO);

this.eventName = "ItemLocationChanged";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ public SCMCheckoutCompletedEventImpl(BuildData buildData) {

setPriority(Priority.LOW);
setAlertType(AlertType.SUCCESS);

this.eventName = "SCMCheckout";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class UserAuthenticationEventImpl extends AbstractDatadogSimpleEvent {
public final static String ACCESS_DENIED = "failed to authenticate";
public final static String LOGOUT = "logout";

private String action;

public UserAuthenticationEventImpl(String username, String action, Map<String, Set<String>> tags) {
super(tags);
// Overriding tags set in parent class
Expand All @@ -62,6 +64,19 @@ public UserAuthenticationEventImpl(String username, String action, Map<String, S
setPriority(Priority.NORMAL);
setAlertType(AlertType.ERROR);
}

this.action = action;
this.eventName = "User";
if (action.equals(LOGIN)) {
this.eventName += "Authenticated";
} else if (action.equals(ACCESS_DENIED)) {
this.eventName += "FailedToAuthenticate";
} else if (action.equals(LOGOUT)) {
this.eventName += "LoggedOut";
}
}

public String getAction() {
return this.action;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void onStarted(Run run, TaskListener listener) {

// Send an event
DatadogEvent event = new BuildStartedEventImpl(buildData);
client.event(event);
if (DatadogUtilities.canSendEventToClient(event)) client.event(event);

// Send a metric
// item.getInQueueSince() may raise a NPE if a worker node is spinning up to run the job.
Expand Down Expand Up @@ -248,7 +248,7 @@ public void onCompleted(Run run, @Nonnull TaskListener listener) {

// Send an event
DatadogEvent event = new BuildFinishedEventImpl(buildData);
client.event(event);
if (DatadogUtilities.canSendEventToClient(event)) client.event(event);

// Send a metric
Map<String, Set<String>> tags = buildData.getTags();
Expand Down Expand Up @@ -415,7 +415,7 @@ public void onDeleted(Run run) {

// Send an event
DatadogEvent event = new BuildAbortedEventImpl(buildData);
client.event(event);
if (DatadogUtilities.canSendEventToClient(event)) client.event(event);

// Submit counter
Map<String, Set<String>> tags = buildData.getTags();
Expand Down
Loading