Repository navigation
Support Python enum classes as metric states - #1234
Open
ajaykr0905 wants to merge 1 commit into
Open
ajaykr0905 wants to merge 1 commit into
ajaykr0905 wants to merge 1 commit into
Conversation
Accept enum classes as Enum metric states and export canonical member names. Preserve the class for labelled children and validate member selection, aliases and empty definitions. Refs prometheus#975 Assisted-by: OpenAI Codex Signed-off-by: Ajay Kumar <206070437+ajaykr0905@users.noreply.github.com>
This branch has not been deployed
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.
Summary
Allow a Python
enum.Enumclass to define an Enum metric's states, as requested in #975.Export member names as string labels, independent of their underlying values. Preserve the enum class when constructing labelled children. Accept member names and aliases; reject empty enum classes and members of a different enum class. Existing string sequences retain their behavior. The documentation specifies these choices and includes an example.
Fixes #975. @csmarchbanks
Evidence
ff9a2d3: enum classes expose member objects as labels,state()raisesAttributeError, and empty enum classes are accepted.tox -e flake8,isort,mypy: passed; mypy reports no issues in 42 files.git diff --check: passed.The initial macOS system Python 3.9.6 run failed six existing TLS tests because its SSL library lacks TLS 1.3. The complete run was repeated with isolated Python 3.9.24 and OpenSSL 3.5.4; no tests or TLS checks were changed.
AI assistance: OpenAI Codex assisted with implementation, tests, and validation.
Merge Danger
Door: two-way
Blast Radius: Enum
This adds a constructor input type and member-based state selection. Metric names and existing string-state behavior remain unchanged. Enum classes expose canonical member names, including when selected through an alias.