Repository navigation
Conversation
Kaiten now makes usage reports idempotent and keeps their history. The SDK follows. - internal/gen is regenerated from the current Core OpenAPI document. - UsageReportInput.TransactionID: Kaiten applies a report at most once per key, instance and entitlement. A key is checked before sending (ErrInvalidTransactionID) and omitted from the body when empty. - Instances.ReportEntitlementUsage returns a UsageReportResult: the usage, Replayed (Idempotent-Replayed) and MetadataDropped (Kaiten-Metadata-Dropped). ReportEntitlementUsageMetric is now that call without the two flags. - Retries: a report with a key is retried on transport errors and on 500, 502, 503 and 504, three attempts in all under the same key, with exponential backoff that honours the context. A report without a key is still sent once. - A conflict wraps ErrTransactionIDReused or ErrThresholdExceeded according to its problem code, alongside the *Error. ReportUsage no longer reports a reused key as a threshold. - A server older than transaction IDs refuses the field: the report is sent again without it, and the client stops sending keys and retrying for its lifetime, logging that once. WithLogger sets the logger; slog.Default() otherwise. - Instances.ListUsageReports walks a pair's history by afterSeq, with From/To/TransactionID filters and a Limit ceiling. - Instances.ExportUsageReports and ExportOrganizationUsageReports stream CSV or NDJSON: the body is returned unread, with the attachment's name. - The report wrapper passes the new 503 problem through. Signed-off-by: Tom Ribuot <tom.ribuot@kaiten.sh>
fuzcap
pushed a commit
to kaitencloud/kaiten
that referenced
this pull request
Oct 5, 2026
github.com/kaitencloud/sdk-go moves to the commit that adds usage report transaction IDs and the usage history (kaitencloud/sdk-go#1). The SDK coverage test now maps listUsageReports, exportUsageReports and exportOrganizationUsageReports to it instead of listing them as awaiting the SDK. It is a pseudo-version of that pull request's branch: bump it to the tag once the SDK pull request is merged and released. Signed-off-by: Tom Ribuot <tom.ribuot@kaiten.sh>
This was referenced Oct 5, 2026
This was referenced Oct 7, 2026
client.Billing covers every billing operation of the Core contract (kaiten feat/billing at 56738183): settings, capabilities, health, sync and period closing; subscriptions; invoices, their export and line reports; the accounting handoff (Claim / Ack); licence prices and the invoice preview; the add-on catalogue and attachments; vouchers and redemptions; publishable keys and customer sessions; customers' payment methods and portal; and what a pk_ key and a kst_ session reach. Paginated lists walk every page and have a ...Page variant. *Error carries Retry-After. internal/gen is regenerated; an overlay names InvoiceHandoff.status's type, which collided with Invoice.handoffStatus's. The wrappers of the five deletes and updates the contract now answers 409 for pass it through. The billing wrappers are listed in the problem and surface coverage tests. Signed-off-by: Tom Ribuot <tom.ribuot@kaiten.sh>
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR change?
The SDK side of two Kaiten features: idempotent usage reports (
transactionId) and the usage history. Server side: kaitencloud/kaiten#16.transactionId.UsageReportInput.TransactionIDmakes a report idempotent: Kaiten applies it at most once per key, instance and entitlement within its idempotency window (35 days by default). A malformed key fails locally withErrInvalidTransactionID; an empty one is left out of the body.Instances.ReportEntitlementUsagereturns aUsageReportResult: the usage, plusReplayed(Idempotent-Replayed) andMetadataDropped(Kaiten-Metadata-Dropped).ReportEntitlementUsageMetricis now that call without the two flags.ErrTransactionIDReusedorErrThresholdExceededaccording to its problem code, alongside the*Error.ReportUsageno longer reports a reused key as a threshold.transactionIdrefuses the field (the body is closed). The client then resends the report without it and stops sending keys and retrying for its lifetime, logging that once.WithLoggersets the logger;slog.Default()otherwise.Instances.ListUsageReportswalks a pair's history (From,To,TransactionID, aLimitceiling).Instances.ExportUsageReportsandExportOrganizationUsageReportsstream CSV or NDJSON: the body is returned unread, with the attachment's file name.internal/genis regenerated from the current Core OpenAPI document, and the report wrapper passes the new 503 problem through.Testing
transactionIdsent only when set.ReportEntitlementUsageandReportUsage.body.transactionIdgives a resend without the key, later reports keyless and unretried, and one log line. A newer server'sInvalidTransactionIdis not mistaken for it.afterSeq, theLimitceiling, query parameters.*Errorwith theirCode; organization filters and a malformed ID option.task vulnreports standard library advisories of the local Go toolchain (go1.26.3, fixed in 1.26.6), not of this module.Compatibility
Additive only (gorelease: no incompatible change). Keys need a Kaiten release with
transactionId; against an older one the SDK falls back as described above.