feat(otlp): Update otlp to use generic rules class#437
Conversation
| rule_copy['expr'] = self._rules.promql.tool.inject_label_matchers( | ||
| rule_copy['expr'] = CosTool( | ||
| default_query_type='promql' | ||
| ).inject_label_matchers( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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'] |
There was a problem hiding this comment.
the provier does not do topology injection anymore so we can remove this part of the test
Tandem PR for the
cos-libchanges.Downstream tandem PR:
This pull request updates the OTLP interface to use the new
GenericRulesAPI from a feature branch of thecos-liblibrary, and refactors rule handling to align with recent upstream changes.Rule handling refactor:
RuleStoreto useGenericRuleswith explicit Loki and Prometheus backends, replacing the previousRulesclass and associated APIs. [1] [2]validatemethod sinceotlpis the only user of theinject_and_validatemethod and we can be sure that rules that come to theOtlpProviderwill always have topology injected. [1]CosToolfor PromQL label injection. [1]Testing updates:
test_rules.pyto match the new rule handling logic, since we now don't do topology injection on the provider side anymore.