From fcc4be3a6eea68b8c3ec5f649b53455a80655a35 Mon Sep 17 00:00:00 2001 From: Vamsi Manohar Date: Fri, 16 Feb 2024 13:49:52 -0800 Subject: [PATCH] Fix issue in testSourceMetricCommandWithTimestamp integ test with different timezones and locales. (#2522) * Timezon fix Signed-off-by: Vamsi Manohar * Timezon fix Signed-off-by: Vamsi Manohar --------- Signed-off-by: Vamsi Manohar --- .../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);