Skip to content

Commit 429f9c8

Browse files
Fix issue in testSourceMetricCommandWithTimestamp integ test with different timezones and locales. (#2522) (#2524)
* Timezon fix * Timezon fix --------- (cherry picked from commit fcc4be3) Signed-off-by: Vamsi Manohar <reddyvam@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1848d86 commit 429f9c8

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import java.net.URI;
2222
import java.nio.file.Files;
2323
import java.nio.file.Paths;
24-
import java.text.SimpleDateFormat;
24+
import java.time.LocalDateTime;
25+
import java.time.format.DateTimeFormatter;
2526
import java.util.Date;
2627
import lombok.SneakyThrows;
2728
import org.apache.commons.lang3.StringUtils;
@@ -97,10 +98,12 @@ public void testSourceMetricCommand() {
9798
@Test
9899
@SneakyThrows
99100
public void testSourceMetricCommandWithTimestamp() {
100-
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
101+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
102+
// Generate timestamp string for one hour less than the current time
103+
String timestamp = LocalDateTime.now().minusHours(1).format(formatter);
101104
String query =
102105
"source=my_prometheus.prometheus_http_requests_total | where @timestamp > '"
103-
+ format.format(new Date(System.currentTimeMillis() - 3600 * 1000))
106+
+ timestamp
104107
+ "' | sort + @timestamp | head 5";
105108

106109
JSONObject response = executeQuery(query);

0 commit comments

Comments
 (0)