Add a minimal Pydantic model for Mimir coordinator config - #461
Open
Moetez-Fradi wants to merge 1 commit into
Open
Add a minimal Pydantic model for Mimir coordinator config#461Moetez-Fradi wants to merge 1 commit into
Moetez-Fradi wants to merge 1 commit into
Conversation
Type-check existing fields so invalid config fails at build time instead of sending broken data over relations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
coordinator/src/mimir_config.pycovering only the sectionsMimirConfig.config()already produces (alertmanager,ingester,limits, storage, TLS, etc.).MimirConfigModel.model_validate(...)beforeyaml.dump, so a bad shape fails on the coordinator at build time._build_*helpers returning dicts so existing unit tests stay intact.extra="ignore"so unknown keys (e.g. 2.17 ↔ dev) are dropped rather than raising. S3 inner keys stayDict[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/:Or from the repo root:
tox -e unit.New cases in
coordinator/tests/unit/test_mimir_config.py:storage_prefixreplacesfilesystem)ValidationErrorUpgrade 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.