Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Define node and module streams with specific labels #3

Merged
merged 7 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
49 changes: 5 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,13 @@ The module use the [Promtail official docker image](https://github.com/grafana/l

## Install

Instantiate the module, example:
```
add-module ghcr.io/nethserver/promtail:latest 1
```

The output of the command will return the instance name.
Output example:
```
{"module_id": "promtail1", "image_name": "promtail", "image_url": "ghcr.io/nethserver/promtail:latest"}
```

Wait for `add-module` to complete by looking inside `journalctl`.
An instance of Promtail is installed by default on every cluster node.
Upon service startup, the default Loki cluster instance is found and
Promtail is configured to send log to it.

As default, the Loki server used will be the default instance of the cluster.
To add another Promtail instance run

## Configure

Let's assume that the Promtail instance is named `promtail1`.

Then launch `configure-module`, by setting the following parameters:
- `loki_instance`, *string*: Module id of the Loki server.
- `loki_url`, *string*: Address of the remote Loki server.
- `auth`, *object*: Authentication credentials, only valid if `loki_url` is used:
- `token`, *string*: Bearer token to send to the server.
- `basic`, *object*: Basic auth username and password for authenticate to the server.
- `username`, *string*: Username.
- `Password`, *string*: Password.

All parameters must be set inside the `data` field as a JSON object.

Example:
```
redis-cli LPUSH module/promtail1/tasks '{"id":"'$(uuidgen)'","action":"configure-module","data": {"loki_instance":"loki1"}}'
```

```
redis-cli LPUSH module/promtail1/tasks '{"id":"'$(uuidgen)'","action":"configure-module","data": {"loki_url":"https://example.com/loki/api/v1/push"}}'
```

```
redis-cli LPUSH module/promtail1/tasks '{"id":"'$(uuidgen)'","action":"configure-module","data": {"loki_url": ""https://example.com/loki/api/v1/push", "auth": {"token": "XXXXXXXXXXXXXXXXXX"}}}'
```

```
redis-cli LPUSH module/promtail1/tasks '{"id":"'$(uuidgen)'","action":"configure-module","data": {"loki_url": "http://10.135.0.3:3100/loki/api/v1/push", "auth": {"basic": {"user": "user", "password": "password"}}}}'
```
add-module promtail

## Uninstall

Expand Down
2 changes: 1 addition & 1 deletion build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildah add "${container}" ui /ui
buildah config --entrypoint=/ "${container}"
buildah config --label="org.nethserver.rootfull=1" \
--label="org.nethserver.flags=core_module no_data_backup" \
--label="org.nethserver.images=docker.io/grafana/promtail:2.7.3" \
--label="org.nethserver.images=docker.io/grafana/promtail:2.8.2" \
"${container}"
buildah commit "${container}" "${repobase}/${reponame}"
images+=("${repobase}/${reponame}")
Expand Down
67 changes: 0 additions & 67 deletions imageroot/actions/configure-module/20unit_env

This file was deleted.

30 changes: 0 additions & 30 deletions imageroot/actions/configure-module/30start_service

This file was deleted.

82 changes: 0 additions & 82 deletions imageroot/actions/configure-module/validate-input.json

This file was deleted.

15 changes: 15 additions & 0 deletions imageroot/actions/create-module/05set_journal_path
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3

#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import agent
import os

if os.listdir('/run/log/journal'):
agent.set_env("PROMTAIL_JOURNAL", "/run/log/journal")
else:
agent.set_env("PROMTAIL_JOURNAL", "/var/log/journal")

6 changes: 0 additions & 6 deletions imageroot/actions/create-module/10initialize
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ set -e

exec 1>&2 # Send any output to stderr, to not alter the action response protocol

#Get the module id of the default Loki instance.

loki_id=$(REDIS_USER=default redis-exec GET cluster/default_instance/loki)

jq -cnM --arg loki_instance ${loki_id} '{"loki_instance":$loki_instance}' | ../actions/configure-module/20unit_env

install -m 644 "${AGENT_INSTALL_DIR}/promtail.service" "/etc/systemd/system/${MODULE_ID}.service"
systemctl daemon-reload
systemctl enable --now "${MODULE_ID}.service"
Loading
Loading