canonical / loki-coordinator-k8s-operator

https://charmhub.io/loki-coordinator-k8s
Apache License 2.0
0 stars 0 forks source link

Wrong loki api endpoint rendered in logging relations #14

Open lucabello opened 2 weeks ago

lucabello commented 2 weeks ago

Bug Description

Regardless of Traefik/TLS, the LokiPushApiProvider always renders http with socket.getfqdn() (see here) instead of https and the external_url.

This makes it impossible to send logs over an ingressed Loki / over TLS.

To Reproduce

# deploy the basic Loki HA setup
juju deploy traefik-k8s traefik --channel=latest/edge --trust

juju relate loki:logging traefik
juju relate loki:ingress traefik

jhack show-relation loki:logging traefik
lucabello commented 2 weeks ago

Analyzing the diff between the charm code for the monolithic charm and the coordinator, I spotted a difference. Specifically, the monolithic charm had this section, which the coordinator does not have:

    def __init__(self, *args):
        ...
        self.framework.observe(self.on.logging_relation_changed, self._on_logging_relation_changed)

    def _on_logging_relation_changed(self, event):
        # If there is a change in logging relation, let's update Loki endpoint
        # We are listening to relation_change to handle the Loki scale down to 0 and scale up again
        # when it is related with ingress. If not, endpoints will end up outdated in consumer side.
        self.loki_provider.update_endpoint(url=self._external_url, relation=event.relation)

Adding this event listener and function to the coordinator fixes this issue!

lucabello commented 2 weeks ago

Fixed by this commit in the PR linked below.