-
Epic
-
Resolution: Unresolved
-
Normal
-
None
-
None
-
None
-
Refactor hourly aggregation of billable usages
-
False
-
-
False
-
To Do
-
100% To Do, 0% In Progress, 0% Done
We're using Kafka Streams in the SWATCH Billable Usage service to group usages within an hour that then will be sent to the SWATCH Producer AWS/Azure/Red Hat Marketplace services.
However, we're seeing lots of inconveniences of using Kafka Streams for this. The most relevant ones are:
- Missing billing usages to be grouped: SWATCH-2908
- Kafka and database transaction issues with Quarkus
- The Kafka Streams Quarkus extension is not officially supported by Quarkus
In order to improve the SWATCH Billable Usage service's resiliency and observability we need to replace the Kafka Streams implementation and use the supported Kafka Quarkus extension.
Context
At the moment, the hourly aggregation of billable usages works as described in the following diagram:
- The SWATCH Tally service sends tally summary messages to the “platform.rhsm-subscriptions.tally” topic.
- The SWATCH Billable Usage service consumes the tally summary messages and for each one:
- Map the tally summary message into a billable usage message (logic here)
- Populate the contract coverage if usage is contract enabled (logic here)
- Map the billable usage message into the billable_usage_remittance entity (check schema in the diagram, logic here)
- Persist the new entity into the database
- Send the billable usage message into the “platform.rhsm-subscriptions.billable-usage” topic
- The SWATCH Billable Usage service consumes the billable usage message and for each one:
- Kafka Streams keeps the messages and aggregates them per hourly basis
- When the time window is closed, it sends a billable usage aggregate message into the “platform.rhsm-subscriptions.billable-usage-hourly-aggregate” topic.
Changes
The workflow would look like as:
- Cron Job is executed hourly to invoke a BillableUsage API
- Gather all the records "billable_usage_remittance" and status is pending and group these records based on the existing "BillableUsageAggregateKey" class and hourly. Filter out the records older than a concrete amount of time defined in configuration.
- Update the above records with status “In Progress” and updated_at to now().
- Send aggregations to the “platform.rhsm-subscriptions.billable-usage-hourly-aggregate” topic using the group-id to either “swatch-producer-aws” or “swatch-producer-azure”.
- If the above transaction fails, update the records to "Pending" status
- If the above transaction works, update the records to “Sent” status.
Links
- is depended on by
-
SWATCH-3244 Avoid all the swatch consumers consume all the messages from the topic "platform.rhsm-subscriptions.billable-usage-hourly-aggregate"
-
- Backlog
-
-
SWATCH-3245 Set the group-id when producing/consuming the remittance aggregations
-
- Closed
-