Skip to content

Commit

Permalink
adopt the one-relation model
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabello committed Nov 10, 2023
1 parent 24a2ca6 commit a1d6e88
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 42 deletions.
11 changes: 10 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
options: {}
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

options:
config_file:
type: string
default: ""
description: >
Mimir configuration file (yaml). Refer to
https://grafana.com/docs/mimir/latest/references/configuration-parameters/ for full details.
38 changes: 2 additions & 36 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,8 @@ resources:
description: OCI image for Grafana Agent

requires:
# On the same mimir_worker interface, the coordinator will accept one relation to a worker per
# each Mimir component.
# The relation(s) determine the role(s) the worker will assume.
# Each Mimir worker can take on multiple roles; however, there can be no role replication among
# workers related to the same coordinator, which is why we force `limit: 1`.
# Note: relation names exactly match Mimir roles.
compactor:
interface: mimir_worker
limit: 1
distributor:
interface: mimir_worker
limit: 1
ingester:
interface: mimir_worker
limit: 1
querier:
interface: mimir_worker
limit: 1
query-frontend:
interface: mimir_worker
limit: 1
store-gateway:
interface: mimir_worker
limit: 1
alertmanager:
interface: mimir_worker
limit: 1
ruler:
interface: mimir_worker
limit: 1
overrides-exporter:
interface: mimir_worker
limit: 1
query-scheduler:
interface: mimir_worker
limit: 1
mimir-cluster:
interface: mimir_cluster

s3:
interface: s3
Expand Down
13 changes: 8 additions & 5 deletions src/mimir_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import List, Optional

import pydantic
from interfaces.mimir_worker.v0.schema import MimirRole, RequirerSchema
from interfaces.mimir_cluster.v0.schema import MimirRole, RequirerSchema
from ops.model import ModelError, Relation, Unit

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -49,8 +49,9 @@
deployment to be considered robust according to the official recommendations/guidelines."""


def _endpoint_to_role(endpoint: str) -> MimirRole:
return MimirRole(endpoint.replace("-", "_"))
def _relation_to_role(relation: Relation) -> MimirRole:
# TODO: extract the role from the relation
return MimirRole(relation.role) # FIXME


class MimirCoordinator:
Expand All @@ -77,7 +78,7 @@ def is_recommended(self) -> bool:
return True

def roles(self) -> typing.Counter[MimirRole]:
"""Gather the roles from the mimir_worker relations and count them."""
"""Gather the roles from the mimir_cluster relations and count them."""
roles = Counter()

for relation in self.relations:
Expand All @@ -86,8 +87,10 @@ def roles(self) -> typing.Counter[MimirRole]:
continue

try:
role = _endpoint_to_role(relation.name)
role = _relation_to_role(relation) # TODO: get the role from relation data

except ValueError:
# TODO: not an actual role: should probably warn
logger.info(f"Not a mimir-*role* relation: {relation.name}")
continue

Expand Down

0 comments on commit a1d6e88

Please sign in to comment.