Skip to content

Commit

Permalink
Remove hardware measurement type from billable usage and remittance
Browse files Browse the repository at this point in the history
This patch removes the hardware measurement type from billable usage
and remittance since it does not apply to remittance in general.
  • Loading branch information
mstead committed Dec 10, 2024
1 parent 9dd0050 commit 3a34bf2
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.20.xsd">
<changeSet id="202412091327-01" author="mstead">
<comment>Drop the hardware_measurement_type column from billable_usage_remittance table.</comment>
<dropColumn tableName="billable_usage_remittance" columnName="hardware_measurement_type" />
<rollback>
<addColumn tableName="billable_usage_remittance">
<column name="hardware_measurement_type" type="varchar(32)" />
</addColumn>
</rollback>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions src/main/resources/liquibase/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,6 @@
<include file="/liquibase/202410021300-update_usages_to_unknown.xml"/>
<include file="/liquibase/202410211200-retry-after-billable-usage-index.xml"/>
<include file="/liquibase/202410241408-clear-retryable.xml"/>
<include file="/liquibase/202412091327-drop-hardware-measurement-type-from-billable-usage-remittance.xml"/>
</databaseChangeLog>
<!-- vim: set expandtab sts=4 sw=4 ai: -->
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public class BillableUsageRemittanceEntity implements Serializable {
@Column(name = "tally_id")
private UUID tallyId;

@Column(name = "hardware_measurement_type")
private String hardwareMeasurementType;

@Column(name = "status")
private RemittanceStatus status;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class BillableUsageRemittanceFilter {
private String metricId;
private String billingProvider;
private String billingAccountId;
private String hardwareMeasurementType;
private OffsetDateTime beginning;
private OffsetDateTime ending;
private String accumulationPeriod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public List<RemittanceSummaryProjection> getRemittanceSummaries(
root.get(BillableUsageRemittanceEntity_.METRIC_ID),
root.get(BillableUsageRemittanceEntity_.ORG_ID),
root.get(BillableUsageRemittanceEntity_.PRODUCT_ID),
root.get(BillableUsageRemittanceEntity_.HARDWARE_MEASUREMENT_TYPE),
root.get(BillableUsageRemittanceEntity_.STATUS),
root.get(BillableUsageRemittanceEntity_.ERROR_CODE));
}
Expand All @@ -81,7 +80,6 @@ public List<RemittanceSummaryProjection> getRemittanceSummaries(
root.get(BillableUsageRemittanceEntity_.BILLING_PROVIDER),
root.get(BillableUsageRemittanceEntity_.BILLING_ACCOUNT_ID),
root.get(BillableUsageRemittanceEntity_.METRIC_ID),
root.get(BillableUsageRemittanceEntity_.HARDWARE_MEASUREMENT_TYPE),
root.get(BillableUsageRemittanceEntity_.STATUS),
root.get(BillableUsageRemittanceEntity_.ERROR_CODE)));
return entityManager.createQuery(query).getResultList();
Expand Down Expand Up @@ -171,10 +169,6 @@ private Specification<BillableUsageRemittanceEntity> buildSearchSpecification(
if (Objects.nonNull(filter.getSla())) {
searchCriteria = searchCriteria.and(matchingSla(filter.getSla()));
}
if (Objects.nonNull(filter.getHardwareMeasurementType())) {
searchCriteria =
searchCriteria.and(matchingHardwareMeasurementType(filter.getHardwareMeasurementType()));
}
if (filter.isExcludeFailures()) {
searchCriteria = searchCriteria.and(excludesFailures());
}
Expand All @@ -193,14 +187,6 @@ private Specification<BillableUsageRemittanceEntity> excludesFailures() {
root.get(BillableUsageRemittanceEntity_.status), RemittanceStatus.FAILED));
}

private Specification<BillableUsageRemittanceEntity> matchingHardwareMeasurementType(
String hardwareMeasurementType) {
return (root, query, builder) ->
builder.equal(
root.get(BillableUsageRemittanceEntity_.hardwareMeasurementType),
hardwareMeasurementType);
}

