Skip to content

Commit 4883d42

Browse files
committed
make timestamp more user friendly when reading
Signed-off-by: Jackie <jkhanjob@gmail.com>
1 parent 671e103 commit 4883d42

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

build.gradle

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ tasks.register('prepareJacocoAgent', Copy) {
220220
// to prevent duplicate -javaagent entries.
221221
tasks.named('test', Test) {
222222
// Disable Gradle's default Jacoco injection to avoid transient agent path issues
223-
jacoco.enabled = false
223+
jacoco.enabled = true
224224
// Ensure OpenSearch bytecode agent is not attached to unit tests
225225
// Build a classpath that prefers main/test outputs and external deps over the shaded jar
226226
classpath = files(
@@ -232,7 +232,8 @@ tasks.named('test', Test) {
232232
// Remove any opensearch-agent -javaagent from jvmArgs if present
233233
def before = jvmArgs == null ? [] : new ArrayList<String>(jvmArgs)
234234
if (before) {
235-
def filtered = before.findAll { !(it instanceof String && it.contains('opensearch-agent')) && !(it instanceof String && it.startsWith('-javaagent:')) }
235+
// Only strip the OpenSearch java agent; keep Jacoco agent intact
236+
def filtered = before.findAll { !(it instanceof String && it.contains('opensearch-agent')) }
236237
if (filtered.size() != before.size()) {
237238
jvmArgs = filtered
238239
}
@@ -440,6 +441,7 @@ task integTest(type: RestIntegTestTask) {
440441
tasks.named("check").configure { dependsOn(integTest) }
441442

442443
integTest {
444+
jacoco.enabled = true
443445
retry {
444446
if (BuildParams.isCi()) {
445447
maxRetries = 6
@@ -1162,6 +1164,15 @@ jacocoTestCoverageVerification {
11621164
check.dependsOn jacocoTestCoverageVerification
11631165
jacocoTestCoverageVerification.dependsOn jacocoTestReport
11641166

1167+
jacocoTestReport {
1168+
dependsOn test, integTest
1169+
executionData.from = files(test.jacoco.destinationFile, integTest.jacoco.destinationFile)
1170+
reports {
1171+
xml.required = true
1172+
html.required = true
1173+
}
1174+
}
1175+
11651176
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
11661177

11671178
apply plugin: 'com.netflix.nebula.ospackage'

src/main/java/org/opensearch/ad/ml/InsightsGenerator.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import java.io.IOException;
99
import java.time.Instant;
10+
import java.time.ZoneOffset;
11+
import java.time.format.DateTimeFormatter;
1012
import java.util.ArrayList;
1113
import java.util.HashMap;
1214
import java.util.HashSet;
@@ -215,6 +217,13 @@ private static String generateParagraphText(
215217
) {
216218
StringBuilder text = new StringBuilder();
217219

220+
DateTimeFormatter friendlyFormatter = DateTimeFormatter
221+
.ofPattern("MMM d, yyyy HH:mm z")
222+
.withLocale(Locale.ROOT)
223+
.withZone(ZoneOffset.UTC);
224+
String startStr = friendlyFormatter.format(eventStart);
225+
String endStr = friendlyFormatter.format(eventEnd);
226+
218227
text.append(String.format(Locale.ROOT, "Correlated anomalies detected across %d detector(s)", detectorIds.size()));
219228

220229
if (!indices.isEmpty()) {
@@ -226,8 +235,9 @@ private static String generateParagraphText(
226235
}
227236

228237
text.append(".");
229-
230-
text.append(String.format(Locale.ROOT, " Detected from %s to %s with %d correlated metrics.", eventStart, eventEnd, numMetrics));
238+
text.append(
239+
String.format(Locale.ROOT, " Detected from %s to %s with %d correlated metrics.", startStr, endStr, numMetrics)
240+
);
231241

232242
return text.toString();
233243
}

0 commit comments

Comments
 (0)