Skip to content

Commit

Permalink
changed all remining printstack to logger.error()
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed Mar 28, 2022
1 parent 6c39a08 commit 776fac5
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,10 @@ tasks.named('forbiddenApisMain').configure {
}

//Adds custom file that only has some of the checks for testApis checks since too many violations
// For example, we have to allow @Test to be used in test classes not inherited from LuceneTestCase.
// example: warning for every file: `Forbidden annotation use: org.junit.Test [defaultMessage Just name your test method testFooBar]`
//For example, we have to allow @Test to be used in test classes not inherited from LuceneTestCase.
//example: warning for every file: `Forbidden annotation use: org.junit.Test [defaultMessage Just name your test method testFooBar]`
forbiddenApisTest.setSignaturesFiles(files('src/forbidden/ad-test-signatures.txt'))

//removed jdk-system-out since we have e.printStackTrace() added at times for exception messages
forbiddenApisTest.setBundledSignatures(['jdk-deprecated', 'jdk-unsafe', 'jdk-non-portable'] as Set<String>)

// Allow test cases to be named Tests without having to be inherited from LuceneTestCase.
// see https://github.com/elastic/elasticsearch/blob/323f312bbc829a63056a79ebe45adced5099f6e6/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/TestingConventionsTasks.java
testingConventions.enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ protected List<Object> waitUntilTaskReachState(String detectorId, Set<String> ta
try {
adTaskProfile = getADTaskProfile(detectorId);
} catch (Exception e) {
e.printStackTrace();
logger.error("failed to get ADTaskProfile", e);
} finally {
Thread.sleep(1000);
}
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/opensearch/ad/cluster/HashRingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void testGetOwningNode() throws UnknownHostException {
// Circles for realtime AD will change as it's eligible to build for when its empty
assertEquals("Wrong hash ring size for realtime AD", 2, hashRing.getNodesWithSameAdVersion(Version.V_1_1_0, true).size());
}, e -> {
e.printStackTrace();
logger.error("building hash ring failed", e);
assertFalse("Build hash ring failed", true);
}));

Expand All @@ -166,7 +166,8 @@ public void testGetOwningNode() throws UnknownHostException {
// Circles for realtime AD will not change as it's eligible to rebuild
assertEquals("Wrong hash ring size for realtime AD", 2, hashRing.getNodesWithSameAdVersion(Version.V_1_1_0, true).size());
}, e -> {
e.printStackTrace();
logger.error("building hash ring failed", e);

assertFalse("Build hash ring failed", true);
}));

Expand All @@ -185,7 +186,7 @@ public void testGetOwningNode() throws UnknownHostException {
);
assertEquals("Wrong hash ring size for realtime AD", 4, hashRing.getNodesWithSameAdVersion(Version.V_1_1_0, true).size());
}, e -> {
e.printStackTrace();
logger.error("building hash ring failed", e);
assertFalse("Failed to build hash ring", true);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private double[] getTestResults(
}
} catch (Exception e) {
errors++;
e.printStackTrace();
logger.error("failed to get detection results", e);
}
}
return new double[] { positives, truePositives, positiveAnomalies.size(), errors };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected void doExecute(Task task, UpdateByQueryRequest request, ActionListener
false
);
} catch (IOException exception) {
exception.printStackTrace();
logger.error(exception);
}
listener.onResponse(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void doExecute(Task task, UpdateByQueryRequest request, ActionListener
false
);
} catch (IOException exception) {
exception.printStackTrace();
logger.error(exception);
}
listener.onResponse(response);
}
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/opensearch/ad/rest/ADRestTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import org.apache.http.HttpHeaders;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.opensearch.ad.AbstractADTest;
import org.opensearch.ad.TestHelpers;
import org.opensearch.ad.mock.model.MockSimpleLog;
import org.opensearch.ad.model.ADTask;
Expand All @@ -50,6 +53,7 @@

//TODO: remove duplicate code in HistoricalAnalysisRestTestCase
public class ADRestTestUtils {
protected static final Logger LOG = (Logger) LogManager.getLogger(ADRestTestUtils.class);
public enum DetectorType {
SINGLE_ENTITY_DETECTOR,
SINGLE_CATEGORY_HC_DETECTOR,
Expand Down Expand Up @@ -472,7 +476,7 @@ public static ADTaskProfile waitUntilTaskReachState(RestClient client, String de
try {
adTaskProfile = getADTaskProfile(client, detectorId);
} catch (Exception e) {
e.printStackTrace();
LOG.error("failed to get ADTaskProfile", e);
} finally {
Thread.sleep(1000);
}
Expand Down

0 comments on commit 776fac5

Please sign in to comment.