Skip to main content

Plan for corrections

A usage event cannot be edited or deleted. To correct usage later, give each usage event an identity and a revision from the start.

Prerequisites

  • To create a usage-event collection, you need a role with the Can Create Usage Event and Can Read Usage Event permissions.
  • To add data fields to an existing usage-event collection, you need a role with the Can Update Usage Event and Can Read Usage Event permissions.

Steps

Usage events that arrive before you add the correction fields have no value for them. Add the fields before you send usage events.
  1. Add two data fields to the data schema of the usage-event collection, when you create the usage-event collection or later:
    • event_id, with the data type String. It holds an identifier that you choose for each usage event.
    • revision, with the data type Int64. It holds 1 for the first revision of a usage event.
    See Create a usage-event collection or Add a data field.
  2. In every usage event that your systems send, fill in event_id and revision.
A billable metric can then keep only the latest revision of each usage event. See Replace usage events.

Replace usage events

This method works for every calculation.

Prerequisites

  • The usage-event collection has the correction fields. See Plan for corrections.
  • To send usage events, you need a role with the Can Create Usage Event and Can Read Usage Event permissions.
  • To change the billable metric, you need a role with the Can Update Billable Metric and Can Read Billable Metric permissions.

Steps

A corrected usage event with a different timestamp can fall in another billing period. Zenskar then counts it next to the original. Keep the original timestamp.
  1. Send a new usage event with the same event_id, customer_id, and timestamp as the usage event that it corrects. Set revision one higher. See Send usage events through the API.
  2. Put the corrected values in the other data fields.
  3. Open the billable metric in the SQL builder. If it uses the visual builder, move it first. See Move a billable metric to the SQL builder.
  4. Change the query so that it numbers the revisions of each event_id, newest first, and keeps only the first row of each event_id. The following query counts API calls with only the latest revision of each usage event:
  5. Preview the billable metric for a period with a corrected usage event. See Preview a billable metric.
  6. Click SAVE CHANGES.
The billable metric now keeps only the latest revision of each usage event. Charges that Zenskar already calculated change only when they are recalculated. See Recalculate charges.

Offset usage in a sum

Send a usage event that cancels out part of the usage that was recorded wrongly. A billable metric that already sums needs no change.

Prerequisites

  • You need a role with the Can Create Usage Event and Can Read Usage Event permissions.

Steps

An offsetting usage event with a timestamp in another billing period changes that billing period instead. Use a timestamp in the same billing period as the usage that it corrects.
  1. Send a usage event with the same customer_id, a timestamp in the same billing period, and a negative value in the data field that the billable metric sums. For example, to remove 40 GB that were recorded twice, send -40 in the field.
The sum of the billing period then includes the negative value. Charges that Zenskar already calculated change only when they are recalculated. See Recalculate charges.

Offset usage in a count

A count cannot go down by adding usage events. Count with a sum of a number instead.

Prerequisites

  • To add a data field, you need a role with the Can Update Usage Event and Can Read Usage Event permissions.
  • To send usage events, you need a role with the Can Create Usage Event and Can Read Usage Event permissions.
  • To change the billable metric, you need a role with the Can Update Billable Metric and Can Read Billable Metric permissions.

Steps

  1. Add an Int64 data field, such as units, to the usage-event collection. See Add a data field.
  2. Send 1 in units with every usage event.
  3. Change the billable metric to use the calculation type SUM over units. See Edit a billable metric.
    Usage events that arrived before you added units have no value for it, and a sum over units leaves them out. Change the billable metric only from the first billing period in which every usage event has units.
  4. To remove a usage event that was recorded wrongly, send a usage event with -1 in units, with the same customer_id and a timestamp in the same billing period.
Charges that Zenskar already calculated change only when they are recalculated. See Recalculate charges.

Correct usage in a data source

Prerequisites

  • You need access to the system that the data source connects to.
  • To sync a synced data source right away, you need a role with the Can Read Data Source permission.

Steps

  1. Fix the data in your system. Zenskar queries a remote data source each time it calculates. For a remote data source, the next preview or calculation uses the fix.
  2. For a synced data source, wait for the next scheduled sync, or start one. See Sync now, pause, or resume syncing. In a table without a cursor column, each sync replaces the whole table in the synced usage data. The next sync therefore picks up the fix.
    In a table with a cursor column, a sync copies a changed row only when its cursor value goes up. The sync then adds it next to the old row, and the old row stays. Correct such a table by adding new rows with the revision method, as in Replace usage events. You can also sync the table without a cursor column.
Charges that Zenskar already calculated change only when they are recalculated. See Recalculate charges.

Recalculate charges

A corrected usage event or a fixed data source changes a quantity only when Zenskar calculates it again. Zenskar calculates the quantity of a billing period when it builds the invoice of that billing period.

Prerequisites

Steps

  1. For each contract that the correction affects, regenerate its invoices. See Regenerate the invoices of a contract.
Invoice regeneration recalculates the draft and upcoming invoices of an active contract. A change to a billing period whose invoice is already approved follows the invoicing configuration of the contract. See Invoicing configurations: increases after approval.