Skip to content

Commit

Permalink
Timezon fix
Browse files Browse the repository at this point in the history
Signed-off-by: Vamsi Manohar <reddyvam@amazon.com>
  • Loading branch information
vmmusings committed Feb 16, 2024
1 parent a775dcc commit b18ec13
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
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 java.util.TimeZone;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
Expand Down Expand Up @@ -98,11 +98,12 @@ public void testSourceMetricCommand() {
@Test
@SneakyThrows
public void testSourceMetricCommandWithTimestamp() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
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 b18ec13

Please sign in to comment.