diff --git a/bruno/Get.bru b/bruno/Get.bru index 9095403..1e37fc7 100644 --- a/bruno/Get.bru +++ b/bruno/Get.bru @@ -5,13 +5,15 @@ meta { } get { - url: http://localhost:4000/api/metrics/analytics-backend-deployment-8695d9f87f-v8n7r/WORKLOAD?bucket-unit=RAW + url: {{origin}}/api/metrics/analytics-backend-deployment-8695d9f87f-v8n7r/WORKLOAD?bucket-unit=RAW&from=2017-04-26T15:13:12.016+02:00&to=2017-04-26T15:13:12.016+02:00 body: none auth: basic } params:query { bucket-unit: RAW + from: 2017-04-26T15:13:12.016+02:00 + to: 2017-04-26T15:13:12.016+02:00 } auth:basic { diff --git a/bruno/Insert.bru b/bruno/Insert.bru index 0aaaa01..7c86f8a 100644 --- a/bruno/Insert.bru +++ b/bruno/Insert.bru @@ -5,7 +5,7 @@ meta { } post { - url: http://localhost:4000/api/metrics/analytics-backend-deployment-8695d9f87f-v8n7r/WORKLOAD + url: {{origin}}/api/metrics/analytics-backend-deployment-8695d9f87f-v8n7r/WORKLOAD body: json auth: basic } diff --git a/bruno/collection.bru b/bruno/collection.bru new file mode 100644 index 0000000..3cde53a --- /dev/null +++ b/bruno/collection.bru @@ -0,0 +1,3 @@ +vars:pre-request { + origin: http://localhost:8090 +} diff --git a/src/main/java/dev/dinauer/metrics/service/Repo.java b/src/main/java/dev/dinauer/metrics/service/Repo.java index d909784..f11cbf1 100644 --- a/src/main/java/dev/dinauer/metrics/service/Repo.java +++ b/src/main/java/dev/dinauer/metrics/service/Repo.java @@ -19,13 +19,8 @@ public class Repo implements PanacheRepositoryBase return find("resource = :resource AND name = :name AND timestamp = :timestamp AND bucketUnit = :bucketUnit", Parameters.with("resource", resource).and("name", name).and("timestamp", timestamp).and("bucketUnit", bucketUnit)).firstResultOptional(); } - public List findByResourceAndMetricAndTimeUnit(String resource, String name, BucketUnit bucketUnit) - { - return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit)); - } - public List findByResourceAndMetricAndTimeUnitAndPeriod(String resource, String name, BucketUnit bucketUnit, Long from, Long to) { - return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit AND (unix >= :from AND unix <= :to) ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit).and("from", from).and("to", to)); + return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit AND unixTimestamp >= :from AND unixTimestamp <= :to ORDER BY unixTimestamp DESC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit).and("from", from).and("to", to)); } } diff --git a/src/main/java/dev/dinauer/metrics/service/Resource.java b/src/main/java/dev/dinauer/metrics/service/Resource.java index fb48c57..7b210cd 100644 --- a/src/main/java/dev/dinauer/metrics/service/Resource.java +++ b/src/main/java/dev/dinauer/metrics/service/Resource.java @@ -1,5 +1,6 @@ package dev.dinauer.metrics.service; +import java.time.ZonedDateTime; import java.util.List; import java.util.Optional; @@ -41,12 +42,12 @@ public class Resource } @GET - public List get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional bucketUnit) + public List get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional bucketUnit, @QueryParam("from") ZonedDateTime from, @QueryParam("to") ZonedDateTime to) { if (authenticationService.canRead()) { Timer timer = Timer.start(); - List buckets = service.get(resource, metric, bucketUnit.orElse(BucketUnit.RAW)); + List buckets = service.get(resource, metric, bucketUnit.orElse(BucketUnit.RAW), from, to); LOG.infof("Retrieving %s buckets in %s seconds.", buckets.size(), timer.stop()); return buckets; } diff --git a/src/main/java/dev/dinauer/metrics/service/Service.java b/src/main/java/dev/dinauer/metrics/service/Service.java index ef15481..1d10fe2 100644 --- a/src/main/java/dev/dinauer/metrics/service/Service.java +++ b/src/main/java/dev/dinauer/metrics/service/Service.java @@ -63,8 +63,8 @@ public class Service } } - public List get(String resource, String metric, BucketUnit unit) + public List get(String resource, String metric, BucketUnit unit, ZonedDateTime from, ZonedDateTime to) { - return repo.findByResourceAndMetricAndTimeUnit(resource, metric, unit); + return repo.findByResourceAndMetricAndTimeUnitAndPeriod(resource, metric, unit, from.toEpochSecond(), to.toEpochSecond()); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1f4a383..2bc9512 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ # HTTP quarkus.http.root-path=/api/metrics -%dev.quarkus.http.port=4000 +%dev.quarkus.http.port=8090 # Test Client %dev.big.bucket.client.test.rw=test