private static Specification<BillableUsageRemittanceEntity> matchingProductId(String productId) {
return (root, query, builder) ->
builder.equal(root.get(BillableUsageRemittanceEntity_.productId), productId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class RemittanceSummaryProjection {
private String billingProvider;
private String billingAccountId;
private String metricId;
private String hardwareMeasurementType;
private RemittanceStatus status;
private RemittanceErrorCode errorCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ private BillableUsage toBillableUsage(
.withBillingAccountId(snapshot.getBillingAccountId())
.withMetricId(measurement.getMetricId())
.withValue(measurement.getValue())
.withHardwareMeasurementType(measurement.getHardwareMeasurementType())
.withCurrentTotal(measurement.getCurrentTotal());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ private void createRemittance(
.usage(usage.getUsage().value())
.remittancePendingDate(clock.now())
.tallyId(usage.getTallyId())
.hardwareMeasurementType(usage.getHardwareMeasurementType())
.status(
contractCoverage.isGratis() ? RemittanceStatus.GRATIS : RemittanceStatus.PENDING)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ private BillableUsageRemittanceEntity remittance(
.accumulationPeriod(AccumulationPeriodFormatter.toMonthId(remittanceDate))
.remittancePendingDate(remittanceDate)
.remittedPendingValue(value)
.hardwareMeasurementType("AWS")
.build();
}

Expand Down Expand Up @@ -335,7 +334,6 @@ void getMonthlySummary() {
.totalRemittedPendingValue(24.0)
.sla(remittance1.getSla())
.usage(remittance1.getUsage())
.hardwareMeasurementType("AWS")
.build();

var expectedSummary2 =
Expand All @@ -350,7 +348,6 @@ void getMonthlySummary() {
.totalRemittedPendingValue(15.0)
.sla(remittance3.getSla())
.usage(remittance3.getUsage())
.hardwareMeasurementType("AWS")
.build();

List<RemittanceSummaryProjection> results = repository.getRemittanceSummaries(filter1);
Expand All @@ -370,7 +367,6 @@ void testRemittanceFilterUsedByBillableUsageService() {
String billingProvider = "aws";
String billingAccountId = "ba123456789";
String remittancePendingDateStr = "2024-06-19T16:52:17.526219+00:00";
String hardwareMeasurementType = "AWS";

var billableUsageNoExpected =
BillableUsageRemittanceEntity.builder()
Expand All @@ -387,7 +383,6 @@ void testRemittanceFilterUsedByBillableUsageService() {
OffsetDateTime.parse(
remittancePendingDateStr, DateTimeFormatter.ISO_OFFSET_DATE_TIME))
.tallyId(UUID.randomUUID())
.hardwareMeasurementType(hardwareMeasurementType)
.status(RemittanceStatus.PENDING)
.build();

Expand All @@ -406,7 +401,6 @@ void testRemittanceFilterUsedByBillableUsageService() {
OffsetDateTime.parse(
remittancePendingDateStr, DateTimeFormatter.ISO_OFFSET_DATE_TIME))
.tallyId(UUID.randomUUID())
.hardwareMeasurementType(hardwareMeasurementType)
.status(RemittanceStatus.PENDING)
.build();

Expand All @@ -426,7 +420,6 @@ void testRemittanceFilterUsedByBillableUsageService() {
OffsetDateTime.parse(
remittancePendingDateStr, DateTimeFormatter.ISO_OFFSET_DATE_TIME))
.tallyId(UUID.randomUUID())
.hardwareMeasurementType("PHYSICAL")
.status(RemittanceStatus.SUCCEEDED)
.build();
repository.persist(
Expand All @@ -446,8 +439,7 @@ void testRemittanceFilterUsedByBillableUsageService() {
.withMetricId(metricId)
.withProductId(productTag)
.withUsage(BillableUsage.Usage.PRODUCTION)
.withSla(BillableUsage.Sla.PREMIUM)
.withHardwareMeasurementType("PHYSICAL");
.withSla(BillableUsage.Sla.PREMIUM);

// Build the filter the same way that we do in the billable usage in the service.
var filter = BillableUsageRemittanceFilter.totalRemittedFilter(incomingUsage);
Expand All @@ -470,8 +462,6 @@ void testRemittanceFilterUsedByBillableUsageService() {
.totalRemittedPendingValue(expectedRemittedPendingValue)
.sla(billableUsageRemittanceFromRhelemeter.getSla())
.usage(billableUsageRemittanceFromRhelemeter.getUsage())
.hardwareMeasurementType(
billableUsageRemittanceFromRhelemeter.getHardwareMeasurementType())
.status(billableUsageRemittanceFromRhelemeter.getStatus())
.build();

Expand All @@ -490,7 +480,6 @@ void testRemittanceFilterUsedByBillableUsageService() {
.totalRemittedPendingValue(billableUsageRemittanceFromCost.getRemittedPendingValue())
.sla(billableUsageRemittanceFromCost.getSla())
.usage(billableUsageRemittanceFromCost.getUsage())
.hardwareMeasurementType(billableUsageRemittanceFromCost.getHardwareMeasurementType())
.status(billableUsageRemittanceFromCost.getStatus())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ void shouldProduceBillableUsageWhenOrgIdPresent() {
.withBillingAccountId(expectedBillingAccountId)
.withMetricId(expectedMetricId)
.withValue(42.0)
.withHardwareMeasurementType("PHYSICAL")
.withCurrentTotal(expectedCurrentTotal);

var summary =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ void givenExistingRemittanceForUsage(
.usage(usage.getUsage().value())
.remittancePendingDate(remittancePendingDate)
.tallyId(usage.getTallyId())
.hardwareMeasurementType(usage.getHardwareMeasurementType())
.status(status)
.build();
// Remitted value should be set to usages metric_value rather than billing_value
Expand Down
3 changes: 0 additions & 3 deletions swatch-core/schemas/billable_usage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ properties:
vendor_product_code:
description: Field used to specify a unique contract
type: string
hardware_measurement_type:
type: string
format: string
currentTotal:
description: Sum of all measurements between the start of the month to the snapshot date.
type: number

0 comments on commit 3a34bf2

Please sign in to comment.