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

[GP-4245] Debug logging for jira client #1290

Merged
merged 7 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 changes/fix_jira-logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Additional server logging for jira errors

Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void labels(Set<String> labels) {
public ActionState perform(
ActionServices services, Duration lastGeneratedByOlive, boolean isOliveLive) {
if (connection == null) {
System.err.println("JIRA Connection for " + issueUrl + " is null.");
return ActionState.FAILED;
}
final var current = connection.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public ActionState perform(
.orElse(false)) {
bestMatch.accept(issue);
if (!connection.transition(issue, Stream::anyMatch, comment)) {
StringBuilder errorBuilder = new StringBuilder();
errorBuilder
.append("Unable to transition issue ")
.append(issue.getKey())
.append("\nConnection: ")
.append(connection);
System.err.println(errorBuilder);
return ActionState.FAILED;
}
}
Expand All @@ -68,6 +75,11 @@ public boolean search(Pattern query) {
public String verb() {
return "Close";
}

@Override
public String toString() {
return "Close JIRA Issue with comment " + comment;
}
}

public static class Open extends IssueVerb {
Expand Down Expand Up @@ -149,6 +161,19 @@ public boolean search(Pattern query) {
public String verb() {
return "Open";
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut
.append("Re/open JIRA Issue with description '")
.append(description)
.append("', reopen with comment '")
.append(comment)
.append("'");
assignee.ifPresent(s -> writeOut.append(", with assignee '").append(s));
return writeOut.toString();
}
}

public abstract ActionState perform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ public <F> Stream<Pair<String, F>> searches(
.flatMap(
search ->
search
.getType()
.type()
.join(
search.getName(),
search.getFilter().convert(builder),
search.name(),
search.filter().convert(builder),
issues
.get(search.getJql())
.get(search.jql())
.flatMap(
issue -> {
final var assignee =
Expand Down Expand Up @@ -444,16 +444,26 @@ boolean transition(
authenticationHeader.ifPresent(
header -> commentRequestBuilder.header("Authorization", header));

return CLIENT
.send(
commentRequestBuilder
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(MAPPER.writeValueAsString(updateComment)))
.build(),
BodyHandlers.discarding())
.statusCode()
/ 100
== 2;
var result =
CLIENT.send(
commentRequestBuilder
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(MAPPER.writeValueAsString(updateComment)))
.build(),
BodyHandlers.ofString());
boolean isGood = result.statusCode() / 100 == 2;
if (!isGood) {
StringBuilder errorBuilder = new StringBuilder();
errorBuilder
.append("Unable to transition issue ")
.append(issue.getKey())
.append(" using any of ")
.append(transitions)
.append("\nGot ")
.append(result.body());
System.err.println(errorBuilder);
}
return isGood;
}
}
return false;
Expand Down Expand Up @@ -506,4 +516,34 @@ public Optional<Integer> update(Configuration config) {
public String url() {
return url;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut
.append("JiraConnection with closedStatuses = ")
.append(closedStatuses)
.append(", defaultFieldValues = ")
.append(defaultFieldValues.entrySet())
.append(", definer = ")
.append(definer)
.append(", issueTypeId = ")
.append(issueTypeId)
.append(", issueTypeName = ")
.append(issueTypeName)
.append(", cached issues = ")
.append(issues)
.append(", projectId = ")
.append(projectId)
.append(", projectKey = ")
.append(projectKey)
.append(", searches = ")
.append(searches)
.append(", url = ")
.append(url)
.append(", version = ")
.append(version);
authenticationHeader.ifPresent(s -> writeOut.append(", authenticationHeader = ").append(s));
return writeOut.toString();
}
}
39 changes: 1 addition & 38 deletions plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,4 @@

import ca.on.oicr.gsi.shesmu.plugin.filter.ActionFilter;

public final class Search {
private ActionFilter filter;
private String jql;
private String name;
private JoiningRule type;

public ActionFilter getFilter() {
return filter;
}

public String getJql() {
return jql;
}

public String getName() {
return name;
}

public JoiningRule getType() {
return type;
}

public void setFilter(ActionFilter filter) {
this.filter = filter;
}

public void setJql(String jql) {
this.jql = jql;
}

public void setName(String name) {
this.name = name;
}

public void setType(JoiningRule type) {
this.type = type;
}
}
public record Search(ActionFilter filter, String jql, String name, JoiningRule type) {}
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,23 @@ public final void ttl(int ttl) {
this.ttl = ttl;
ttlValue.labels(name).set(ttl);
}

public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut
.append(this.getClass())
.append(" with CACHES = ")
.append(CACHES.entrySet())
.append(", maxCount = ")
.append(maxCount)
.append(", name = ")
.append(name)
.append(", recordFactory = ")
.append(recordFactory)
.append(", records = ")
.append(records.entrySet())
.append(", ttl = ")
.append(ttl);
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ public List<String> getIds() {
public void setIds(List<String> ids) {
this.ids = ids;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append("Action filter for action identifier: ").append(ids);
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public class ActionFilterOrphaned extends ActionFilter {
public <F> F convert(ActionFilterBuilder<F, ActionState, String, Instant, Long> filterBuilder) {
return filterBuilder.orphaned();
}

@Override
public String toString() {
return "Action filter for orphaned actions";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ public void setMatchCase(boolean matchCase) {
public void setPattern(String pattern) {
this.pattern = pattern;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append("Text matching regex filter of pattern: '").append(pattern).append("'");
if (!matchCase) writeOut.append(" not");
writeOut.append(" matching case");
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.on.oicr.gsi.shesmu.plugin.action.ActionState;
import java.time.Instant;
import java.util.Arrays;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -32,4 +33,11 @@ public String[] getFiles() {
public void setFiles(String[] files) {
this.files = files;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append("Source file action filter for file: ").append(Arrays.toString(files));
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.on.oicr.gsi.shesmu.plugin.action.ActionState;
import java.time.Instant;
import java.util.Arrays;
import java.util.stream.Stream;

/** An action filter that checks if an action comes from a particular olive definition */
Expand Down Expand Up @@ -30,4 +31,13 @@ public SourceOliveLocation[] getLocations() {
public void setLocations(SourceOliveLocation[] locations) {
this.locations = locations;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut
.append("Source location action filter for location: ")
.append(Arrays.toString(locations));
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.on.oicr.gsi.shesmu.plugin.action.ActionState;
import java.time.Instant;
import java.util.Arrays;
import java.util.stream.Stream;

/** An action filter that checks for actions in a particular state */
Expand Down Expand Up @@ -30,4 +31,11 @@ public ActionState[] getStates() {
public void setState(ActionState[] states) {
this.states = states;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append("Action state filter for state: ").append(Arrays.toString(states));
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.on.oicr.gsi.shesmu.plugin.action.ActionState;
import java.time.Instant;
import java.util.Arrays;
import java.util.stream.Stream;

/** An action filter that checks if an action has a particular tag associated with it */
Expand Down Expand Up @@ -30,4 +31,11 @@ public String[] getTags() {
public void setTags(String[] tags) {
this.tags = tags;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append("Tag filter for tags: ").append(Arrays.toString(tags));
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public void setMatchCase(boolean matchCase) {
public void setPattern(String pattern) {
this.pattern = pattern;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append("Tag matching regex filter of pattern: '").append(pattern).append("'");
if (!matchCase) writeOut.append(" not");
writeOut.append(" matching case");
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@ public void setMatchCase(boolean matchCase) {
public void setText(String text) {
this.text = text;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append("Text action filter for text: '").append(text).append("'");
if (!matchCase) writeOut.append(" not");
writeOut.append(" matching case");
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.on.oicr.gsi.shesmu.plugin.action.ActionState;
import java.time.Instant;
import java.util.Arrays;
import java.util.stream.Stream;

/** Action filter to check an action's type */
Expand Down Expand Up @@ -30,4 +31,11 @@ public String[] getTypes() {
public void setTypes(String[] types) {
this.types = types;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append("Action type filter of types: ").append(Arrays.toString(types));
return writeOut.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ public final long getOffset() {
public final void setOffset(long offset) {
this.offset = offset;
}

@Override
public String toString() {
StringBuilder writeOut = new StringBuilder();
writeOut.append(this.getClass()).append(" type filter of offset: ").append(offset);
return writeOut.toString();
}
}
Loading