diff options
author | Ola Aunrønning <olaa@verizonmedia.com> | 2020-04-30 15:28:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-30 15:28:12 +0200 |
commit | 6e35291a4a5d190e0c09e627e99a5af09b00e33b (patch) | |
tree | b9347671faab767b158da0524ededd5becf5c812 | |
parent | cfd33dc27c625ed84f1821e4fe8bc06c216f9f63 (diff) | |
parent | 7f24d22ab4317f0e5313c247ed19abc6740a4019 (diff) |
Merge pull request #13124 from vespa-engine/olaa/cost-of-period
Allow getting tenant cost of any period
2 files changed, 23 insertions, 3 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java index 784f97d5296..fa3d28fe50c 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/MockTenantCost.java @@ -22,7 +22,7 @@ public class MockTenantCost implements TenantCost { } @Override - public List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + public List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTimestamp, long endTimestamp) { return costInfoList; } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java index b0f8ca757b4..a2a91454366 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/TenantCost.java @@ -3,7 +3,9 @@ package com.yahoo.vespa.hosted.controller.api.integration.resource; import com.yahoo.config.provision.TenantName; +import java.time.LocalDate; import java.time.YearMonth; +import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; import java.util.Set; @@ -15,7 +17,11 @@ public interface TenantCost { Set<YearMonth> monthsWithMetering(TenantName tenantName); - List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month); + List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTimestamp, long endTimestamp); + + default List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + return getTenantCostOfPeriod(tenantName, getMonthStartTimeStamp(month), getMonthEndTimeStamp(month)); + } static TenantCost empty() { return new TenantCost() { @@ -25,9 +31,23 @@ public interface TenantCost { } @Override - public List<CostInfo> getTenantCostOfMonth(TenantName tenantName, YearMonth month) { + public List<CostInfo> getTenantCostOfPeriod(TenantName tenantName, long startTime, long endTime) { return Collections.emptyList(); } }; } + + private long getMonthStartTimeStamp(YearMonth month) { + LocalDate startOfMonth = LocalDate.of(month.getYear(), month.getMonth(), 1); + return startOfMonth.atStartOfDay(java.time.ZoneId.of("UTC")) + .toInstant() + .toEpochMilli(); + } + private long getMonthEndTimeStamp(YearMonth month) { + LocalDate startOfMonth = LocalDate.of(month.getYear(), month.getMonth(), 1); + return startOfMonth.plus(1, ChronoUnit.MONTHS) + .atStartOfDay(java.time.ZoneId.of("UTC")) + .toInstant() + .toEpochMilli(); + } } |