canonical / tempo-k8s-operator

https://charmhub.io/tempo-k8s
Apache License 2.0
5 stars 3 forks source link

get_endpoint is trigger-happy #85

Closed PietroPasotti closed 6 months ago

PietroPasotti commented 6 months ago

Bug Description

When you use charm-tracing, you typically do:

class MyCharm(...):
    def __init__(...):
        self.tracing = TracingRequirer(endpoints=['otlp_http'])
    def otlp_http_endpoint(self):
        return self.tracing.get_endpoint('otlp_http')

self.tracing.get_endpoint raises an exception if the endpoint hasn't been requested (yet).

Since the requested endpoints are app-level, TracingRequirer only requests them if the owner is the leader and silently does nothing if otherwise. When you're leader, there is no problem because on __init__, the requirer lib will request the endpoint and so by the time otlp_http_endpoint is accessed, endpoints have certainly been requested (even if there is no response yet).

When you're not leader, there are two issues, one verified and reproducible, and one potential:

To Reproduce

n/a

Environment

n/a

Relevant log output

n/a

Additional context

No response