feat(usage): rename metrics → tokens_embedded/pages_embedded + export token cost to Prometheus
Billing product model finalized (Deck #281): bill pages externally, record tokens internally. Rename the data-plane metric literals to match the now- canonical contract (Deck #284) — the control plane's METRIC_EVENT_NAMES is already renamed, so the old names would be unmapped and never sync to Stripe. Rename (values unchanged): - embeddings_queries → tokens_embedded (value = real token count, already emitted by this PR; the unit upstream providers bill on). - pages_chunks → pages_embedded (value kept as len(chunk_texts) interim; TODO(#282): real normalized "pages indexed" count — real pages for paginated types, chars/tokens-per-page constant otherwise — is deferred to the instrumentation card, this only lands the name/contract). - All literals, log strings, docstrings, comments, the migration comment, and tests renamed; grep confirms zero old strings remain. Observability (new): export embedding token cost to Prometheus as astrolabe_embedding_tokens_total{provider,operation} (operation = index|query) so the billed cost unit is visible in Grafana, not just the per-tenant billing DB. Dedicated counter (doesn't inflate the existing chunk/request metrics) and always-on (independent of USAGE_METERING_ENABLED, so OSS/self-host gets it). Wired on both the indexing batch embed and the search query embed (query inside the per-request cache-miss branch, so reused embeddings aren't double-counted). Note: the rename orphans any pre-existing embeddings_queries/pages_chunks rows in tenant app DBs (CP no longer maps them) — acceptable; pipeline is inert with throwaway dev/sandbox data. Deck #284 (folded into PR #875). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ddefb03701
commit
973f80e7b9
@@ -73,7 +73,7 @@ class Provider(ABC):
|
||||
Returns ``(embedding, token_count)``. The default delegates to
|
||||
:meth:`embed` and estimates the tokens; providers that surface real
|
||||
usage from their embedding response override this. Used by the
|
||||
usage-metering hooks (Deck #67) to bill ``embeddings_queries`` by
|
||||
usage-metering hooks (Deck #67) to bill ``tokens_embedded`` by
|
||||
tokens rather than by operation count.
|
||||
|
||||
IMPORTANT (recursion invariant): this default calls ``self.embed``. A
|
||||
|
||||
@@ -143,7 +143,7 @@ class MistralProvider(Provider):
|
||||
Returns ``(embeddings, total_tokens)`` where ``total_tokens`` is the
|
||||
sum of ``response.usage.total_tokens`` across the ``BATCH_SIZE`` sub-
|
||||
requests (the unit Mistral bills on). Used by the usage-metering hooks
|
||||
to record ``embeddings_queries`` by tokens (Deck #67).
|
||||
to record ``tokens_embedded`` by tokens (Deck #67).
|
||||
"""
|
||||
if not self.supports_embeddings:
|
||||
raise NotImplementedError(_NO_EMBEDDING_MODEL_MSG)
|
||||
|
||||
Reference in New Issue
Block a user