Skip to content

refactor: Improve testing and docs#375

Merged
MichaelThamm merged 2 commits intocanonical:mainfrom
MichaelThamm:fix/improve-testing
Mar 24, 2026
Merged

refactor: Improve testing and docs#375
MichaelThamm merged 2 commits intocanonical:mainfrom
MichaelThamm:fix/improve-testing

Conversation

@MichaelThamm
Copy link
Contributor

@MichaelThamm MichaelThamm commented Mar 20, 2026

Context

Why is this needed?

This PR simplifies the OTLP testing by removing the otlp_dual_ctx charm fixture for testing the requirer and provider charms in isolation. This is the intended way to test libraries with Scenario since we can provide remote and local databags to provide sufficient coverage. The previous testing was leaking otelcol implementation detail into the library.

Drive-by fixes

  • Make the _OtlpAppData models private since they are not public and to indicate that they are not intended to be.
  • We were missing some coverage for single and official rule file formats
  • Since we removed the leaked charm implementation from the lib and the otlp_dual_ctx charm fixture, tests for metadata and provider rules were added.
  • Fix the metadata in tests and in documentation to use juju_charm instead of charm.
  • Replace old-style charming practices (when we wrote observe-pattern libs) with reconciler-style charming patterns in the README, __init__, and conftest.

For example, before:

class MyOtlpServer(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.otlp_provider = OtlpProvider(self)
        self.framework.observe(self.on.ingress_ready, self._on_ingress_ready)

    def _on_ingress_ready(self, event):
        self.otlp_provider.add_endpoint(
            protocol="grpc",
            endpoint="https://my-app.ingress:4317",
            telemetries=["logs", "metrics"],
        )
        self.otlp_provider.add_endpoint(
            protocol="http",
            endpoint="https://my-app.ingress:4318",
            telemetries=["traces"],
        )
        self.otlp_provider.publish()

now:

class MyOtlpServer(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.framework.observe(self.on.ingress_ready, self._on_ingress_ready)

    def _on_ingress_ready(self, event):
        OtlpProvider(self).add_endpoint(
            protocol="grpc",
            endpoint="https://my-app.ingress:4317",
            telemetries=["logs", "metrics"],
        ).add_endpoint(
            protocol="http",
            endpoint="https://my-app.ingress:4318",
            telemetries=["traces"],
        ).publish()

User-facing changes

This PR does not actually functionally change the lib and is simply cosmetic. However, the documentation was updated which is user-facing. I will release as part of:

@MichaelThamm MichaelThamm requested a review from a team as a code owner March 20, 2026 13:42
@MichaelThamm MichaelThamm changed the title Fix/improve testing chore: Update tests and docs to reconciler-pattern lib usage Mar 20, 2026
@MichaelThamm MichaelThamm changed the title chore: Update tests and docs to reconciler-pattern lib usage chore: Remove the dual context charm fixture Mar 20, 2026
@MichaelThamm MichaelThamm changed the title chore: Remove the dual context charm fixture fix: Improve testing and docs Mar 23, 2026
@MichaelThamm MichaelThamm changed the title fix: Improve testing and docs refactor: Improve testing and docs Mar 23, 2026
@MichaelThamm MichaelThamm requested a review from a team as a code owner March 23, 2026 18:12
@MichaelThamm MichaelThamm merged commit dcafcc2 into canonical:main Mar 24, 2026
26 checks passed
@MichaelThamm MichaelThamm deleted the fix/improve-testing branch March 24, 2026 17:58
@MichaelThamm MichaelThamm restored the fix/improve-testing branch March 24, 2026 17:59
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