Skip to content

feat(otlp): Update otlp to use generic rules class#437

Open
swetha1654 wants to merge 3 commits into
canonical:mainfrom
swetha1654:feat/update-to-generic-rules
Open

feat(otlp): Update otlp to use generic rules class#437
swetha1654 wants to merge 3 commits into
canonical:mainfrom
swetha1654:feat/update-to-generic-rules

Conversation

@swetha1654

@swetha1654 swetha1654 commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Tandem PR for the cos-lib changes.

Downstream tandem PR:

  1. otel-collector: test latest otlp interface

This pull request updates the OTLP interface to use the new GenericRules API from a feature branch of the cos-lib library, and refactors rule handling to align with recent upstream changes.

Rule handling refactor:

  • Refactored RuleStore to use GenericRules with explicit Loki and Prometheus backends, replacing the previous Rules class and associated APIs. [1] [2]
  • Updated rule validation and injection logic to use the new validate method since otlp is the only user of the inject_and_validate method and we can be sure that rules that come to the OtlpProvider will always have topology injected. [1]
  • Updated backend-specific label injection, including using CosTool for PromQL label injection. [1]

Testing updates:

  • Updated unit tests in test_rules.py to match the new rule handling logic, since we now don't do topology injection on the provider side anymore.
  • Adjusted imports to ignore private import usage warnings for compatibility with the new API.

@swetha1654 swetha1654 requested a review from a team as a code owner April 16, 2026 06:01
@swetha1654 swetha1654 changed the title Update otlp to use generic rules class feat(otlp): Update otlp to use generic rules class Apr 16, 2026
Comment thread interfaces/otlp/src/charmlibs/interfaces/otlp/_otlp.py Outdated
rule_copy['expr'] = self._rules.promql.tool.inject_label_matchers(
rule_copy['expr'] = CosTool(
default_query_type='promql'
).inject_label_matchers(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

self._rules.promql is of type GenericRules now and doesn't expose a tool attribute anymore so we can either use self._rules.promql.backend.tool.inject_label_matchers or we can use CosTool directly. I decided to use CosTool to keep it simple.

promql_result = rules.promql.inject_and_validate_rules(
requirer.rules.promql, requirer.metadata
promql_result = rules.promql.validate(
cast('Mapping[str, list[OfficialRuleFileItem]]', requirer.rules.promql)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The new GenericRules class does not expose inject_and_validate but only validate. We can be sure that the rules obtained from OtlpRequirer databag will always have juju topology injected. This is because the OtlpRequirer class uses the add API from the upstream cosl before it dumps into the databag and this method takes care of adding the juju topology.

# AND the expressions are labeled
assert f'juju_model="{MODEL_NAME}"' in rule['expr']
assert f'juju_model_uuid="{MODEL_UUID}"' in rule['expr']
assert f'juju_application="{app}"' in rule['expr']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the provier does not do topology injection anymore so we can remove this part of the test

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