Skip to content

feat: split billing event types by embedding and reranking - #2583

Merged
erichare merged 4 commits into
mainfrom
feat/billing-event-type-per-model-type
Sep 21, 2026
Merged

erichare merged 4 commits into
mainfrom
feat/billing-event-type-per-model-type

Conversation

@erichare

@erichare erichare commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What this PR does:

  • Billing event_type now comes from the call's ModelType, e.g. internal_reranking_total_tokens / internal_embedding_total_tokens. 12 event types instead of 6, one per internal/external, embedding/reranking and metric.
  • MODEL_TYPE_UNSPECIFIED has no event types, logs an error and emits nothing.

Tests: new BillingEventTypeTest pins the 12 names, DefaultBillingTest covers both model types and unspecified, BillingS3UploadIntegrationTest expects only embedding events.

Which issue(s) this PR fixes:
None, follow up to #2522

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

Billing events only had the model name, so pricing could not tell a rerank
call from an embedding call. Resolve the event_type from ModelType, e.g.
internal_reranking_total_tokens and internal_embedding_total_tokens, for
every internal/external metric. MODEL_TYPE_UNSPECIFIED has no event types
and is logged as an error.
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

📈 Unit Test Coverage Delta vs Main Branch

Metric Value
Main Branch 54.06%
This PR 54.12%
Delta 🟢 +0.07%
✅ Coverage improved!

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Unit Test Coverage Report

Overall Project 54.12% -0.01% 🍏
Files changed 96.92% 🍏

File Coverage
BillingEvent.java 100% 🍏
BillingEventType.java 97.74% -1.13% 🍏
DefaultBilling.java 95.58% 🍏
ModelType.java 68.97% -8.62%

@erichare
erichare marked this pull request as ready for review September 16, 2026 22:19
@erichare
erichare requested a review from a team as a code owner September 16, 2026 22:19
@erichare
erichare requested a review from amorton September 16, 2026 22:19
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

📈 Integration Test Coverage Delta vs Main Branch (dse69-it)

Metric Value
Main Branch 71.98%
This PR 71.99%
Delta 🟢 +0.00%
✅ Coverage improved!

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Integration Test Coverage Report (dse69-it)

Overall Project 71.99% -0.04% 🍏
Files changed 81.92% 🍏

File Coverage
DefaultBilling.java 95.03% 🍏
BillingEventType.java 83.02% -15.85% 🍏
BillingEvent.java 61.24% 🍏
ModelType.java 48.28% -8.62%

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

📉 Integration Test Coverage Delta vs Main Branch (hcd-it)

Metric Value
Main Branch 73.25%
This PR 73.25%
Delta 🔴 -0.00%
⚠️ Coverage decreased

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Integration Test Coverage Report (hcd-it)

Overall Project 73.25% -0.04% 🍏
Files changed 81.92% 🍏

File Coverage
DefaultBilling.java 95.03% 🍏
BillingEventType.java 83.02% -15.85% 🍏
BillingEvent.java 61.24% 🍏
ModelType.java 48.28% -8.62%

@amorton amorton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see notes

case EGRESS_BYTES -> internal ? INTERNAL_MODEL_EGRESS_BYTES : EXTERNAL_MODEL_EGRESS_BYTES;
case INGRESS_BYTES -> internal ? INTERNAL_MODEL_INGRESS_BYTES : EXTERNAL_MODEL_INGRESS_BYTES;
};
public static Optional<BillingEventType> of(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ModelType#MODEL_TYPE_UNSPECIFIED is passed throw an IllegalArgument error, that value should never have been added it makes no sense.

change to not return Optional, all calls should return a value for any combination of the arg, if not it is an error. Otherwise we will not know how to record the billing.

if possible revert back to using a modern switch{} clause, because this makes the compiler check that all possible values of the enum are covered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call about the compiler!! i am used to the world without it!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  public static BillingEventType of(ModelType modelType, Metric metric, boolean internal) {
    return switch (modelType) {
      case MODEL_TYPE_UNSPECIFIED ->
          throw new IllegalArgumentException(
              "BillingEventType.of() - modelType must be specified, modelType=%s, metric=%s"
                  .formatted(modelType, metric));
      case EMBEDDING ->
          switch (metric) {
            case TOTAL_TOKENS ->
                internal ? INTERNAL_EMBEDDING_TOTAL_TOKENS : EXTERNAL_EMBEDDING_TOTAL_TOKENS;
            case EGRESS_BYTES ->
                internal ? INTERNAL_EMBEDDING_EGRESS_BYTES : EXTERNAL_EMBEDDING_EGRESS_BYTES;
            case INGRESS_BYTES ->
                internal ? INTERNAL_EMBEDDING_INGRESS_BYTES : EXTERNAL_EMBEDDING_INGRESS_BYTES;
          };
      case RERANKING ->
          switch (metric) {
            case TOTAL_TOKENS ->
                internal ? INTERNAL_RERANKING_TOTAL_TOKENS : EXTERNAL_RERANKING_TOTAL_TOKENS;
            case EGRESS_BYTES ->
                internal ? INTERNAL_RERANKING_EGRESS_BYTES : EXTERNAL_RERANKING_EGRESS_BYTES;
            case INGRESS_BYTES ->
                internal ? INTERNAL_RERANKING_INGRESS_BYTES : EXTERNAL_RERANKING_INGRESS_BYTES;
          };

Comment thread src/main/java/io/stargate/sgv2/jsonapi/service/billing/BillingEventType.java Outdated
Comment thread src/main/java/io/stargate/sgv2/jsonapi/service/billing/DefaultBilling.java Outdated
Comment thread src/test/java/io/stargate/sgv2/jsonapi/service/billing/DefaultBillingTest.java Outdated
… model type

- BillingEventType.of() returns a value (no Optional) via exhaustive switch
- throw IllegalArgumentException for ModelType.MODEL_TYPE_UNSPECIFIED
- add billingEventName() to ModelType and Metric, event name built from parts
- DefaultBilling no longer skips missing event types
- remove unneeded test helper

@amorton amorton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erichare
erichare merged commit 55e83c3 into main Sep 21, 2026
3 checks passed
@erichare
erichare deleted the feat/billing-event-type-per-model-type branch September 21, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants