Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring Grafana datasource over the relation #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions src/interface_http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import logging
sys.path.append('lib')

from ops.framework import (
Expand All @@ -8,10 +9,7 @@
ObjectEvents,
)

from adapters import (
framework,
k8s,
)
from adapters import framework

# Ideally, this interface and its tests should be located in its own
# repository. However, to keep the initial development process simple,
Expand Down Expand Up @@ -98,17 +96,13 @@ def relation_name(self):
return self._relation_name

def on_relation_changed(self, event):
# TODO: Add some logic here to pick up the right relation in case
# the client charm is related to more than one unit. E.g. when the
# server is in HA mode.
relation = self.adapter.get_relations(self.relation_name)[0]
juju_app = relation.app.name
juju_model = self.adapter.get_model_name()

# Fetch the k8s Service resource fronting the server pods
service_spec = k8s.get_service_spec(juju_model=juju_model,
juju_app=juju_app)

server_details = ServerDetails(host=service_spec.host,
port=service_spec.port)
remote_relation_data = event.relation.data[event.unit]
logging.debug(
"Received from Prom: %s " % list(remote_relation_data.items())
)

server_details = ServerDetails(
host=remote_relation_data['ingress-address'],
port=remote_relation_data['prometheus-port']
)
self.on.server_available.emit(server_details)