On 4 November 2026 I reviewed MOKS, my AI SRE agent, on my lab cluster. All five investigations since the worker had started ended with a report built from rules instead of by the model, although all 15 model calls had succeeded. The worker's own counters said so. Nobody saw them, because Prometheus was not scraping the application, and the reason each report fell back was written only in the report's notes. I found it by reading one trace. The model was fine; the system around it had quietly stopped using it.

That gap between "the model works" and "the system that uses the model works" is what this article is about. It sets out how I think about the model lifecycle as an ML platform engineer, follows one small LLM-backed service from instrumentation to a working scrape, and lists the pitfalls I have hit. Model registries, drift detection and canary rollouts are out of scope.
LLMOps & MLOps in one paragraph
This is my working definition, not a standard one. MLOps is the practice of treating a model as a production component with a lifecycle: it is built, checked, versioned, deployed, observed, and replaced, and each step leaves evidence. LLMOps is the same discipline when the model is a large language model you often call through a provider rather than train. The weights may not be yours, but the prompts, the provider configuration, the budget, the fallback path and the evaluation set are.
In both cases the model is one part of a pipeline. MOKS, the SRE investigation portal I am building, was built on that rule when I reviewed it. It recorded each model call but not its content, and if no model was configured or the model's answer was unusable, it built the report from rules instead. That design keeps the portal useful, and it is also why the fallback has to be measured. A system that always produces an answer can hide the fact that the model stopped contributing.
How it works
The lifecycle, as I draw it
This is my own drawing, kept generic on purpose: no registry stage names, no serving framework.
flowchart LR
D["Data and prompts"] --> B["Build: train, fine-tune or configure a provider model"]
B --> E["Evaluate against a fixed question set"]
E -->|passes| V["Version the artifact: weights, or prompt + provider config"]
E -->|fails| D
V --> R["Deploy"]
R --> S["Run: online serving, offline pipeline or batch job"]
S --> M["Monitor: requests, errors, latency, tokens, cost, fallbacks"]
M -->|regression or drift in what users ask| D
M -->|bad release| VTwo arrows matter more than the boxes:
- Monitor back to data. What users actually ask is evidence your evaluation set lacks. In MOKS, the evaluation for retrieval reranking used 30 synthetic questions, and I recorded that they cannot represent real incident queries.
- Monitor back to the versioned artifact. If you cannot name the previous good version, you cannot go back to it. For an LLM service, that version includes the prompt and the provider settings, not just a model name.
The run stage has three shapes
The stage where most operational work happens is "Run". Prometheus's instrumentation guidance (opens in a new tab) splits services into three types: online-serving, offline-processing and batch jobs. They map directly onto the shapes ML workloads take:
| Shape | ML example | Key metrics (per the Prometheus page) |
|---|---|---|
| Online serving | An inference endpoint or an LLM-backed API | Queries performed, errors, latency; in-progress requests can help. Monitor on both client and server side |
| Offline processing | An embedding or ingestion pipeline | Per stage: items in, items in progress, last processed time, items out. A heartbeat item passed through shows propagation time |
| Batch job | A nightly retraining or evaluation run | The last time the job succeeded. Push gauges to a PushGateway; for jobs longer than a few minutes, also scrape them |
The same page suggests considering converting batch jobs that run more often than every 15 minutes into daemons. That is a useful check on any "retrain every five minutes" CronJob: at that frequency you are running an offline-processing service and should monitor it as one.
Classifying the workload first tells you which numbers matter. A batch evaluation job with a perfect request-latency dashboard and no "last success" timestamp can silently stop running for a week.
What changes when the model is an LLM
This is my own view from running MOKS:
| Concern | Classic ML service | LLM-backed service (MOKS as the example) |
|---|---|---|
| What you version | Trained weights and features | Prompt, provider, model name and limits; the provider owns the weights |
| Cost signal | Compute per request | Tokens per call, turned into an estimated cost from configured per-million prices |
| Correctness | Offline metrics on a held-out set | Structured output that code validates; unusable answers trigger a fallback |
| Hidden failure | Accuracy degrades while requests succeed | Requests succeed while the system falls back to rules |
| Control flow | Usually one call per request | Often several calls per request, inside a bounded loop |
The last row is why agent systems need traces as well as metrics. At the time of the review, a MOKS investigation was a LangGraph state machine: intake, knowledge, triage, logs, skills and refresh, then a plan and act loop in which the model asked for more evidence, then correlate and report, with a rules node taking over when no usable model answer existed. One user question could mean several model calls, and a per-call metric cannot tell you which node quietly gave up. I explained why MOKS used LangGraph for that control flow (opens in a new tab) in a separate article. MOKS has since moved incident investigations to a CrewAI flow and keeps the graph as its fallback, but nothing below depends on the engine.
A worked example
The example is one LLM-backed service that produces reports. It calls a configured model. If the call fails or the answer is unusable, it builds the report from rules. It is a simplified version of the MOKS pattern, with my own metric names, so that the code runs on its own.
Step 1: decide what to measure before writing code
From the Prometheus guidance, the rules that shape this service's metrics are:
- One metric with labels, not several metrics. The page's example is
http_responses_totalwith acodelabel instead ofhttp_responses_500_totalandhttp_responses_403_total. - A total for every failure counter, so the failure ratio is one division.
- Counters only go up, and they reset on restart. Use
rate()on them. If a value can go down, it is a gauge. - Export a Unix timestamp, not "time since", and compute the age in the query.
- Export 0 for series you know may exist. Most client libraries, including Go, Java and Python, do this automatically, but only for metrics without labels. Labelled series appear the first time a label combination is used, so the example creates them up front.
Applied to the report service, that gives three metrics:
llm_requests_total{provider, model, outcome}: every model call, so successes and failures share one total.reports_total{path}: every report, labelledmodelorrules. MOKS had the same signal asmoks_investigations_total{mode="llm_fallback"}; it only needed someone to collect it.report_last_model_success_timestamp_seconds: when the model last produced a usable report.
The model label is bounded because its values come from configuration, not from requests. MOKS does the same: its model label comes from admin-configured models. That distinction matters for cardinality, which the pitfalls section covers.
Step 2: instrument the service
The script needs Python 3.10 or later, because of the str | None annotation; on Python 3.9 it fails with a TypeError as soon as call_model is defined. I ran it on Python 3.12 with prometheus_client 0.26.0, the version MOKS used. It simulates model calls with random so you can run it without a provider. Replace call_model with your real client.
import random
import time
from prometheus_client import Counter, Gauge, start_http_server
# Models come from configuration, never from request data, so the label stays bounded.
CONFIGURED_MODELS = [("provider-a", "model-a")]
OUTCOMES = ["ok", "error", "unusable"]
PATHS = ["model", "rules"]
LLM_REQUESTS = Counter(
"llm_requests_total",
"Model calls by provider, model and outcome.",
["provider", "model", "outcome"],
)
REPORTS = Counter(
"reports_total",
"Reports produced, by the path that built them.",
["path"],
)
LAST_MODEL_SUCCESS = Gauge(
"report_last_model_success_timestamp_seconds",
"Unix time of the last report built from a usable model answer.",
)
# Labelled series do not exist until first used, so export them at 0 up front.
for provider, model in CONFIGURED_MODELS:
for outcome in OUTCOMES:
LLM_REQUESTS.labels(provider=provider, model=model, outcome=outcome)
for path in PATHS:
REPORTS.labels(path=path)
def call_model(provider: str, model: str) -> str | None:
"""Stand-in for a real provider call. Returns None when the answer is unusable."""
roll = random.random()
if roll < 0.1:
raise RuntimeError("provider error")
if roll < 0.3:
return None
return "a structured report"
def build_report() -> str:
provider, model = CONFIGURED_MODELS[0]
try:
answer = call_model(provider, model)
except RuntimeError:
LLM_REQUESTS.labels(provider=provider, model=model, outcome="error").inc()
answer = None
else:
outcome = "ok" if answer is not None else "unusable"
LLM_REQUESTS.labels(provider=provider, model=model, outcome=outcome).inc()
if answer is None:
REPORTS.labels(path="rules").inc()
return "a report built from rules"
REPORTS.labels(path="model").inc()
LAST_MODEL_SUCCESS.set_to_current_time()
return answer
if __name__ == "__main__":
start_http_server(8000)
while True:
build_report()
time.sleep(1)Note the unusable outcome. In the MOKS review, every model call succeeded at the HTTP level and the reports still fell back. A call that returns 200 with an answer your validator rejects is a failure for the product, even if it is a success for the provider. Counting it as ok is how the fallback stays invisible.
Run it and read the endpoint:
python report_service.py &
sleep 5
curl -s localhost:8000/metrics | grep -E '^(llm_requests_total|reports_total|report_last)'This is what my run printed. The calls are random, so your counts will differ:
llm_requests_total{model="model-a",outcome="ok",provider="provider-a"} 4.0
llm_requests_total{model="model-a",outcome="error",provider="provider-a"} 0.0
llm_requests_total{model="model-a",outcome="unusable",provider="provider-a"} 1.0
reports_total{path="model"} 4.0
reports_total{path="rules"} 1.0
report_last_model_success_timestamp_seconds 1.796112848114532e+09The error series is there at 0 although no call has failed yet, which is the point of creating the labels up front: an alert on it has something to evaluate from the first scrape. Two things the grep hides. The Python client also exports a *_created gauge for every counter series (llm_requests_created, reports_created) with the time it was created. And before the first usable answer, report_last_model_success_timestamp_seconds is 0.0, which matters for the age query below.
Step 3: query it
The fallback ratio is the number that would have shown me the MOKS problem on a dashboard, had anything been collecting it:
sum(rate(reports_total{path="rules"}[15m]))
/
sum(rate(reports_total[15m]))The model failure ratio uses the shared total, which is why rule 2 exists:
sum by (model) (rate(llm_requests_total{outcome!="ok"}[15m]))
/
sum by (model) (rate(llm_requests_total[15m]))And the age of the last good model report, computed in the query from an exported timestamp:
time() - report_last_model_success_timestamp_secondsBecause the gauge starts at 0, this returns the seconds since 1970 until the model has produced one usable answer, so an alert on the age fires right after a restart. I want that: a service that has not used its model once since starting is worth a look. If you don't, add and report_last_model_success_timestamp_seconds > 0 to the alert.
That last query also covers the batch case. A nightly evaluation job that exports the time of its last success can be alerted on with the same subtraction, whatever the job's duration.
Step 4: make Prometheus scrape it, then check that it does
This step looks trivial, and it is the one that failed in my review. The scrape job for MOKS had been sitting in the MOKS repository since 30 October, with a comment saying where it belonged:
# Add to the Prometheus scrape_configs in the tools repository (observability/prometheus),
# next to the jithendar-com job. The headless Service moks-metrics resolves to every MOKS pod.
- job_name: moks
metrics_path: /metrics
dns_sd_configs:
- names: [moks-metrics.moks.svc.cluster.local]
type: A
port: 9464
relabel_configs:
- {target_label: service, replacement: moks}Nobody had copied it there, so every MOKS panel was empty, while a worker's /metrics listed 95,045 successful k8s_triage calls. An empty panel looks the same as a healthy one with no errors.
The job finds pods through DNS. A headless Service (no cluster IP) makes the name resolve to one A record per pod, so Prometheus scrapes every MOKS pod on its metrics port. This is the Service from the MOKS Helm chart, with the templating removed:
apiVersion: v1
kind: Service
metadata:
name: moks-metrics
spec:
clusterIP: None
selector: {app: moks}
ports:
- {name: metrics, port: 9464, targetPort: 9464}If the namespace has NetworkPolicies, the policy also has to let Prometheus in on that port; MOKS's admits the monitoring namespace on 9464 only. Your report service would get the same pair, a headless Service selecting its pods and a job named after it, with its own port in place of 9464.
Then check from Prometheus's side, not the application's. Prometheus records an up sample for every target it scrapes: 1 if the scrape worked, 0 if it failed.
up{job="moks"}After the fix, on 6 November, this returned 1 for every MOKS pod. Before it, it would have returned nothing at all: no target, so no up series. The same list, with each target's last error, is in the HTTP API (here with Prometheus on localhost:9090; I use a port-forward):
curl -s localhost:9090/api/v1/targets \
| jq '.data.activeTargets[] | {job: .labels.job, health, lastError}'Last, ask for a metric you know exists. reports_total should return its two series even when nothing has happened, because they start at 0. If the query comes back empty rather than zero, the problem is collection, not the service.
Step 5: add traces for the parts metrics cannot explain
The counters said that reports fell back. A trace showed where: node report took 65 ms with no model call inside it, while three plan calls before it had answered. The tracing setup is covered in observability for MOKS (opens in a new tab). The parts that matter for LLMOps are:
- Fixed span names:
node <name>,tool <name>,llm.complete,llm.embed,rag.searchandjob <type>. Names never include request data. - Model attributes on the span:
gen_ai.system,gen_ai.request.model,gen_ai.request.max_tokens,gen_ai.usage.input_tokens,gen_ai.usage.output_tokensandgen_ai.response.model, plusmoks.llm.fallback,moks.llm.retriesandmoks.llm.adjusted. - Metadata only. Spans and logs never carry prompts, outputs or retrieved text.
The gen_ai.* names come from the OpenTelemetry GenAI semantic conventions. Those have since moved to their own repository, open-telemetry/semantic-conventions-genai (opens in a new tab), and are still marked Development. The current inference span conventions name the provider gen_ai.provider.name, where MOKS used the older gen_ai.system, and suggest naming the span {gen_ai.operation.name} {gen_ai.request.model}. Check the current names before copying mine.
For reference, mk4 ran the OpenTelemetry Python SDK 1.45.2, prometheus_client 0.26.0, the OpenTelemetry Collector 0.162, Jaeger 2.22, Loki 3.7.9 and Prometheus 3.15 at the time. Those are my versions, not recommendations.
Trade-offs and pitfalls
Label cardinality
The fastest way to break Prometheus with an LLM service is to put request data in labels: a prompt hash, a user ID or a conversation ID. The Prometheus guidance is blunt:
- Each label set is another time series, with RAM, CPU, disk and network costs.
- As a guideline, keep a metric's cardinality below 10. Limit metrics above that to a handful across the system.
- Cardinality over 100, or the potential to reach it, calls for a different approach.
- The vast majority of metrics should have no labels at all.
The page's own example makes the scale clear. Ten thousand nodes give roughly 100,000 series for node_filesystem_avail, which is fine. Adding a per-user quota for 10,000 users would reach double-digit millions, which the page calls "too much for the current implementation of Prometheus".
For LLM services, the rule I follow is that labels describe configuration (provider, model, outcome, path) and traces describe requests. If you need to find the one conversation that went wrong, that is a trace search, not a PromQL query.
Hot-path cost
The guidance says to take care with metric updates in code called more than 100,000 times a second, and cites 12 to 17 ns for a Java counter increment. Model calls are nowhere near that rate. Tokenisers, retrieval scoring loops and per-chunk embedding code can be, so instrument the batch, not the item.
Fallbacks hide failures
A fallback is good design and bad observability. MOKS always produced a report, which is what an on-call engineer needs, and that is exactly why 5 of 5 rule-based reports went unnoticed. If your system degrades gracefully, the degradation needs its own counter (reports_total{path="rules"} above), an alert on its ratio, and a reason. The review added moks_llm_answers_unused_total{stage, reason} for the reason, and the fixes were live by 6 November. That day the counter held one series, stage="report", reason="BudgetExceeded": the three planning calls had used 48,859 of the default 60,000-token budget, and the report prompt carried the same evidence again, so no room was left for its answer.
Don't confuse that with the provider's own fallback. The same change added moks_llm_fallbacks_total for answers served by a different model than the one asked, and moks_llm_retries_total for provider calls repeated after a rate limit or overload. Each is a different failure, and each gets its own counter.
Retries you cannot see
Two findings from the same review are worth checking in any LLM service:
- Every model call began with a refused request. The OpenAI-compatible path retried once without the parameter the server refused, but forgot the adjustment every time. That cost about 2.3 seconds of a 15-second investigation, and no metric showed it; MOKS now remembers the adjustment per endpoint and model.
- The provider SDK's retries were uncounted. The Anthropic SDK version in use, 2.3.0, is built on
httpx2, which the httpx instrumentation does not see. Claude calls got no HTTP child spans, and the SDK's internal retries never appeared anywhere.
The general lesson: do not assume your HTTP instrumentation sees your model client. Make one call, then look for the child span. If it is missing, count retries in your own code around the client.
Metrics that do not exist
MOKS did not stream model output, so time to first token did not exist for it. That is fine, but it means a latency dashboard for MOKS showed total call time only. If you copy an LLM dashboard from somewhere else, check that each panel's metric can exist for your service. Otherwise you will have panels that are empty forever, and that train people to ignore empty panels.
Evaluation sets lie by omission
The 30-question synthetic set I used to evaluate MOKS reranking had two problems I recorded afterwards. It could not represent real incident queries. It also used keyword candidates only, leaving out the vector candidates that production retrieval uses, so it tested a pipeline that was not quite the one in production. An evaluation gate in the lifecycle is only as good as its resemblance to production traffic. The monitor-to-data arrow in the diagram exists to close that gap. The retrieval design under that evaluation is described in how MOKS uses RAG and SKILL.md playbooks (opens in a new tab).
What this leaves out
Drift detection, canary or A/B rollout of models, registry-based versioning and rollback mechanics are not covered here. If you run them, the monitoring above still applies. A canary is only useful if reports_total{path} and the unusable outcome are split by version, so you can see which version is falling back.
When this is too much
If your model is called from one batch job a day, you do not need per-call counters, traces or a fallback ratio. You need the last-success timestamp and an alert on its age. Start from the workload's shape in the table above and add instruments only when a failure shows you something you could not see.
Further reading
- Prometheus instrumentation guidance (opens in a new tab): the source for the metric rules, the three service types and the cardinality limits used here.
- Prometheus querying basics (opens in a new tab) and jobs and instances (opens in a new tab), for the selectors in Step 3 and the
upseries in Step 4. - Observability for MOKS (opens in a new tab), for the full logging, tracing and metrics setup, and the review findings in detail.
What to check next on your own LLM service:
- Does
up{job="<your job>"}return 1 for every instance, and does a known metric return zero rather than nothing? - Is there a counter for each fallback path, with an alert on its ratio and a label for the reason?
- Does a single model call produce an HTTP child span? If not, where are retries counted?
- Do any metric labels come from request data rather than configuration?



Discussion comments
No comments yet. Start the discussion.