From 429f9c807d24def8653565fdda8d67cf3a5b1d4d Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:35:50 -0800 Subject: [PATCH] Fix issue in testSourceMetricCommandWithTimestamp integ test with different timezones and locales. (#2522) (#2524) * Timezon fix * Timezon fix --------- (cherry picked from commit fcc4be3a6eea68b8c3ec5f649b53455a80655a35) Signed-off-by: Vamsi Manohar Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../sql/ppl/PrometheusDataSourceCommandsIT.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java index 10fe13a8db..e0b463ed36 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java @@ -21,7 +21,8 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; -import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Date; import lombok.SneakyThrows; import org.apache.commons.lang3.StringUtils; @@ -97,10 +98,12 @@ public void testSourceMetricCommand() { @Test @SneakyThrows public void testSourceMetricCommandWithTimestamp() { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + // Generate timestamp string for one hour less than the current time + String timestamp = LocalDateTime.now().minusHours(1).format(formatter); String query = "source=my_prometheus.prometheus_http_requests_total | where @timestamp > '" - + format.format(new Date(System.currentTimeMillis() - 3600 * 1000)) + + timestamp + "' | sort + @timestamp | head 5"; JSONObject response = executeQuery(query);