Skip to content

Phase 0 for OpenMetrics flow: Inspect Endpoint#23848

Merged
luisorofino merged 5 commits into
loa/openmetrics-ai-genfrom
loa/phase0-openmetrics
Jun 1, 2026
Merged

Phase 0 for OpenMetrics flow: Inspect Endpoint#23848
luisorofino merged 5 commits into
loa/openmetrics-ai-genfrom
loa/phase0-openmetrics

Conversation

@luisorofino
Copy link
Copy Markdown
Contributor

@luisorofino luisorofino commented May 27, 2026

What does this PR do?

Adds Phase 0 (InspectEndpointPhase) for the OpenMetrics integration-generation flow, plus the orchestrator plumbing needed to support flow-specific phase modules.

InspectEndpointPhase is a fully deterministic (non-agentic) phase that:

  1. Fetches the target Prometheus/OpenMetrics endpoint over HTTP.
  2. Validates the response is reachable (HTTP 200) and contains parseable exposition (Prometheus or OpenMetrics format).
  3. Writes a <phase_id>_metrics.jsonl sidecar next to the checkpoint file — one JSON row per metric family — carrying name, type, help, unit, label_keys, and sample_count. This catalog is the ground-truth input later phases will use for metric renaming, metrics.py mapping, and metadata.csv generation.
  4. Produces a markdown memory blob summarising the inspection result (URL, HTTP status, content-type, exposition format, metric count, catalog path).

Orchestrator change_discover_and_register_phases is refactored to accept an explicit (phases_dir, import_prefix) pair. On startup the orchestrator now runs discovery twice: once for the built-in phases under ddev.ai.phases, and once for any phases/ subdirectory sitting next to the active flow.yaml. This lets OpenMetrics (and future flows) ship their own phase modules without touching the core framework.

Minor checkpoint fixCheckpointManager gains a memory_dir property (the directory of the checkpoint file) so phases can resolve sidecar paths without re-deriving it themselves. Also, keys are now sorted so that chekpoints preserve a natural structure and become clearer to understand.

Dependencyprometheus-client is added as an optional [ai] dependency in pyproject.toml; the hatch.toml default environment now installs this extra so all AI tests run with the full dependency set.

Motivation

Phase 0 is the mandatory first step of the OpenMetrics flow: before any agent can propose a configuration, the framework needs a structured, exhaustive catalog of every metric family the endpoint actually exposes. A deterministic phase is ideal here — no LLM is needed and the output is fully reproducible, keeping token costs at zero for this step.

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

@luisorofino luisorofino added the qa/skip-qa Automatically skip this PR for the next QA label May 27, 2026
@dd-octo-sts dd-octo-sts Bot added the ddev label May 27, 2026
@luisorofino luisorofino changed the title Loa/phase0 openmetrics AI OpenMetrics flow: Phase 0 – deterministic endpoint inspection May 27, 2026
@datadog-official

This comment has been minimized.

@luisorofino luisorofino changed the title AI OpenMetrics flow: Phase 0 – deterministic endpoint inspection Phase 0 for OpenMetrics flow: Inspect Endpoint May 27, 2026
@luisorofino luisorofino marked this pull request as ready for review May 27, 2026 15:00
@luisorofino luisorofino requested a review from a team as a code owner May 27, 2026 15:00
Copy link
Copy Markdown

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

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: 7695ec2f13

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if flow_phases_dir.is_dir():
ai_root = Path(__file__).parent.parent
try:
rel = flow_phases_dir.relative_to(ai_root)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve flow phase paths before comparing

When callers pass a relative flow_yaml_path for a packaged flow, flow_phases_dir is also relative but ai_root comes from __file__ and is absolute, so this relative_to() call raises FlowConfigError even though the phases/ directory is actually under ddev.ai. This makes the new OpenMetrics flow fail to initialize depending only on whether the path was supplied as relative or absolute; resolve both paths before doing the containment check/import-prefix calculation.

Useful? React with 👍 / 👎.

def _parse_exposition(body: str, content_type: str) -> tuple[list[Metric], str]:
"""Parse body with the parser matching content_type.

Returns (families, exposition_format) where exposition_format is
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize the OpenMetrics content type

HTTP media types are case-insensitive, but this check only recognizes lowercase application/openmetrics-text. If an endpoint returns a valid OpenMetrics body with a capitalized header such as Application/OpenMetrics-Text; version=1.0.0, the phase falls back to the Prometheus parser, which can reject or miscatalog OpenMetrics-specific features like units/exemplars. Lowercase the media type portion before choosing the parser.

Useful? React with 👍 / 👎.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 97.96840% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.30%. Comparing base (c6bddc5) to head (7695ec2).

Additional details and impacted files
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@luisorofino luisorofino force-pushed the loa/phase0-openmetrics branch from 7695ec2 to e76a198 Compare May 29, 2026 08:27
Copy link
Copy Markdown
Contributor Author

luisorofino commented May 29, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Base automatically changed from loa/subagent-tool to loa/openmetrics-ai-gen June 1, 2026 08:31
@luisorofino luisorofino force-pushed the loa/phase0-openmetrics branch from e76a198 to 9ecf0b2 Compare June 1, 2026 08:56
@luisorofino luisorofino merged commit f319783 into loa/openmetrics-ai-gen Jun 1, 2026
315 of 325 checks passed
@luisorofino luisorofino deleted the loa/phase0-openmetrics branch June 1, 2026 08:57
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Jun 1, 2026

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

luisorofino added a commit that referenced this pull request Jun 1, 2026
* First implementation of Phase0

* Merge phase0 and phase1 into phase0. Add metrics dumping to jsonl.

* Raise if flow not in ddev.ai

* Check if endpoint returns response bigger than 10MB

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

Labels

ddev qa/skip-qa Automatically skip this PR for the next QA team/agent-integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants