Sub topic 13
Monitoring and troubleshooting an endpoint
This chapter assumes you have already created an endpoint named iris-endpoint for main.default.iris_classifier and queried it with a token. It also assumes you can read a Python traceback and an HTTP status code. By the end you should be able to read an endpoint's health, find the logs that explain a failure, and match common symptoms to causes.
Where problems show up
A serving endpoint can fail at four points. Each point leaves evidence in a different place, so it helps to know which one you are dealing with before you open any logs.
- Deployment. The endpoint never becomes ready, or an update fails. The evidence is the endpoint state and the build logs.
- Request. The request is rejected before it reaches your model. The evidence is the HTTP status code and the error body.
- Inference. The model receives the request and raises an exception. The evidence is the service logs.
- Capacity. The model works but is slow or rejects traffic. The evidence is the metrics charts.
Reading endpoint state
The endpoint page in the workspace shows a Ready or Not ready status. The SDK returns the same information, so you can check it from a script or a CI job. The state has two parts. ready says whether the endpoint can serve traffic. config_update says whether a create or update is running, finished, or failed.
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
ep = w.serving_endpoints.get(name="iris-endpoint")
print("ready:", ep.state.ready.value if ep.state.ready else None)
print("config_update:", ep.state.config_update.value if ep.state.config_update else None)
for entity in ep.config.served_entities:
print("served entity:", entity.name, "->", entity.entity_name, "v" + str(entity.entity_version))A healthy endpoint prints READY and NOT_UPDATING. You will see these combinations most often.
| `ready` | `config_update` | Meaning |
|---|---|---|
| `NOT_READY` | `IN_PROGRESS` | The endpoint is being created or updated. Wait, and check the build logs if it takes too long. |
| `READY` | `IN_PROGRESS` | An update is rolling out. The previous configuration still serves traffic. |
| `READY` | `NOT_UPDATING` | Normal steady state. |
| `READY` | `UPDATE_FAILED` | The update failed. The previous configuration is still serving. |
| `NOT_READY` | `UPDATE_FAILED` | The first deployment failed. Nothing is serving. |
The second row is the one that makes updates safe. If you roll an endpoint forward to a new version and the new container fails to start, the old version keeps answering requests. Read UPDATE_FAILED as "the change did not apply", not "the endpoint is down". Check the first column to tell which one you have.
Build logs and service logs
Serving has two kinds of logs, and people often open the wrong one.
- Build logs record how the container image was assembled. This covers installing the dependencies recorded with the model, such as the contents of
requirements.txt. Read them when an endpoint stays inIN_PROGRESSand then fails, or when the error mentions a package. - Service logs record what the running container prints. This includes the stack trace when your model code raises an exception during
predict. Read them when the endpoint is ready but some requests return 500.
Both are on the endpoint page in the Logs tab, and both are available through the SDK. Logs are kept per served entity, so you need the entity's name. It defaults to the model name and version, for example iris_classifier-1, so read it from the endpoint instead of guessing.
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
name = "iris-endpoint"
ep = w.serving_endpoints.get(name=name)
served_name = ep.config.served_entities[0].name
build = w.serving_endpoints.build_logs(name=name, served_model_name=served_name)
print("--- build logs ---")
print(build.logs)
service = w.serving_endpoints.logs(name=name, served_model_name=served_name)
print("--- service logs ---")
print(service.logs)Service logs are only useful if your model writes something. Standard Python logging or print output from a custom pyfunc model appears there. For a plain scikit-learn model you mostly get the traceback, which is usually enough.
Reading the metrics
The Metrics tab charts the endpoint's behavior over time. Read these charts together, because one chart rarely explains a problem alone.
- Request rate and error rate. Requests per second, and the share that ended in 4xx or 5xx. A sudden jump in errors right after a deployment points to the new version. A steady low error rate points to a client sending bad payloads.
- Latency. Reported as percentiles such as p50 and p99. A p99 far above p50 usually means occasional cold starts or a few unusually large requests, not a uniformly slow model.
- CPU and memory usage. Memory near its limit is a strong signal. An out-of-memory container restarts, and the requests in flight fail.
- Provisioned concurrency. Shows how much capacity the endpoint has scaled to. If requests are queued or rejected while concurrency sits at its maximum, the workload size is too small for the traffic.
If you chose scale to zero in the previous chapters, expect the latency chart to show spikes after quiet periods. This is the cost of paying nothing while idle. If the spikes break a latency requirement, turn scale to zero off and accept the standing cost.
Reading status codes
Most client-side debugging starts with the HTTP status code. The table below lists the codes you are most likely to see from the invocations URL and the usual cause of each.
| Status | Usual cause | First thing to check |
|---|---|---|
| 400 | The payload does not match the model signature. | Column names, column count and types in the JSON. |
| 401 | The token is missing, expired or malformed. | The `Authorization: Bearer` header and the token's validity. |
| 403 | The identity is valid but lacks permission. | The endpoint's **Can Query** permission for that user or service principal. |
| 404 | The endpoint name or workspace host is wrong. | The URL path `/serving-endpoints/<name>/invocations`. |
| 429 | Too many requests for the available capacity. | Request rate against workload size and any rate limits. |
| 500 | The model raised an exception while predicting. | The service logs. |
| 503 | The endpoint is not ready or is starting up. | The endpoint state, and whether it scaled to zero. |
A 400 on an endpoint that worked yesterday usually means the client changed, not the model. The signature you logged defines the exact column names. sepal length (cm) is not the same as sepal_length. The error body names the offending column, so print it instead of only the status code.
A 403 is easy to confuse with a Unity Catalog privilege problem. Calling an endpoint needs permission on the endpoint itself. The privileges from earlier chapters (USE CATALOG, USE SCHEMA, EXECUTE) matter when you create or update the endpoint, because the endpoint reads the model from Unity Catalog. They do not grant the right to query it.
The script below calls the endpoint and prints the status and body whenever the call fails, with a retry for the transient codes only.
import os
import time
import requests
HOST = os.environ["DATABRICKS_HOST"].rstrip("/") # e.g. https://<workspace-host>
TOKEN = os.environ["DATABRICKS_TOKEN"]
URL = f"{HOST}/serving-endpoints/iris-endpoint/invocations"
payload = {
"dataframe_split": {
"columns": [
"sepal length (cm)",
"sepal width (cm)",
"petal length (cm)",
"petal width (cm)",
],
"data": [[5.1, 3.5, 1.4, 0.2]],
}
}
for attempt in range(1, 5):
resp = requests.post(
URL,
headers={"Authorization": f"Bearer {TOKEN}"},
json=payload,
timeout=120,
)
if resp.ok:
print(resp.json())
break
print(f"attempt {attempt}: HTTP {resp.status_code}: {resp.text[:500]}")
if resp.status_code not in (429, 503):
break # 4xx and 500 will not fix themselves, so stop and investigate
time.sleep(2 ** attempt)Retrying only 429 and 503 is deliberate. Those codes can clear on their own when capacity arrives or a container finishes starting. A retry cannot fix a 400 or a 500, and repeating them only adds noise to your logs.
Recording requests with inference tables
Logs and charts tell you what happened recently. To review what the endpoint actually received, enable an inference table. This feature writes each request and response to a Delta table in Unity Catalog. You enable it from the endpoint's AI Gateway settings and choose a catalog and schema for the table.
The table is useful for three jobs:
- Reproducing a failure. You can find a request with
status_code = 500and replay its exact payload. - Checking for drift. You can compare the distribution of incoming features with your training data.
- Auditing. You can show who or what called the model and when.
Typical columns include the request time, the status code, the request and response bodies, and the execution time. Rows are written in batches, so recent requests can take a while to appear. Do not use the table for live alerting. Because the table lives in Unity Catalog, the identity enabling it needs privileges on the target catalog and schema, and you control who can read the payloads with the same GRANT statements used for models. Payloads can contain sensitive data, so grant access narrowly.
A debugging routine
When an endpoint misbehaves, work through the same order each time. It is faster than guessing.
- Read the state. If it is
NOT_READYorUPDATE_FAILED, go to the build logs. - Reproduce the failure with a single request, and print the full status code and body.
- For a 4xx, compare your payload to the model signature. Then check the token and the endpoint permission.
- For a 500, read the service logs for the traceback at the time of the request.
- For slowness or 429, open the metrics and compare latency, memory and provisioned concurrency with the traffic.
- If you cannot reproduce it, query the inference table for the failing rows.
- After a bad update, check which version the endpoint serves. If the cause is the new version, repoint the endpoint at the previous one, as in the update chapter.
Exercise
A client reports HTTP 500 from iris-endpoint. The endpoint page shows Ready, and the metrics show a normal request rate. Which logs do you open first, and why? What would you check if the code were 400 instead?
Show answer
Open the service logs. The endpoint is ready, so the container built and started, and a 500 means the model raised an exception while handling a request. The traceback is in the service logs, not the build logs. For a 400, compare the request payload to the model signature (column names, count and types), because the error means the input shape is wrong and the request never reached the model.
Exercise
You update the endpoint to a new model version and the state shows READY with UPDATE_FAILED. Is the endpoint down? Where do you look for the cause?
Show answer
No. The previous configuration is still serving traffic, because a failed update does not replace the working one. Read the build logs for the new version first, since dependency installation is the most common cause. Then check the events and service logs if the container built but would not start.