Skip to content

[IGNORE] alertmanager: add CUE schema tests - #933

Open
s3onghyun wants to merge 1 commit into
perses:mainfrom
s3onghyun:fix/perses-am-schema-tests
Open

s3onghyun wants to merge 1 commit into
perses:mainfrom
s3onghyun:fix/perses-am-schema-tests

Conversation

@s3onghyun

Copy link
Copy Markdown
Contributor

Description

Adds valid/invalid CUE model fixtures for every alertmanager schema (datasource, alerts query, silences query, AlertTable, SilenceTable) so make test-schemas-plugins covers this plugin; before this change percli plugin test-schemas --plugin.path=alertmanager reported "No tests found" (jaeger has 2 fixtures, prometheus 9).

Fixtures only, no schema or runtime change. make test-schemas-plugins passes locally with percli v0.55.1 (24 alertmanager tests); breaking one valid fixture makes it fail as expected. Field values follow alertmanager/src (column sort modes, silence field names, actions, colour mappings).

While writing them I noticed that alert-table.cue does not allow sortMode: "status" although the TS model, the columns editor and the sorting code support it; I left that out of this PR and will open a separate small fix.

Screenshots

n/a (no UI change)

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.

Add valid and invalid model fixtures for every alertmanager schema (datasource, alerts query, silences query, AlertTable and SilenceTable panels) so that `make test-schemas-plugins` exercises them. Fixtures only, no schema or runtime change.

Signed-off-by: Joshua (OpenClaw) <s3onghyun@users.noreply.github.com>

@Nexucis Nexucis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding these, LGTM!

Checked locally

  • percli plugin test-schemas --plugin.path=alertmanager with percli v0.55.1 (the CI version): No tests found on main, 24/24 passing on this branch.
  • Fixing only the intended defect in each invalid fixture makes it validate (14 corrected copies, both-modes.json both ways), so none of them fails for an unrelated reason.
  • All files are valid JSON and pass oxfmt --check.

Optional suggestions

  1. datasource/tests/valid/alertmanager-proxy.json is missing two endpoints allowed by the editor's default proxy config (AlertManagerDatasourceEditor.tsx): GET /api/v2/silence/.* and GET /api/v2/status. The latter is the plugin's healthCheckPath, so the proxy would answer the health check with a 403 if someone reused this config. Mirroring the editor default would make it a realistic example.
  2. silence-table/tests/valid/full.json configures status, matchers and comment, which are the built-in default columns: the columns editor doesn't offer them, and SilenceTablePanel drops them from spec.columns before prepending its own defaults. Columns users can actually add (startsAt, duration, updatedAt, ...) would be more representative.
  3. Cheap cases that pass today and would add coverage:
    • valid: a variable datasource selector ("datasource": "$alertmanager") in both query schemas
    • invalid: an empty datasource spec (neither directUrl nor proxy)
    • invalid: an unknown labelColorMappings[].mode
    • invalid: an unknown column sort value
  4. alert-table/tests/valid/deduplication-fingerprint.json also covers allowedActions: []; splitting it would keep one concern per fixture.

Out of scope, found while checking coverage

  • An invalid fixture for a datasource selector of the wrong kind can't be added yet, because the schemas accept it: {"kind": "AlertManagerAlertsQuery", "spec": {"datasource": {"kind": "PrometheusDatasource"}}} validates, and so does a PrometheusTimeSeriesQuery pointing at a TempoDatasource. The datasource plugins define #selector: common.#datasourceSelector & {_kind: #kind}, but CUE hidden fields are scoped to their package, so the plugin's _kind isn't the _kind declared in perses/shared and kind accepts any string. In a minimal two-package reproduction, the pattern rejects a wrong kind within one package but accepts it across packages, and passing the kind through a definition field (#kind) instead fixes it. This needs a change in perses/shared and the plugins, and tightening it could start rejecting saved dashboards that use a mismatched kind, so it deserves its own issue.
  • +1 to fixing sortMode: "status" in alert-table.cue separately: the columns editor offers it, so a panel using it currently fails schema validation. A valid fixture using it would fit well in that PR.
  • The SilenceTable schema accepts any column name, while the TS model only allows the 8 SilenceFieldName values; that could be tightened at the same time.

FYI: the DCO check ran on #934 but hasn't reported on this PR. It's not a required check and the commit is signed off, so it doesn't block.

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.

2 participants