Skip to content

Commit 55155cd

Browse files
authored
[DPE-8439] Remove reinitialisation and hash config (#1101)
* Remove reinitialisation and hash config * Libs and fixes * Copy relations_user_databases_map from VM * Remove second restart * Bump libs * Remove dead code
1 parent 8ab3b48 commit 55155cd

File tree

9 files changed

+157
-954
lines changed

9 files changed

+157
-954
lines changed

lib/charms/loki_k8s/v1/loki_push_api.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ def __init__(self, ...):
544544

545545
# Increment this PATCH version before using `charmcraft publish-lib` or reset
546546
# to 0 if you are raising the major API version
547-
LIBPATCH = 19
547+
LIBPATCH = 21
548548

549549
PYDEPS = ["cosl"]
550550

@@ -1601,28 +1601,46 @@ def loki_endpoints(self) -> List[dict]:
16011601
"""Fetch Loki Push API endpoints sent from LokiPushApiProvider through relation data.
16021602
16031603
Returns:
1604-
A list of dictionaries with Loki Push API endpoints, for instance:
1604+
A list of unique dictionaries with Loki Push API endpoints, for instance:
16051605
[
16061606
{"url": "http://loki1:3100/loki/api/v1/push"},
16071607
{"url": "http://loki2:3100/loki/api/v1/push"},
16081608
]
16091609
"""
1610-
endpoints = [] # type: list
1610+
endpoints = []
1611+
seen_urls = set()
16111612

16121613
for relation in self._charm.model.relations[self._relation_name]:
16131614
for unit in relation.units:
16141615
if unit.app == self._charm.app:
1615-
# This is a peer unit
16161616
continue
16171617

1618-
endpoint = relation.data[unit].get("endpoint")
1619-
if endpoint:
1620-
deserialized_endpoint = json.loads(endpoint)
1621-
endpoints.append(deserialized_endpoint)
1618+
if not (endpoint := relation.data[unit].get("endpoint")):
1619+
continue
1620+
1621+
deserialized_endpoint = json.loads(endpoint)
1622+
url = deserialized_endpoint.get("url")
1623+
1624+
# Deduplicate by URL.
1625+
# With loki-k8s we have ingress-per-unit, so in that case
1626+
# we do want to collect the URLs of all the units.
1627+
# With loki-coordinator-k8s, even when the coordinator
1628+
# is scaled, we want to advertise only one URL.
1629+
# Without deduplication, we'd end up with the same
1630+
# tls config section in the promtail config file, in which
1631+
# case promtail immediately exits with the following error:
1632+
# [promtail] level=error ts=<timestamp> msg="error creating promtail" error="failed to create client manager: duplicate client configs are not allowed, found duplicate for name: "
1633+
1634+
if not url or url in seen_urls:
1635+
continue
1636+
1637+
seen_urls.add(url)
1638+
endpoints.append(deserialized_endpoint)
16221639

16231640
return endpoints
16241641

16251642

1643+
16261644
class LokiPushApiConsumer(ConsumerBase):
16271645
"""Loki Consumer class."""
16281646

0 commit comments

Comments
 (0)