Skip to content

torchserve: add container-based config discovery support - #24609

Draft
martavicentenavarro wants to merge 8 commits into
masterfrom
feat/martavicentenavarro/DSCVR-485-torchserve-config-discovery
Draft

torchserve: add container-based config discovery support#24609
martavicentenavarro wants to merge 8 commits into
masterfrom
feat/martavicentenavarro/DSCVR-485-torchserve-config-discovery

Conversation

@martavicentenavarro

@martavicentenavarro martavicentenavarro commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds container-based config discovery to torchserve, scoped to the OpenMetrics endpoint.

  • Port: 8082, TorchServe's documented default Metrics API port.
  • Port exclusions: TorchServe also exposes Inference (8080, plus 7070 for gRPC) and Management (8081, plus 7071 for gRPC) on the same container. Discovery's fallback probes every other exposed port if 8082 doesn't answer, so those four ports are explicitly excluded — probing the gRPC ones over HTTP just logs container-side errors.
  • Scope: Inference and Management APIs can't qualify for discovery at all, even without the port exclusion — they only emit a service check, no metrics, and discovery's probe requires at least one metric to accept a candidate. Both remain manually configurable.
  • Tooling fix included: also fixes _get_instance_option_names in datadog_checks_dev's spec validator, which didn't recurse into multiple_instances_defined's nested option groups (torchserve's three instance modes). Bundled here since it's what unblocked this PR; the fix is general and covers any integration with this spec shape.

Motivation

https://datadoghq.atlassian.net/browse/DSCVR-556

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

Adds a discovery stanza to the spec (one from_ports strategy per
mode — OpenMetrics, Inference API, Management API — since each port
maps to exactly one candidate config), wires the E2E fixture to expose
auto_conf.yaml/container labels to the Agent, and adds a combined
discovery E2E test alongside a stability check across all candidates.

Also fixes _get_instance_option_names in datadog_checks_dev's spec
validator: it only read top-level instance group names, so specs using
multiple_instances_defined together with a discovery stanza (like this
one) failed validation because the validator couldn't see the actual
field names nested under each instance mode.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Jul 20, 2026

Copy link
Copy Markdown

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 88.14%
Overall Coverage: 69.05% (-19.28%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 19ff436 | Docs | Datadog PR Page | Give us feedback!

Add container-based config discovery for TorchServe, restricted to its
OpenMetrics endpoint (port 8082):

- Generate an `openmetrics_endpoint` candidate from discovered ports, with
  8082 preferred as the configured port hint.
- Exclude TorchServe's known non-metrics ports (8080 inference API, 8081
  management API) from candidate generation, while still falling back to
  other exposed ports in case OpenMetrics is served on a custom port.
- Default the openmetrics/inference/management endpoint options to `None`
  instead of a hardcoded host:port, so discovered instances don't collide
  with a stale default.
- Fix `_get_instance_option_names` in datadog_checks_dev's spec validator
  to unwrap `multiple_instances_defined` mode groups by exactly one level
  instead of recursing arbitrarily, which the new discovery config
  triggered.
- Add unit tests for the discovery candidate generation (including the
  custom-port fallback and candidate ordering) and E2E coverage exercising
  discovery end-to-end.
@martavicentenavarro
martavicentenavarro force-pushed the feat/martavicentenavarro/DSCVR-485-torchserve-config-discovery branch from a08ee03 to d8fae0e Compare July 20, 2026 16:52
martavicentenavarro and others added 3 commits July 20, 2026 19:02
The comment and changelog entry incorrectly implied both the Inference and
Management APIs submit only service checks. Management actually submits
gauge metrics; the reason it isn't discovered is that discovery is scoped
to OpenMetrics only.
…llback

The TorchServe image exposes gRPC ports 7070/7071 in addition to the HTTP
8080/8081/8082 ports, even though the test compose file only publishes the
latter three. The custom-port fallback treated 7070/7071 as OpenMetrics
candidates, and probing a gRPC port over HTTP logs container-side errors,
which failed test_e2e_discovery_all_candidates in CI. Exclude them alongside
the HTTP Inference/Management ports.
The README had no mention of the new discovery support, so a customer
relying on autodiscovery had no signal that only the OpenMetrics
endpoint is auto-configured, or that metrics_mode must be set to
prometheus for discovery to work at all. Document both, matching the
style already used on gitlab_runner's README for its own discovery
scoping note.

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@martavicentenavarro

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 8b3f8a80ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b3f8a80ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread torchserve/datadog_checks/torchserve/config_models/discovery_overrides.py Outdated
…'s default param

Codex flagged the untyped default parameter as violating AGENTS.md's
type-hinting rule for newly generated code. Typed it as the callable
it actually is (matches _generated_candidates' own signature).

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@martavicentenavarro

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 19ff436774

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread torchserve/README.md

Follow the instructions below to install and configure this check for an Agent running on a host. For containerized environments, see the [Autodiscovery Integration Templates][3] for guidance on applying these instructions.

#### Container-based configuration discovery

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.

Suggested change
#### Container-based configuration discovery
### Container-based configuration discovery

Comment thread torchserve/README.md

#### Container-based configuration discovery

This check supports [Autodiscovery][3] based on containers exposing TorchServe's OpenMetrics endpoint (default port `8082`). Discovery only generates an `openmetrics_endpoint` instance; the Inference API and Management API endpoints cannot be derived automatically and remain manually configurable, as described below. Discovery also requires `metrics_mode` to be set to `prometheus` in `config.properties`, since TorchServe defaults to `log` mode, which the Agent cannot scrape.

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.

Suggested change
This check supports [Autodiscovery][3] based on containers exposing TorchServe's OpenMetrics endpoint (default port `8082`). Discovery only generates an `openmetrics_endpoint` instance; the Inference API and Management API endpoints cannot be derived automatically and remain manually configurable, as described below. Discovery also requires `metrics_mode` to be set to `prometheus` in `config.properties`, since TorchServe defaults to `log` mode, which the Agent cannot scrape.
This check supports [Autodiscovery][3] based on containers exposing TorchServe's OpenMetrics endpoint (default port `8082`). Discovery only generates an `openmetrics_endpoint` instance; Autodiscovery cannot derive the Inference API and Management API endpoints, configure those manually using the steps in the [Configuration](#configuration) section. Discovery also requires `metrics_mode` to be set to `prometheus` in `config.properties`, since TorchServe defaults to `log` mode, which the Agent cannot scrape.

@dd-octo-sts

dd-octo-sts Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and code coverage settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants