Skip to content

Commit

Permalink
Fix issue in testSourceMetricCommandWithTimestamp integ test with dif…
Browse files Browse the repository at this point in the history
…ferent timezones and locales. (#2522)

* Timezon fix

Signed-off-by: Vamsi Manohar <[email protected]>

* Timezon fix

Signed-off-by: Vamsi Manohar <[email protected]>

---------

Signed-off-by: Vamsi Manohar <[email protected]>
  • Loading branch information
vmmusings authored Feb 16, 2024
1 parent f3e06d5 commit fcc4be3
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fcc4be3

Please sign in to comment.