Skip to content

feat: Replace the requirer's rule interface with a rules object#376

Merged
MichaelThamm merged 11 commits intocanonical:mainfrom
MichaelThamm:feat/rules-interface
Mar 25, 2026
Merged

feat: Replace the requirer's rule interface with a rules object#376
MichaelThamm merged 11 commits intocanonical:mainfrom
MichaelThamm:feat/rules-interface

Conversation

@MichaelThamm
Copy link
Copy Markdown
Contributor

@MichaelThamm MichaelThamm commented Mar 20, 2026

Context

Blocked by these PRs:

Blocking this PR:

Why is this needed?

This PR allows users of the lib to build a rules object (built around the cosl.rules.Rules class) and pass that to the OtlpRequirer for publishing to the databag. The library adds its own rules to this object e.g., generic alert rules prior to publishing to the relation databag. The RuleStore is the API used to build the rules object which has a similar API to the cosl.rules.Rules class which uses the add and add_path methods to store rules.

API

Old

class OtlpRequirerCharm(CharmBase):
    def __init__(self, framework: ops.Framework):
        super().__init__(framework)
        self.framework.observe(self.on.update_status, self._on_update_status)

    def _on_update_status(self, event: ops.EventBase) -> None:
        OtlpRequirer(
            self,
            protocols=['http', 'grpc'],
            telemetries=['metrics', 'logs'],
            loki_rules_path=self.charm_root.joinpath(*LOKI_RULES_DEST_PATH.split('/')),
            prometheus_rules_path=self.charm_root.joinpath(*METRICS_RULES_DEST_PATH.split('/')),
        ).publish()

New

class OtlpRequirerCharm(CharmBase):
    def __init__(self, framework: ops.Framework):
        super().__init__(framework)
        self.framework.observe(self.on.update_status, self._publish_rules)

    def _publish_rules(self, _: ops.EventBase) -> None:
        rules = (
            RuleStore(JujuTopology.from_charm(self))
            .add_logql(SINGLE_LOGQL_ALERT, group_name='test_logql_alert')
            .add_logql(SINGLE_LOGQL_RECORD, group_name='test_logql_record')
            .add_promql(SINGLE_PROMQL_ALERT, group_name='test_promql_alert')
            .add_promql(SINGLE_PROMQL_RECORD, group_name='test_promql_record')
            .add_logql(OFFICIAL_LOGQL_RULES)
            .add_promql(OFFICIAL_PROMQL_RULES)
        )
        OtlpRequirer(
            self, protocols=ALL_PROTOCOLS, telemetries=ALL_TELEMETRIES, rules=rules
        ).publish()

@MichaelThamm MichaelThamm force-pushed the feat/rules-interface branch from 3974030 to 0ab9393 Compare March 23, 2026 18:43
@MichaelThamm MichaelThamm marked this pull request as ready for review March 23, 2026 19:08
@MichaelThamm MichaelThamm requested a review from a team as a code owner March 23, 2026 19:08
Co-authored-by: Sina P <55766091+sinapah@users.noreply.github.com>
@MichaelThamm MichaelThamm changed the title feat: Replace the requirer's rule interface from path to object feat: Replace the requirer's rule interface with a rules object Mar 25, 2026
@MichaelThamm MichaelThamm merged commit b75e082 into canonical:main Mar 25, 2026
27 checks passed
@MichaelThamm MichaelThamm deleted the feat/rules-interface branch March 27, 2026 19:35
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