Skip to content

Commit

Permalink
use redis_exporter provided by ROCK instead of 3rd party image, add r…
Browse files Browse the repository at this point in the history
…edis_exporter as service in pebble layer, run redis in appendonly mode
  • Loading branch information
reneradoi committed Jun 11, 2024
1 parent 426d05e commit 7c92738
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
8 changes: 1 addition & 7 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,12 @@ containers:
location: /var/lib/redis
sentinel:
resource: redis-image
exporter:
resource: exporter

resources:
redis-image:
type: oci-image
description: ubuntu lts docker image for redis
upstream: ghcr.io/canonical/charmed-redis:7.0-22.04_edge
exporter:
type: oci-image
description: redis exporter for prometheus metrics
upstream: docker.io/oliver006/redis_exporter:v1.59.0
upstream: ghcr.io/canonical/charmed-redis:7.2.5-22.04-edge
cert-file:
type: file
filename: redis.crt
Expand Down
25 changes: 18 additions & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
SENTINEL_PASSWORD_KEY,
SOCKET_TIMEOUT,
WAITING_MESSAGE,
WORKING_DIR,
)
from redis_exporter import Exporter
from sentinel import Sentinel

logger = logging.getLogger(__name__)
Expand All @@ -60,7 +60,6 @@ def __init__(self, *args):
self._namespace = self.model.name
self.redis_provides = RedisProvides(self, port=REDIS_PORT)
self.sentinel = Sentinel(self)
self.exporter = Exporter(self)
self.metrics_endpoint = MetricsEndpointProvider(
self,
jobs=[
Expand Down Expand Up @@ -209,7 +208,6 @@ def _config_changed(self, event: EventBase) -> None:

self._update_layer()
self.sentinel._update_sentinel_layer()
self.exporter._update_exporter_layer()

# update_layer will set a Waiting status if Pebble is not ready
if not isinstance(self.unit.status, ActiveStatus):
Expand Down Expand Up @@ -351,8 +349,8 @@ def _update_layer(self) -> None:
if current_layer.services != new_layer.services:
container.add_layer("redis", new_layer, combine=True)
logger.info("Added updated layer 'redis' to Pebble plan")
container.restart("redis")
logger.info("Restarted redis service")
container.restart("redis", "redis_exporter")
logger.info("Restarted redis and redis_exporter services")

self.unit.status = ActiveStatus()

Expand All @@ -370,9 +368,20 @@ def _redis_layer(self) -> Layer:
"override": "replace",
"summary": "Redis service",
"command": f"redis-server {self._redis_extra_flags()}",
"user": "redis",
"group": "redis",
"user": REDIS_USER,
"group": REDIS_USER,
"startup": "enabled",
},
"redis_exporter": {
"override": "replace",
"summary": "Redis metric exporter",
"command": "bin/redis_exporter",
"user": REDIS_USER,
"group": REDIS_USER,
"startup": "enabled",
"environment": {
"REDIS_PASSWORD": self._get_password(),
},
}
},
}
Expand All @@ -390,6 +399,8 @@ def _redis_extra_flags(self) -> str:
f"--masterauth {self._get_password()}",
f"--replica-announce-ip {self.unit_pod_hostname}",
f"--logfile {LOG_FILE}",
"--appendonly yes",
f"--dir {WORKING_DIR}",
]

if self._peers.data[self.app].get("enable-password", "true") == "false":
Expand Down
1 change: 1 addition & 0 deletions src/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
LOG_DIR = "/var/log/redis"
LOG_FILE = f"{LOG_DIR}/redis-server.log"
CONFIG_DIR = "/etc/redis-server"
WORKING_DIR = "/var/lib/redis/"
SENTINEL_CONFIG_PATH = f"{CONFIG_DIR}/sentinel.conf"

0 comments on commit 7c92738

Please sign in to comment.