Skip to content
Permalink
Browse files
IGNITE-11947: More debug information added to locate problem with not…
…ification
  • Loading branch information
dspavlov committed Jul 1, 2019
1 parent 72f53ef commit ab47aab84ff6c13269433215f6d2d84a6c0736f4
Showing 5 changed files with 74 additions and 9 deletions.
@@ -20,6 +20,7 @@
import com.google.common.base.MoreObjects;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -30,14 +31,14 @@
import org.jetbrains.annotations.Nullable;

/**
*
* Issue used both for saving into DB and in UI (in issue history).
*/
@SuppressWarnings("WeakerAccess")
@SuppressWarnings({"WeakerAccess", "PublicField"})
@Persisted
public class Issue {
/** Type code. Null of older versions of issue */
@Nullable
private String type;
public String type;

/** Display type. for issue. Kept for backward compatibilty with older records without type code. */
private String displayType;
@@ -66,6 +67,8 @@ public class Issue {
/** Set of build tags detected. */
public Set<String> buildTags = new TreeSet<>();

public java.util.Map<String, Integer> stat = new HashMap<>();

public Issue(IssueKey issueKey, IssueType type,
@Nullable Long buildStartTs) {
this.issueKey = issueKey;
@@ -17,6 +17,7 @@

package org.apache.ignite.ci.issue;

import java.util.HashMap;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.cache.Cache;
@@ -65,6 +66,24 @@ public static IgniteCache<IssueKey, Issue> botDetectedIssuesCache(Ignite ignite)
return add;
}

@Override
public void saveIssueSubscribersStat(IssueKey issueKey, int cntSrvAllowed, int cntSubscribed,
int cntTagsFilterPassed) {
Issue issue = cache().get(issueKey);
if (issue == null)
return;

if (issue.stat == null)
issue.stat = new HashMap<>();

issue.stat.put("cntSrvAllowed", cntSrvAllowed);
issue.stat.put("cntSubscribed", cntSubscribed);
issue.stat.put("cntTagsFilterPassed", cntTagsFilterPassed);

cache().put(issueKey, issue);

}

/** {@inheritDoc} */
@Override public boolean containsIssueKey(IssueKey issueKey) {
return cache().containsKey(issueKey);
@@ -41,4 +41,6 @@ public interface IIssuesStorage {
* @return update successful. This address was not notified before.
*/
public boolean setNotified(IssueKey key, String addr);

public void saveIssueSubscribersStat(IssueKey key, int cntSrvAllowed, int cntSubscribed, int cntTagsFilterPassed);
}
@@ -149,6 +149,11 @@ protected String sendNewNotificationsEx() throws IOException {
Map<String, Notification> toBeSent = new HashMap<>();

AtomicInteger issuesChecked = new AtomicInteger();
AtomicInteger filteredFresh = new AtomicInteger();
AtomicInteger filteredBuildTs = new AtomicInteger();
AtomicInteger filteredNotDisabled = new AtomicInteger();
AtomicInteger hasSubscriptions = new AtomicInteger();
AtomicInteger neverSentBefore = new AtomicInteger();

issuesStorage.allIssues()
.peek(issue -> issuesChecked.incrementAndGet())
@@ -163,6 +168,7 @@ protected String sendNewNotificationsEx() throws IOException {

return issueAgeMs <= bound;
})
.peek(issue -> filteredFresh.incrementAndGet())
.filter(issue -> {
if (issue.buildStartTs == null)
return true; // exception due to bug in issue detection; field was not filled
@@ -173,31 +179,40 @@ protected String sendNewNotificationsEx() throws IOException {

return buildAgeMs <= maxBuildAgeToNotify;
})
.peek(issue -> filteredBuildTs.incrementAndGet())
.filter(issue -> {
return cfg.getTrackedBranches()
.get(issue.trackedBranchName)
.filter(tb -> !tb.disableIssueTypes().contains(issue.type()))
.isPresent();
})
.peek(issue -> filteredNotDisabled.incrementAndGet())
.forEach(issue -> {
List<String> addrs = new ArrayList<>();

final String srvCode = issue.issueKey().server;

AtomicInteger ctnSrvAllowed = new AtomicInteger();
AtomicInteger cntSubscibed = new AtomicInteger();
AtomicInteger cntTagsFilterPassed = new AtomicInteger();

channels.stream()
.filter(ch -> ch.isServerAllowed(srvCode))
.peek(ch -> ctnSrvAllowed.incrementAndGet())
.filter(ch -> ch.isSubscribedToBranch(issue.trackedBranchName))
.peek(ch -> cntSubscibed.incrementAndGet())
.filter(ch -> {
if (ch.hasTagFilter())
return issue.buildTags().stream().anyMatch(ch::isSubscribedToTag);

return true;
})
.peek(ch -> cntTagsFilterPassed.incrementAndGet())
.forEach(channel -> {
String email = channel.email();
String slack = channel.slack();
logger.info("User/channel " + channel + " is candidate for notification " + email
+ " , " + slack + "for " + issue);
+ " , " + slack + " for " + issue);

if (!Strings.isNullOrEmpty(email))
addrs.add(email);
@@ -206,8 +221,14 @@ protected String sendNewNotificationsEx() throws IOException {
addrs.add(SLACK + slack);
});

if(!addrs.isEmpty())
hasSubscriptions.incrementAndGet();

boolean nonNotifedFound = false;
for (String nextAddr : addrs) {
if (issuesStorage.setNotified(issue.issueKey, nextAddr)) {
nonNotifedFound = true;

toBeSent.computeIfAbsent(nextAddr, addr -> {
Notification notification = new Notification();
notification.ts = System.currentTimeMillis();
@@ -216,11 +237,23 @@ protected String sendNewNotificationsEx() throws IOException {
}).addIssue(issue);
}
}
if (!nonNotifedFound)
issuesStorage.saveIssueSubscribersStat(issue.issueKey, ctnSrvAllowed.get(),
cntSubscibed.get(), cntTagsFilterPassed.get());

if (nonNotifedFound)
neverSentBefore.incrementAndGet();
});

if (toBeSent.isEmpty())
return "Noting to notify, " + issuesChecked + " issues checked";
String stat = issuesChecked.get() + " issues checked " +
filteredFresh.get() + " detected recenty " +
filteredBuildTs.get() + " for fresh builds " +
filteredNotDisabled.get() + " not disabled " +
hasSubscriptions.get() + " has subscriber " +
neverSentBefore.get() + " non notified";

if (toBeSent.isEmpty())
return "Noting to notify, " + stat;
NotificationsConfig notifications = cfg.notifications();

StringBuilder res = new StringBuilder();
@@ -248,7 +281,7 @@ protected String sendNewNotificationsEx() throws IOException {
}
}

return res + ", " + issuesChecked.get() + "issues checked";
return res + ", " + stat;
}

/**
@@ -19,12 +19,15 @@
function showIssues(result) {
var res = "";
res += "Build problems";
res += "<br>";

if (!isDefinedAndFilled(result.issues)) {
return res;
}

res += " " + result.issues.length;

res += "<br>";

for (var i = 0; i < result.issues.length; i++) {
var issue = result.issues[i];

@@ -46,7 +49,12 @@ function showIssues(result) {
}
res += "]";
}
res += " br=" + issue.trackedBranchName + "bID=" + issue.issueKey.buildId;
res += " tbr=" + issue.trackedBranchName + " bID=" + issue.issueKey.buildId;

if(isDefinedAndFilled(issue.stat)) {
res += " stat=";
res += JSON.stringify(issue.stat);
}

res += "<br><br>";
}

0 comments on commit ab47aab

Please sign in to comment.