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

Refactor classes and improve build checks #1017

Merged
merged 1 commit into from
Sep 6, 2023
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
4 changes: 4 additions & 0 deletions .github/workflows/test_build_multi_platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
java: [ 11, 17, 20 ]
name: Build and Test Anomaly Detection Plugin on Windows
runs-on: windows-latest
env:
JENKINS_URL: build.ci.opensearch.org
steps:
- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v1
Expand Down Expand Up @@ -45,6 +47,8 @@ jobs:

name: Build and Test Anomaly detection Plugin
runs-on: ${{ matrix.os }}
env:
JENKINS_URL: build.ci.opensearch.org

steps:
- name: Setup Java ${{ matrix.java }}
Expand Down
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.Callable
import org.opensearch.gradle.test.RestIntegTestTask
import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask
import org.opensearch.gradle.info.BuildParams

buildscript {
ext {
Expand Down Expand Up @@ -67,8 +68,7 @@ plugins {
id 'com.netflix.nebula.ospackage' version "11.0.0"
id "com.diffplug.spotless" version "6.18.0"
id 'java-library'
// Gradle 7.6 support was added in test-retry 1.4.0.
id 'org.gradle.test-retry' version '1.4.1'
id 'org.gradle.test-retry' version '1.5.4'
}

tasks.withType(JavaCompile) {
Expand Down Expand Up @@ -286,14 +286,13 @@ def _numNodes = findProperty('numNodes') as Integer ?: 1

def opensearch_tmp_dir = rootProject.file('build/private/opensearch_tmp').absoluteFile
opensearch_tmp_dir.mkdirs()
boolean isCiServer = System.getenv().containsKey("CI")
test {
retry {
if (isCiServer) {
failOnPassedAfterRetry = false
if (BuildParams.isCi()) {
maxRetries = 6
maxFailures = 10
}
failOnPassedAfterRetry = false
}
include '**/*Tests.class'
systemProperty 'tests.security.manager', 'false'
Expand All @@ -314,11 +313,11 @@ tasks.named("check").configure { dependsOn(integTest) }

integTest {
retry {
if (isCiServer) {
failOnPassedAfterRetry = false
if (BuildParams.isCi()) {
maxRetries = 6
maxFailures = 10
}
failOnPassedAfterRetry = false
}
dependsOn "bundlePlugin"
systemProperty 'tests.security.manager', 'false'
Expand Down Expand Up @@ -367,6 +366,7 @@ integTest {
getClusters().forEach { cluster ->
cluster.waitForAllConditions()
}
println 'Running in CI mode:' + BuildParams.isCi()
}

// The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/opensearch/ad/AnomalyDetectorProfileRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

package org.opensearch.ad;

import static org.opensearch.ad.constant.ADCommonMessages.FAIL_TO_PARSE_DETECTOR_MSG;
import static org.opensearch.core.rest.RestStatus.BAD_REQUEST;
import static org.opensearch.core.rest.RestStatus.INTERNAL_SERVER_ERROR;
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.opensearch.timeseries.constant.CommonMessages.FAIL_TO_FIND_CONFIG_MSG;
import static org.opensearch.timeseries.constant.CommonMessages.FAIL_TO_PARSE_CONFIG_MSG;

import java.util.List;
import java.util.Map;
Expand All @@ -30,7 +30,6 @@
import org.opensearch.action.get.GetRequest;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.ad.constant.ADCommonMessages;
import org.opensearch.ad.constant.ADCommonName;
import org.opensearch.ad.model.ADTaskType;
import org.opensearch.ad.model.AnomalyDetector;
Expand Down Expand Up @@ -66,6 +65,7 @@
import org.opensearch.timeseries.AnalysisType;
import org.opensearch.timeseries.common.exception.NotSerializedExceptionName;
import org.opensearch.timeseries.common.exception.ResourceNotFoundException;
import org.opensearch.timeseries.constant.CommonMessages;
import org.opensearch.timeseries.constant.CommonName;
import org.opensearch.timeseries.model.IntervalTimeConfiguration;
import org.opensearch.timeseries.model.Job;
Expand Down Expand Up @@ -110,7 +110,7 @@ public AnomalyDetectorProfileRunner(

public void profile(String detectorId, ActionListener<DetectorProfile> listener, Set<DetectorProfileName> profilesToCollect) {
if (profilesToCollect.isEmpty()) {
listener.onFailure(new IllegalArgumentException(ADCommonMessages.EMPTY_PROFILES_COLLECT));
listener.onFailure(new IllegalArgumentException(CommonMessages.EMPTY_PROFILES_COLLECT));
return;
}
calculateTotalResponsesToWait(detectorId, profilesToCollect, listener);
Expand All @@ -133,8 +133,8 @@ private void calculateTotalResponsesToWait(
AnomalyDetector detector = AnomalyDetector.parse(xContentParser, detectorId);
prepareProfile(detector, listener, profilesToCollect);
} catch (Exception e) {
logger.error(FAIL_TO_PARSE_DETECTOR_MSG + detectorId, e);
listener.onFailure(new OpenSearchStatusException(FAIL_TO_PARSE_DETECTOR_MSG + detectorId, BAD_REQUEST));
logger.error(FAIL_TO_PARSE_CONFIG_MSG + detectorId, e);
listener.onFailure(new OpenSearchStatusException(FAIL_TO_PARSE_CONFIG_MSG + detectorId, BAD_REQUEST));
}
} else {
listener.onFailure(new OpenSearchStatusException(FAIL_TO_FIND_CONFIG_MSG + detectorId, BAD_REQUEST));
Expand Down Expand Up @@ -208,7 +208,7 @@ private void prepareProfile(
new MultiResponsesDelegateActionListener<DetectorProfile>(
listener,
totalResponsesToWait,
ADCommonMessages.FAIL_FETCH_ERR_MSG + detectorId,
CommonMessages.FAIL_FETCH_ERR_MSG + detectorId,
false
);
if (profilesToCollect.contains(DetectorProfileName.ERROR)) {
Expand Down Expand Up @@ -267,7 +267,7 @@ private void prepareProfile(
}

} catch (Exception e) {
logger.error(ADCommonMessages.FAIL_TO_GET_PROFILE_MSG, e);
logger.error(CommonMessages.FAIL_TO_GET_PROFILE_MSG, e);
listener.onFailure(e);
}
} else {
Expand All @@ -278,7 +278,7 @@ private void prepareProfile(
logger.info(exception.getMessage());
onGetDetectorForPrepare(detectorId, listener, profilesToCollect);
} else {
logger.error(ADCommonMessages.FAIL_TO_GET_PROFILE_MSG + detectorId);
logger.error(CommonMessages.FAIL_TO_GET_PROFILE_MSG + detectorId);
listener.onFailure(exception);
}
}));
Expand All @@ -305,7 +305,7 @@ private void profileEntityStats(MultiResponsesDelegateActionListener<DetectorPro
DetectorProfile profile = profileBuilder.totalEntities(value).build();
listener.onResponse(profile);
}, searchException -> {
logger.warn(ADCommonMessages.FAIL_TO_GET_TOTAL_ENTITIES + detector.getId());
logger.warn(CommonMessages.FAIL_TO_GET_TOTAL_ENTITIES + detector.getId());
listener.onFailure(searchException);
});
// using the original context in listener as user roles have no permissions for internal operations like fetching a
Expand Down Expand Up @@ -359,7 +359,7 @@ private void profileEntityStats(MultiResponsesDelegateActionListener<DetectorPro
DetectorProfile profile = profileBuilder.totalEntities(Long.valueOf(compositeAgg.getBuckets().size())).build();
listener.onResponse(profile);
}, searchException -> {
logger.warn(ADCommonMessages.FAIL_TO_GET_TOTAL_ENTITIES + detector.getId());
logger.warn(CommonMessages.FAIL_TO_GET_TOTAL_ENTITIES + detector.getId());
listener.onFailure(searchException);
});
// using the original context in listener as user roles have no permissions for internal operations like fetching a
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/opensearch/ad/EntityProfileRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.opensearch.action.get.GetRequest;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.ad.constant.ADCommonMessages;
import org.opensearch.ad.constant.ADCommonName;
import org.opensearch.ad.model.AnomalyDetector;
import org.opensearch.ad.model.AnomalyResult;
Expand Down Expand Up @@ -92,7 +91,7 @@ public void profile(
ActionListener<EntityProfile> listener
) {
if (profilesToCollect == null || profilesToCollect.size() == 0) {
listener.onFailure(new IllegalArgumentException(ADCommonMessages.EMPTY_PROFILES_COLLECT));
listener.onFailure(new IllegalArgumentException(CommonMessages.EMPTY_PROFILES_COLLECT));
return;
}
GetRequest getDetectorRequest = new GetRequest(CommonName.CONFIG_INDEX, detectorId);
Expand Down Expand Up @@ -247,7 +246,7 @@ private void getJob(
new MultiResponsesDelegateActionListener<EntityProfile>(
listener,
totalResponsesToWait,
ADCommonMessages.FAIL_FETCH_ERR_MSG + entityValue + " of detector " + detectorId,
CommonMessages.FAIL_FETCH_ERR_MSG + entityValue + " of detector " + detectorId,
false
);

Expand Down Expand Up @@ -310,7 +309,7 @@ private void getJob(
}));
}
} catch (Exception e) {
logger.error(ADCommonMessages.FAIL_TO_GET_PROFILE_MSG, e);
logger.error(CommonMessages.FAIL_TO_GET_PROFILE_MSG, e);
listener.onFailure(e);
}
} else {
Expand All @@ -321,7 +320,7 @@ private void getJob(
logger.info(exception.getMessage());
sendUnknownState(profilesToCollect, entityValue, true, listener);
} else {
logger.error(ADCommonMessages.FAIL_TO_GET_PROFILE_MSG + detectorId, exception);
logger.error(CommonMessages.FAIL_TO_GET_PROFILE_MSG + detectorId, exception);
listener.onFailure(exception);
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

package org.opensearch.ad;

import static org.opensearch.ad.constant.ADCommonMessages.CAN_NOT_FIND_LATEST_TASK;
import static org.opensearch.timeseries.constant.CommonMessages.CAN_NOT_FIND_LATEST_TASK;

import java.time.Instant;
import java.util.ArrayList;
Expand Down
28 changes: 0 additions & 28 deletions src/main/java/org/opensearch/ad/constant/ADCommonMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ public class ADCommonMessages {
public static final String FEATURE_NOT_AVAILABLE_ERR_MSG = "No Feature in current detection window.";
public static final String DISABLED_ERR_MSG =
"AD functionality is disabled. To enable update plugins.anomaly_detection.enabled to true";
public static String FAIL_TO_PARSE_DETECTOR_MSG = "Fail to parse detector with id: ";
public static String FAIL_TO_GET_PROFILE_MSG = "Fail to get profile for detector ";
public static String FAIL_TO_GET_TOTAL_ENTITIES = "Failed to get total entities for detector ";
public static String CATEGORICAL_FIELD_NUMBER_SURPASSED = "We don't support categorical fields more than ";
public static String EMPTY_PROFILES_COLLECT = "profiles to collect are missing or invalid";
public static String FAIL_FETCH_ERR_MSG = "Fail to fetch profile for ";
public static String DETECTOR_IS_RUNNING = "Detector is already running";
public static String DETECTOR_MISSING = "Detector is missing";
public static String AD_TASK_ACTION_MISSING = "AD task action is missing";
Expand All @@ -41,41 +36,18 @@ public class ADCommonMessages {
public static String EXCEED_HISTORICAL_ANALYSIS_LIMIT = "Exceed max historical analysis limit per node";
public static String NO_ELIGIBLE_NODE_TO_RUN_DETECTOR = "No eligible node to run detector ";
public static String EMPTY_STALE_RUNNING_ENTITIES = "Empty stale running entities";
public static String CAN_NOT_FIND_LATEST_TASK = "can't find latest task";
public static String NO_ENTITY_FOUND = "No entity found";
public static String HISTORICAL_ANALYSIS_CANCELLED = "Historical analysis cancelled by user";
public static String HC_DETECTOR_TASK_IS_UPDATING = "HC detector task is updating";
public static String INVALID_TIME_CONFIGURATION_UNITS = "Time unit %s is not supported";
public static String FAIL_TO_GET_DETECTOR = "Fail to get detector";
public static String FAIL_TO_GET_DETECTOR_INFO = "Fail to get detector info";
public static String FAIL_TO_CREATE_DETECTOR = "Fail to create detector";
public static String FAIL_TO_UPDATE_DETECTOR = "Fail to update detector";
public static String FAIL_TO_PREVIEW_DETECTOR = "Fail to preview detector";
public static String FAIL_TO_START_DETECTOR = "Fail to start detector";
public static String FAIL_TO_STOP_DETECTOR = "Fail to stop detector";
public static String FAIL_TO_DELETE_DETECTOR = "Fail to delete detector";
public static String FAIL_TO_DELETE_AD_RESULT = "Fail to delete anomaly result";
public static String FAIL_TO_GET_STATS = "Fail to get stats";
public static String FAIL_TO_SEARCH = "Fail to search";

public static String WINDOW_DELAY_REC =
"Latest seen data point is at least %d minutes ago, consider changing window delay to at least %d minutes.";
public static String TIME_FIELD_NOT_ENOUGH_HISTORICAL_DATA =
"There isn't enough historical data found with current timefield selected.";
public static String DETECTOR_INTERVAL_REC =
"The selected detector interval might collect sparse data. Consider changing interval length to: ";
public static String RAW_DATA_TOO_SPARSE =
"Source index data is potentially too sparse for model training. Consider changing interval length or ingesting more data";
public static String MODEL_VALIDATION_FAILED_UNEXPECTEDLY = "Model validation experienced issues completing.";
public static String FILTER_QUERY_TOO_SPARSE = "Data is too sparse after data filter is applied. Consider changing the data filter";
public static String CATEGORY_FIELD_TOO_SPARSE =
"Data is most likely too sparse with the given category fields. Consider revising category field/s or ingesting more data ";
public static String CATEGORY_FIELD_NO_DATA =
"No entity was found with the given categorical fields. Consider revising category field/s or ingesting more data";
public static String FEATURE_QUERY_TOO_SPARSE =
"Data is most likely too sparse when given feature queries are applied. Consider revising feature queries.";
public static String TIMEOUT_ON_INTERVAL_REC = "Timed out getting interval recommendation";

public static final String NO_MODEL_ERR_MSG = "No RCF models are available either because RCF"
+ " models are not ready or all nodes are unresponsive or the system might have bugs.";
public static String INVALID_RESULT_INDEX_PREFIX = "Result index must start with " + CUSTOM_RESULT_INDEX_PREFIX;
Expand Down
Loading
Loading