Retrieve bucket by period

This commit is contained in:
Andreas Dinauer 2025-11-30 13:30:36 +01:00
parent ce01994b3b
commit f31cab780b
7 changed files with 14 additions and 13 deletions

View File

@ -5,13 +5,15 @@ meta {
} }
get { 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 body: none
auth: basic auth: basic
} }
params:query { params:query {
bucket-unit: RAW bucket-unit: RAW
from: 2017-04-26T15:13:12.016+02:00
to: 2017-04-26T15:13:12.016+02:00
} }
auth:basic { auth:basic {

View File

@ -5,7 +5,7 @@ meta {
} }
post { 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 body: json
auth: basic auth: basic
} }

3
bruno/collection.bru Normal file
View File

@ -0,0 +1,3 @@
vars:pre-request {
origin: http://localhost:8090
}

View File

@ -19,13 +19,8 @@ public class Repo implements PanacheRepositoryBase<Bucket, String>
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(); 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<Bucket> 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<Bucket> findByResourceAndMetricAndTimeUnitAndPeriod(String resource, String name, BucketUnit bucketUnit, Long from, Long to) public List<Bucket> 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));
} }
} }

View File

@ -1,5 +1,6 @@
package dev.dinauer.metrics.service; package dev.dinauer.metrics.service;
import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -41,12 +42,12 @@ public class Resource
} }
@GET @GET
public List<Bucket> get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional<BucketUnit> bucketUnit) public List<Bucket> get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional<BucketUnit> bucketUnit, @QueryParam("from") ZonedDateTime from, @QueryParam("to") ZonedDateTime to)
{ {
if (authenticationService.canRead()) if (authenticationService.canRead())
{ {
Timer timer = Timer.start(); Timer timer = Timer.start();
List<Bucket> buckets = service.get(resource, metric, bucketUnit.orElse(BucketUnit.RAW)); List<Bucket> buckets = service.get(resource, metric, bucketUnit.orElse(BucketUnit.RAW), from, to);
LOG.infof("Retrieving %s buckets in %s seconds.", buckets.size(), timer.stop()); LOG.infof("Retrieving %s buckets in %s seconds.", buckets.size(), timer.stop());
return buckets; return buckets;
} }

View File

@ -63,8 +63,8 @@ public class Service
} }
} }
public List<Bucket> get(String resource, String metric, BucketUnit unit) public List<Bucket> 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());
} }
} }

View File

@ -1,6 +1,6 @@
# HTTP # HTTP
quarkus.http.root-path=/api/metrics quarkus.http.root-path=/api/metrics
%dev.quarkus.http.port=4000 %dev.quarkus.http.port=8090
# Test Client # Test Client
%dev.big.bucket.client.test.rw=test %dev.big.bucket.client.test.rw=test