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

Expose model accuracy metrics in tests #600

Merged
merged 2 commits into from
Jun 29, 2022
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: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
ls ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/$plugin_version
- name: Build and Run Tests
run: |
./gradlew build
./gradlew build -Dtest.logs=true
- name: Publish to Maven Local
run: |
./gradlew publishToMavenLocal
Expand Down
20 changes: 20 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ buildscript {
'opendistro-anomaly-detection/opendistro-anomaly-detection-1.13.0.0.zip'
bwcOpenDistroJSDownload = 'https://d3g5vo6xdbdb9a.cloudfront.net/downloads/elasticsearch-plugins/' +
'opendistro-job-scheduler/opendistro-job-scheduler-1.13.0.0.zip'
// gradle build won't print logs during test by default unless there is a failure.
// It is useful to record intermediately information like prediction precision and recall.
// This option turn on log printing during tests.
printLogs = "true" == System.getProperty("test.logs", "false")
}

repositories {
Expand Down Expand Up @@ -269,6 +273,12 @@ integTest {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
}

if (printLogs) {
testLogging {
showStandardStreams = true
outputs.upToDateWhen {false}
}
}
}

testClusters.integTest {
Expand Down Expand Up @@ -779,3 +789,13 @@ validateNebulaPom.enabled = false
tasks.withType(licenseHeaders.class) {
additionalLicense 'AL ', 'Apache', 'Licensed under the Apache License, Version 2.0 (the "License")'
}

// show test results so that we can record information like precion/recall results of correctness testing.
if (printLogs) {
test {
testLogging {
showStandardStreams = true
outputs.upToDateWhen {false}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Compatible with OpenSearch 2.1.0

* bump rcf to 3.0-rc3 ([#568](https://github.com/opensearch-project/anomaly-detection/pull/568))
* Disable interpolation in HCAD cold start ([#575](https://github.com/opensearch-project/anomaly-detection/pull/575))
* Expose model accuracy metrics in tests ([#600](https://github.com/opensearch-project/anomaly-detection/pull/600))

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private void verifyTestResults(
assertTrue(recall >= minRecall);

assertTrue(errors <= maxError);
LOG.info("Precision: {}, Window recall: {}", precision, recall);
}

private int isAnomaly(Instant time, List<Entry<Instant, Instant>> labels) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ public int compare(Entry<Long, Long> p1, Entry<Long, Long> p2) {

assertTrue("precision is " + prec, prec >= precisionThreshold);
assertTrue("recall is " + recall, recall >= recallThreshold);
LOG.info("Interval {}, Precision: {}, recall: {}", detectorIntervalMins, prec, recall);
}

public int searchInsert(long[] timestamps, long target) {
Expand Down