Skip to content
Permalink
Browse files
IGNITE-11947: Extracting heuristics into constants
  • Loading branch information
dspavlov committed Jul 2, 2019
1 parent a4433f3 commit 26622f3f5b9b65e51dad637b2fc745ded898daea
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 13 deletions.
@@ -42,9 +42,9 @@
import org.apache.ignite.ci.tcbot.user.IUserStorage;
import org.apache.ignite.ci.teamcity.ignited.change.ChangeCompacted;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted;
import org.apache.ignite.ci.teamcity.ignited.runhist.InvocationData;
import org.apache.ignite.ci.user.ITcBotUserCreds;
import org.apache.ignite.ci.user.TcHelperUser;
import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.common.interceptor.AutoProfiling;
import org.apache.ignite.tcbot.common.interceptor.MonitoredTask;
import org.apache.ignite.tcbot.engine.conf.INotificationChannel;
@@ -160,7 +160,15 @@ protected String sendNewNotificationsEx() {
long detected = issue.detectedTs == null ? 0 : issue.detectedTs;
long issueAgeMs = System.currentTimeMillis() - detected;

long bound = TimeUnit.HOURS.toMillis(2);
//here boundary can be not an absolute, but some ts when particular notification channel config was changed
// alternatively boundary may depend to issue notification histroy

boolean neverNotified = issue.addressNotified == null || issue.addressNotified.isEmpty();
// if issue had a prior notification, limit age by 2 hours to avoid new addresses spamming.
// otherwise check last day issues if it is notifiable
long bound = TimeUnit.HOURS.toMillis(neverNotified
? TcBotConst.NOTIFY_MAX_AGE_SINCE_DETECT_HOURS
: TcBotConst.NOTIFY_MAX_AGE_SINCE_DETECT_FOR_NOTIFIED_ISSUE_HOURS );

return issueAgeMs <= bound;
})
@@ -171,7 +179,7 @@ protected String sendNewNotificationsEx() {

long buildStartTs = issue.buildStartTs == null ? 0 : issue.buildStartTs;
long buildAgeMs = System.currentTimeMillis() - buildStartTs;
long maxBuildAgeToNotify = TimeUnit.DAYS.toMillis(InvocationData.MAX_DAYS) / 2;
long maxBuildAgeToNotify = TimeUnit.DAYS.toMillis(TcBotConst.NOTIFY_MAX_AGE_SINCE_START_DAYS) / 2;

return buildAgeMs <= maxBuildAgeToNotify;
})
@@ -28,6 +28,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.engine.pr.PrChainsProcessor;
import org.apache.ignite.tcservice.ITeamcity;
import org.apache.ignite.tcservice.model.conf.BuildType;
@@ -222,7 +223,7 @@ public Map<Integer, FatBuildCompacted> initHistory(IStringCompactor c) {
addBuildsToEmulatedStor(cache1InMaster);
}

long ageMs = TimeUnit.DAYS.toMillis(InvocationData.MAX_DAYS);
long ageMs = TimeUnit.DAYS.toMillis(TcBotConst.HISTORY_MAX_DAYS);

