feat(loki): add docker composition for local learning

This commit is contained in:
Michele Cereda
2025-05-14 00:53:20 +02:00
parent f4ba8f2258
commit c1b1d13a1e
4 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
---
services:
loki-1: &loki
image: grafana/loki:3.5.0
command: >-
-config.file=/etc/loki/local-config.yaml
-target=all
-reporting.enabled=false
-auth.enabled=false
-common.storage.ring.instance-addr=localhost
-common.storage.ring.store=memberlist
-memberlist.join=dns+localhost:7946
-s3.region=eu-west-1
-s3.buckets=loki-chunks
loki-2:
<<: *loki
load-balancer:
image: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- loki-1
- loki-2
ports:
- 3100:3100

View File

@@ -0,0 +1,18 @@
events {
worker_connections 1024;
}
http {
upstream backend {
server loki-1:3100 max_fails=1 fail_timeout=1s;
server loki-2:3100 max_fails=1 fail_timeout=1s;
}
server {
listen 3100;
access_log /dev/null;
location / {
proxy_pass http://backend;
}
}
}

View File

@@ -26,6 +26,8 @@ Designed to be cost-effective and easy to operate.
1. [Microservices mode](#microservices-mode) 1. [Microservices mode](#microservices-mode)
1. [Object storage](#object-storage) 1. [Object storage](#object-storage)
1. [Analytics](#analytics) 1. [Analytics](#analytics)
1. [Troubleshooting](#troubleshooting)
1. [Too many storage configs provided in the common config](#too-many-storage-configs-provided-in-the-common-config)
1. [Further readings](#further-readings) 1. [Further readings](#further-readings)
1. [Sources](#sources) 1. [Sources](#sources)
@@ -71,6 +73,8 @@ Loki runs in multi-tenant mode by default. It:
- Ignores that header, and sets the tenant ID to `fake` when multi-tenant mode is disabled. - Ignores that header, and sets the tenant ID to `fake` when multi-tenant mode is disabled.
This **will** appear in the index and in stored chunks. This **will** appear in the index and in stored chunks.
Loki accepts out-of-order writes by default.
<details> <details>
<summary>Setup</summary> <summary>Setup</summary>
@@ -695,6 +699,93 @@ analytics:
reporting_enabled: false reporting_enabled: false
``` ```
## Troubleshooting
### Too many storage configs provided in the common config
Error message example:
> failed parsing config: too many storage configs provided in the common config, please only define one storage backend
<details>
<summary>Context</summary>
Loki is running locally from its Docker container image using the default configuration file and the following flags:
```yml
---
# docker-compose.yml
services:
loki:
image: grafana/loki:3.5.0
command: >-
-config.file=/etc/loki/local-config.yaml
-target=all
-reporting.enabled=false
-auth.enabled=false
-common.storage.ring.instance-addr=localhost
-common.storage.ring.store=memberlist
-memberlist.join=dns+localhost:7946
-common.storage.s3.region=eu-west-1
-common.storage.s3.buckets=loki-chunks
```
</details>
<details>
<summary>Root cause</summary>
It seems the command flags for S3 storage are not working as expected.
</details>
<details>
<summary>Solution</summary>
Configure those settings (or):
- In the configuration file:
```yml
storage_config:
aws:
bucketnames: loki-chunks
region: eu-west-1
```
- By removing the `common.storage` part in the command:
```yml
command: >-
-s3.region=eu-west-1
-s3.buckets=loki-chunks
```
The end result in `GET /config` is the same:
```yml
storage_config:
alibabacloud: …
aws:
dynamodb: …
s3: ""
s3forcepathstyle: false
bucketnames: loki-chunks
endpoint: ""
region: eu-west-1
access_key_id: ""
secret_access_key: ""
azure: …
```
</details>
## Further readings ## Further readings
- [Website] - [Website]

View File

@@ -52,3 +52,6 @@ docker volume create --driver 'convoy' --opt 'size=100m' 'test'
# The example uses a 2GB RAM disk # The example uses a 2GB RAM disk
hdiutil attach -nomount 'ram://4194304' | xargs diskutil erasevolume HFS+ 'ramdisk' \ hdiutil attach -nomount 'ram://4194304' | xargs diskutil erasevolume HFS+ 'ramdisk' \
&& docker run --rm --name 'alpine' -v "/Volumes/ramdisk/:/ramdisk" -it 'alpine' sh && docker run --rm --name 'alpine' -v "/Volumes/ramdisk/:/ramdisk" -it 'alpine' sh
# Remove containers
docker ps -aq | xargs docker container rm