Skip to content

Add a minimal Pydantic model for Mimir coordinator config - #461

Open
Moetez-Fradi wants to merge 1 commit into
canonical:mainfrom
Moetez-Fradi:feat/mimir-config-pydantic
Open

Add a minimal Pydantic model for Mimir coordinator config#461
Moetez-Fradi wants to merge 1 commit into
canonical:mainfrom
Moetez-Fradi:feat/mimir-config-pydantic

Conversation

@Moetez-Fradi

Copy link
Copy Markdown

Type-check existing fields so invalid config fails at build time instead of sending broken data over relations.

Issue

The coordinator builds Mimir config as an un-typed dict and ships it over relation data, so a malformed config only fail later, when workers try to start (long retry loop). See #38

This PR is the first part requested in the review: a minimal Pydantic model of the fields we already emit (tempo-style).

Solution

  • Add nested Pydantic models in coordinator/src/mimir_config.py covering only the sections MimirConfig.config() already produces (alertmanager, ingester, limits, storage, TLS, etc.).
  • Validate the assembled dict with MimirConfigModel.model_validate(...) before yaml.dump, so a bad shape fails on the coordinator at build time.
  • Keep _build_* helpers returning dicts so existing unit tests stay intact.
  • Use extra="ignore" so unknown keys (e.g. 2.17 ↔ dev) are dropped rather than raising. S3 inner keys stay Dict[str, Any] cause provider/track field names differ.

Context

Same pattern as Tempo: https://github.com/canonical/tempo-operators/blob/main/coordinator/src/tempo_config.py

Pydantic is already in the coordinator environment via charm libs / coordinated-workers; this change only uses it for the config we generate.

Testing Instructions

From coordinator/:

tox -e unit
tox -e lint
tox -e static

Or from the repo root: tox -e unit.

New cases in coordinator/tests/unit/test_mimir_config.py:

  • round-trip with no S3 / no TLS
  • unknown extra keys ignored
  • S3 + TLS still validates (storage_prefix replaces filesystem)
  • invalid types raise ValidationError

Upgrade Notes

charm config, relation, and storage have not been changed. Config YAML keys/values are aslo unchanged for current fields.

Unknown extra keys are ignored so a newer track adding a field this model does not know about should not fail validation. Older payloads still parse cause new model fields are optional or have defaults.

Type-check existing fields so invalid config fails at build time instead of sending broken data over relations.
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.

1 participant