Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions docs/reference/feature-servers/python-feature-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ thread from starting). All categories default to `true` except
|--------|------|--------|----------|-------------|
| `feast_feature_server_cpu_usage` | Gauge | — | `resource` | Process CPU usage % |
| `feast_feature_server_memory_usage` | Gauge | — | `resource` | Process memory usage % |
| `feast_feature_server_request_total` | Counter | `endpoint`, `status`, `status_class` | `request` | Total requests per endpoint and response status (see below) |
| `feast_feature_server_request_latency_seconds` | Histogram | `endpoint`, `feature_count`, `feature_view_count` | `request` | Request latency with p50/p95/p99 support (`feature_count` is bucketed, see below) |
| `feast_feature_server_request_total` | Counter | `endpoint`, `status`, `status_class`, `feature_service` | `request` | Total requests per endpoint and response status (see below) |
| `feast_feature_server_request_latency_seconds` | Histogram | `endpoint`, `feature_count`, `feature_view_count`, `feature_service` | `request` | Request latency with p50/p95/p99 support (`feature_count` is bucketed, see below) |
| `feast_online_features_request_total` | Counter | — | `online_features` | Total online feature retrieval requests |
| `feast_online_features_entity_count` | Histogram | — | `online_features` | Entity rows per online feature request |
| `feast_feature_server_online_store_read_duration_seconds` | Histogram | — | `online_features` | Online store read phase duration (sync and async) |
Expand Down Expand Up @@ -405,6 +405,36 @@ This produces the labels `0`, `1-5`, `6-20`, and `21+`. Note that this only
affects the Prometheus label; the `feature_count` field in audit logs (see
below) always reports the exact count.

### Feature service label

Set `feature_service_label: true` to label
`feast_feature_server_request_total` and
`feast_feature_server_request_latency_seconds` with the feature service a
`/get-online-features` request was made through:

```yaml
feature_server:
type: local
metrics:
enabled: true
feature_service_label: true
```

It is off by default. Each feature service adds its own set of latency
histogram series, so turn it on only when the number of feature services is
bounded. When it is off, and for requests that list features directly, the
label is empty.

For example, p99 latency per feature service:

```promql
histogram_quantile(0.99,
sum by (feature_service, le) (
rate(feast_feature_server_request_latency_seconds_bucket{endpoint="/get-online-features"}[5m])
)
)
```

### Request status labels

`feast_feature_server_request_total` carries two status labels derived from
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/feast/feature_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ async def lifespan(app: FastAPI):
if metrics_cfg is not None
else default_feature_count_bins
)
feature_service_label = getattr(metrics_cfg, "feature_service_label", False)

@app.post(
"/get-online-features",
Expand All @@ -683,6 +684,8 @@ async def get_online_features(request: GetOnlineFeaturesRequest) -> Any:
feature_count_bins,
)
metrics_ctx.feature_view_count = fv_count
if feature_service_label:
metrics_ctx.feature_service = request.feature_service or ""
Comment on lines +687 to +688

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.

🟨 Client spellings inflate metrics cardinality

With labeling enabled, get_online_features uses the submitted name rather than the resolved name. An uncached MySQL registry with a case-insensitive collation accepts different spellings for the same service. An authorized caller can create separate counter and histogram series for that one service.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


entity_count = len(next(iter(request.entities.values()), []))
feast_metrics.track_online_features_entities(entity_count)
Expand Down
9 changes: 9 additions & 0 deletions sdk/python/feast/infra/feature_servers/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ def validate_feature_count_bins(cls, bins: list[int]) -> list[int]:

return bins

feature_service_label: StrictBool = False
"""Label ``feast_feature_server_request_total`` and
``feast_feature_server_request_latency_seconds`` with the name of the
feature service a ``/get-online-features`` request was made through.

Off by default: every feature service adds its own set of histogram
series, so enable it only when the number of feature services is
bounded. When off, the label is always ``""``."""

online_features: StrictBool = True
"""Emit online feature retrieval metrics
(feast_online_features_request_total,
Expand Down
28 changes: 22 additions & 6 deletions sdk/python/feast/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ def build_metrics_flags(metrics_config: Optional[object] = None) -> _MetricsFlag
request_count = Counter(
"feast_feature_server_request_total",
"Total number of requests to the Feast feature server",
["endpoint", "status", "status_class"],
["endpoint", "status", "status_class", "feature_service"],
)
request_latency = Histogram(
"feast_feature_server_request_latency_seconds",
"Latency of requests to the Feast feature server in seconds",
["endpoint", "feature_count", "feature_view_count"],
["endpoint", "feature_count", "feature_view_count", "feature_service"],
buckets=(0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0),
)

Expand Down Expand Up @@ -318,18 +318,29 @@ class RequestMetricsContext:
to ``200`` and is derived from the exception when the block raises,
so handlers only need to set it when they *return* a non-2xx
response (e.g. a 404 or 409 ``JSONResponse``).

``feature_service`` is the name of the feature service the request
was made through, or ``""`` when there is none or the label is
disabled via ``MetricsConfig.feature_service_label``.
"""

__slots__ = ("feature_count", "feature_view_count", "status_code")
__slots__ = (
"feature_count",
"feature_view_count",
"feature_service",
"status_code",
)

def __init__(
self,
feature_count: str = "",
feature_view_count: str = "",
feature_service: str = "",
status_code: int = 200,
):
self.feature_count = feature_count
self.feature_view_count = feature_view_count
self.feature_service = feature_service
self.status_code = status_code


Expand Down Expand Up @@ -358,12 +369,15 @@ def _status_class(status_code: int) -> str:

@contextmanager
def track_request_latency(
endpoint: str, feature_count: str = "", feature_view_count: str = ""
endpoint: str,
feature_count: str = "",
feature_view_count: str = "",
feature_service: str = "",
):
"""Context manager that records endpoint latency and increments request count.

Yields a :class:`RequestMetricsContext` whose ``feature_count``,
``feature_view_count`` and ``status_code`` attributes can be updated
``feature_view_count``, ``feature_service`` and ``status_code`` attributes can be updated
inside the block. The final values are used when recording the
histogram and counter in ``finally``, so labels are accurate even
when they depend on work done inside the block.
Expand All @@ -375,7 +389,7 @@ def track_request_latency(

Gated by the ``request`` category flag.
"""
ctx = RequestMetricsContext(feature_count, feature_view_count)
ctx = RequestMetricsContext(feature_count, feature_view_count, feature_service)
if not _config.request:
yield ctx
return
Expand All @@ -392,11 +406,13 @@ def track_request_latency(
endpoint=endpoint,
feature_count=ctx.feature_count,
feature_view_count=ctx.feature_view_count,
feature_service=ctx.feature_service,
).observe(elapsed)
request_count.labels(
endpoint=endpoint,
status="success" if ctx.status_code < 400 else "error",
status_class=_status_class(ctx.status_code),
feature_service=ctx.feature_service,
).inc()


Expand Down
Loading