for (int i = 0; i < 134; i++) {
addBuildsToEmulatedStor(createFailedBuild(c, CACHE_1,
@@ -179,7 +179,7 @@ public static void initHistory(IStringCompactor c, Map<RunHistKey, RunHistCompac

Invocation inv = testCompacted.toInvocation(build, (k, v) -> true, successStatusStrId);

hist.addInvocation(inv);
hist.innerAddInvocation(inv);
});
}

@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.tcbot.common;

/**
* TC Bot constants: contains magic numbers for project.
*
* Usually it is a practically set up rules, heuristics used by the bot.
*/
public class TcBotConst {
/** Max days to keep test invocatoin data in run statistics: affects Bot Visa. */
public static final int HISTORY_MAX_DAYS = 21;

/** History collection process: build id per server ID border days. */
public static final int HISTORY_BUILD_ID_BORDER_DAYS = HISTORY_MAX_DAYS + 2;

/** Notify about failure: max build age days (since build start time). */
public static final int NOTIFY_MAX_AGE_SINCE_START_DAYS = HISTORY_MAX_DAYS / 2;

/** */
public static final int NOTIFY_MAX_AGE_SINCE_DETECT_HOURS = 2;

/** */
public static final int NOTIFY_MAX_AGE_SINCE_DETECT_FOR_NOTIFIED_ISSUE_HOURS = 24;

/** Flakyness status change border: Count of test change status before considered as flaky. */
public static final int FLAKYNESS_STATUS_CHANGE_BORDER = 1;

/** Non flaky test failure rate: less that this failure rate in base branch is still blocker border, percents. */
public static final double NON_FLAKY_TEST_FAIL_RATE_BLOCKER_BORDER_PERCENTS = 4.;
}
@@ -23,6 +23,7 @@
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.TestCompacted;
import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.persistence.IStringCompactor;
import org.apache.ignite.tcignited.ITeamcityIgnited;
import org.apache.ignite.tcignited.history.IRunHistSummary;
@@ -102,7 +103,7 @@ public static String getPossibleBlockerComment(IRunHistSummary baseBranchStat) {
boolean flaky = baseBranchStat.isFlaky();

float failRate = baseBranchStat.getFailRate();
boolean lowFailureRate = failRate * 100.0f < 4.;
boolean lowFailureRate = failRate * 100.0f < TcBotConst.NON_FLAKY_TEST_FAIL_RATE_BLOCKER_BORDER_PERCENTS;

if (lowFailureRate && !flaky) {
String runStatPrintable = IRunStat.getPercentPrintable(failRate * 100.0f);
@@ -27,6 +27,7 @@
import java.util.stream.Stream;

import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.persistence.Persisted;
import org.apache.ignite.tcignited.history.RunStatus;

@@ -38,7 +39,7 @@
@Persisted
public class InvocationData {
/** Max days to keep test invocatoin data in run statistics: affects Bot Visa. */
public static final int MAX_DAYS = 21;
public static final int MAX_DAYS = TcBotConst.HISTORY_MAX_DAYS;
/** Muted. */
public static final int MUTED = RunStatus.RES_MUTED_FAILURE.getCode();
/** Failure. */
@@ -22,6 +22,7 @@
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.persistence.IVersionedEntity;
import org.apache.ignite.tcbot.persistence.Persisted;
import org.apache.ignite.tcignited.history.ChangesState;
@@ -36,7 +37,6 @@
public class RunHistCompacted implements IVersionedEntity, IRunHistory {
/** Latest version. */
private static final int LATEST_VERSION = 1;
public static final int FLAKYNESS_STATUS_CHANGE_BORDER = 1;

/** Entity fields version. */
@SuppressWarnings("FieldCanBeLocal")
@@ -92,7 +92,7 @@ public RunHistCompacted(RunHistKey ignored) {
@Override public String getFlakyComments() {
int statusChange = getStatusChangesWithoutCodeModification();

if (statusChange < FLAKYNESS_STATUS_CHANGE_BORDER)
if (statusChange < TcBotConst.FLAKYNESS_STATUS_CHANGE_BORDER)
return null;

return "Test seems to be flaky: " +
@@ -120,7 +120,7 @@ public int getStatusChangesWithoutCodeModification() {

/** {@inheritDoc} */
@Override public boolean isFlaky() {
return getStatusChangesWithoutCodeModification() >= FLAKYNESS_STATUS_CHANGE_BORDER;
return getStatusChangesWithoutCodeModification() >= TcBotConst.FLAKYNESS_STATUS_CHANGE_BORDER;
}

/** {@inheritDoc} */
@@ -132,6 +132,7 @@ public int getStatusChangesWithoutCodeModification() {
* @param inv Invocation.
* @return if test run is new and is not expired.
*/
@Deprecated
public boolean addInvocation(Invocation inv) {
return data.addInvocation(inv);
}
@@ -39,8 +39,8 @@
import org.apache.ignite.ci.teamcity.ignited.BuildRefCompacted;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.TestCompacted;
import org.apache.ignite.ci.teamcity.ignited.runhist.Invocation;
import org.apache.ignite.ci.teamcity.ignited.runhist.InvocationData;
import org.apache.ignite.ci.teamcity.ignited.runhist.RunHistKey;
import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.common.exeption.ExceptionUtil;
import org.apache.ignite.tcbot.common.interceptor.AutoProfiling;
import org.apache.ignite.tcbot.persistence.IStringCompactor;
@@ -176,7 +176,7 @@ protected Set<Integer> determineLatestBuilds(

long ageInDays = Duration.ofMillis(curTs - startTime).toDays();

if (ageInDays > InvocationData.MAX_DAYS + 2) {
if (ageInDays > TcBotConst.HISTORY_BUILD_ID_BORDER_DAYS) {
AtomicInteger integer = biggestBuildIdOutOfHistoryScope.computeIfAbsent(srvId,
s -> {
AtomicInteger atomicInteger = new AtomicInteger();
@@ -190,7 +190,7 @@ protected Set<Integer> determineLatestBuilds(
logger.info("History Collector: New border for server was set " + bId);
}

return ageInDays < InvocationData.MAX_DAYS;
return ageInDays < TcBotConst.HISTORY_MAX_DAYS;
}
).collect(Collectors.toSet());

@@ -72,6 +72,7 @@ public class RunHistCompactedDao {
private IgniteCache<RunHistKey, RunHistCompacted> testHistCache;

/** Suite history cache. */
@Deprecated
private IgniteCache<RunHistKey, RunHistCompacted> suiteHistCache;

/** Build start time. */
@@ -157,6 +158,7 @@ public boolean setBuildProcessed(int srvId, int buildId, long ts) {
}

@AutoProfiling
@Deprecated
public Integer addTestInvocations(RunHistKey histKey, List<Invocation> list) {
if (list.isEmpty())
return 0;
@@ -104,6 +104,7 @@ public static String normalizeBranch(@Nullable String branchName) {
* @param srvCode Server code (internal identification).
* @param build Build.
*/
@Deprecated
public void saveToHistoryLater(String srvCode, FatBuildCompacted build) {
if (!validForStatistics(build))
return;
@@ -201,6 +202,7 @@ protected String saveBuildToHistory(String srvName, int ldrToActivate) {
return saveInvocationsMap(buildsSaveThisRun, testsSaveThisRun);
}

@Deprecated
@AutoProfiling
@Nonnull protected String saveInvocationsMap(
Map<RunHistKey, List<Invocation>> buildsSaveThisRun,
@@ -259,6 +261,7 @@ protected String saveBuildToHistory(String srvName, int ldrToActivate) {
return res;
}

@Deprecated
private void saveInvocationList(Set<Integer> confirmedNewBuild,
Set<Integer> confirmedDuplicate,
AtomicInteger invocations,
@@ -297,6 +300,7 @@ private void saveInvocationList(Set<Integer> confirmedNewBuild,
duplicateOrExpired.addAndGet(invocationList.size() - cntAdded);
}

@Deprecated
public void invokeLaterFindMissingHistory(String srvName) {
scheduler.sheduleNamed(taskName("findMissingHistFromBuildRef", srvName),
() -> findMissingHistFromBuildRef(srvName), 12, TimeUnit.HOURS);
@@ -310,6 +314,7 @@ private String taskName(String taskName, String srvName) {
@SuppressWarnings({"WeakerAccess", "UnusedReturnValue"})
@MonitoredTask(name = "Find Missing Build History", nameExtArgsIndexes = {0})
@AutoProfiling
@Deprecated
protected String findMissingHistFromBuildRef(String srvId) {
int srvIdMaskHigh = ITeamcityIgnited.serverIdToInt(srvId);

@@ -342,6 +347,7 @@ protected String findMissingHistFromBuildRef(String srvId) {
* @param srvNme Server name;
* @param load Build IDs to be loaded into history cache later.
*/
@Deprecated
private void scheduleHistLoad(String srvNme, List<Integer> load) {
load.forEach(id -> {
FatBuildCompacted fatBuild = fatBuildDao.getFatBuild(ITeamcityIgnited.serverIdToInt(srvNme), id);

0 comments on commit 26622f3

Please sign in to comment.