Skip to content

Commit

Permalink
remove unit # from metrics username
Browse files Browse the repository at this point in the history
All units in a Prometheus app will share the same credentials.
  • Loading branch information
barrettj12 committed Sep 12, 2023
1 parent 5e0bffa commit 971446c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _on_website_relation_joined(self, event):
})

def _on_metrics_endpoint_relation_created(self, event: RelationJoinedEvent):
username = metrics_username(event.relation, self.unit)
username = metrics_username(event.relation)
password = secrets.token_urlsafe(16)
add_metrics_user(username, password)

Expand All @@ -98,7 +98,7 @@ def _on_metrics_endpoint_relation_created(self, event: RelationJoinedEvent):

def _on_metrics_endpoint_relation_broken(self, event: RelationDepartedEvent):
# Remove metrics user
username = metrics_username(event.relation, self.unit)
username = metrics_username(event.relation)
remove_metrics_user(username)


Expand Down Expand Up @@ -126,14 +126,13 @@ def ca_cert() -> str:
'''
return _agent_conf('cacert')

def metrics_username(relation: Relation, unit: Unit) -> str:
def metrics_username(relation: Relation) -> str:
'''
metrics_username returns the username used to access the metrics endpoint,
for the given relation and unit. This username has the form
juju-metrics-u0-r1
for the given relation. This username has the form
juju-metrics-r1
'''
unit_number = unit.name.split('/')[1]
return f'juju-metrics-u{unit_number}-r{relation.id}'
return f'juju-metrics-r{relation.id}'

def _introspect(command: str):
'''
Expand Down

0 comments on commit 971446c

Please sign in to comment.