Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-46821: Refactor metrics configuration #311

Merged
merged 6 commits into from
Oct 18, 2024
Merged

DM-46821: Refactor metrics configuration #311

merged 6 commits into from
Oct 18, 2024

Conversation

rra
Copy link
Member

@rra rra commented Oct 17, 2024

Rework the metrics configuration so that MetricsConfiguration is a union type supporting either a disabled or a Kafka-based metrics configuration, which can be used as a drop-in type in an application BaseSettings class and will automatically select one or the other based on what configuration is available. Have those two configuration classes in turn create two different EventManager classes that provide the same interface, and two different underlying EventPublisher classes. Use this to implement the no-op metrics functionality rather than checking a boolean. This allows all of the Kafka configuration to be omitted if metrics are disabled.

Update the documentation accordingly, and fix a few minor problems with the documentation discovered as part of the Gafaelfawr integration.

Move the app_name field to the top level of the metrics configuration on the grounds that this will likely apply to any application metrics, including things that are not events. Rename metrics_events to just events, since the metrics part is clear in context.

Use the topic_prefix name uniformly instead of base_topic_prefix.

@rra rra requested a review from fajpunk October 17, 2024 21:12
@rra rra force-pushed the tickets/DM-46821 branch 5 times, most recently from 242c68f to a0fe58d Compare October 18, 2024 00:35
Rework the metrics configuration so that `MetricsConfiguration` is
a union type supporting either a disabled or a Kafka-based metrics
configuration, which can be used as a drop-in type in an application
`BaseSettings` class and will automatically select one or the other
based on what configuration is available. Have those two configuration
classes in turn create two different `EventManager` classes that
provide the same interface, and two different underlying `EventPublisher`
classes. Use this to implement the no-op metrics functionality rather
than checking a boolean. This allows all of the Kafka configuration
to be omitted if metrics are disabled.

Update the documentation accordingly, and fix a few minor problems
with the documentation discovered as part of the Gafaelfawr integration.

Move the `app_name` field to the top level of the metrics configuration
on the grounds that this will likely apply to any application metrics,
including things that are not events. Rename `metrics_events` to just
`events`, since the metrics part is clear in context.

Use the `topic_prefix` name uniformly instead of `base_topic_prefix`.
`application` looks a bit nicer in YAML configuration since it
doesn't require handling camel-case transformations.
We will get rid of this code as soon as there is a better solution
in dataclasses-avroschema.
Copy link
Member

@fajpunk fajpunk left a comment

Choose a reason for hiding this comment

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

This is great, thanks! A couple of minor questions

safir/src/safir/metrics/_config.py Show resolved Hide resolved
safir/src/safir/metrics/_config.py Show resolved Hide resolved
safir/src/safir/metrics/_config.py Show resolved Hide resolved
safir/src/safir/metrics/_event_manager.py Outdated Show resolved Hide resolved
safir/src/safir/metrics/_event_manager.py Outdated Show resolved Hide resolved
Be clearer about what the name passed to `build_validated_model`
in the `EventManager` class is used for.
@fajpunk fajpunk self-requested a review October 18, 2024 16:42
Refactor the `EventManager` classes to share more structural code
with subclasses. The duplicate detection and iniitalization detection
code has moved to the parent class, and subclasses now only provide
the code to create a publisher from an enriched model, and can
override initialize and aclose if needed.
The logic for event manager loggers is common to all of the
implementations, so move it into the parent class.
@rra rra merged commit 243b2ce into main Oct 18, 2024
6 checks passed
@rra rra deleted the tickets/DM-46821 branch October 18, 2024 20:41
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