Skip to content

fix(project): validate metric plugin options when saving a project - #9228

Open
chenwei791129 wants to merge 2 commits into
apache:mainfrom
chenwei791129:fix/validate-metric-options-on-save
Open

chenwei791129 wants to merge 2 commits into
apache:mainfrom
chenwei791129:fix/validate-metric-options-on-save

Conversation

@chenwei791129

@chenwei791129 chenwei791129 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Validate metric plugin options when a project is created or updated, instead of only when a pipeline plan
is generated.

  • refactor(project): extract the single-metric plan generation of GeneratePlanJsonV200 into
    makeMetricPluginPlan. No behavior change; it lets plan generation and save-time validation share the
    same rules (e.g. empty options default to {}).
  • fix(project): CreateProject and PatchProject call validateProjectMetrics before opening the
    transaction or touching the database. It dry-runs MakeMetricPluginPipelinePlanV200 for every
    enabled metric, discards the plan, and returns errors.BadInput (HTTP 400)
    invalid options for metric plugin <name> wrapping the plugin's error.
    • Disabled metrics are skipped, matching MakePlanForBlueprint (the Settings page always sends every
      metric, with enable: false for disabled ones).
    • An enabled metric whose plugin is not loaded or does not implement MetricPluginBlueprintV200 is
      rejected too, since plan generation would fail on it anyway.
    • PatchProject validates with the post-save project name (the new name on rename).
  • Update the monorepo comment that claimed a bad regex is reported "when the blueprint is saved".
Before
  Save ─► POST/PATCH /projects ─► store pluginOption ─► 2xx
                                                          ⋮  (next Collect Data / cron)
                                  MakePlanForBlueprint ─► plugin rejects option ─► blueprint fails

After
  Save ─► POST/PATCH /projects ─► validateProjectMetrics (enabled metrics only)
                                    │  dry-run MakeMetricPluginPipelinePlanV200, discard plan
                                    ├─ invalid ─► 400 BadInput, nothing written ─► error toast in UI
                                    └─ valid ───► begin tx ─► store pluginOption ─► 2xx

No Config UI change: the Save button already shows the API error as a toast and the settings are not
stored.

Does this close any open issues?

Closes #9227

Screenshots

N/A — backend only.

Other Information

Compatibility

  • POST /projects / PATCH /projects/:projectName now return 400 instead of 2xx when an enabled metric
    has invalid options (e.g. an invalid monorepo deployJobPattern, or monorepo enabled with no
    subProjects). Such requests previously stored settings that broke the next pipeline run.
  • Invalid settings already stored in the database are not affected until the project is saved again;
    no migration.

Tests

New backend/server/services/project_metric_validation_test.go:

  • valid options pass; empty options reach the plugin as {};
  • a plugin error becomes BadInput and keeps the original error in the chain;
  • disabled and nil metrics are never invoked;
  • unknown / non-metric plugins are rejected;
  • CreateProject and PatchProject reject invalid options with a DAL mock that has no expectations,
    proving nothing is written and no transaction is opened; PatchProject uses the new name on rename
    and the current name otherwise.

go test ./server/services/... plus the dora / linker / issue_trace / monorepo unit tests pass;
golangci-lint run ./server/... is clean.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Project] Invalid metric plugin options are accepted on project save and only fail at the next pipeline run

1 participant