Skip to content

Commit

Permalink
Adiciona configuração inicial de Loki e Grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
ogecece committed May 7, 2024
1 parent b35f269 commit 2086946
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
42 changes: 40 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ POD_NAME ?= querido-diario
DATABASE_CONTAINER_NAME ?= $(POD_NAME)-db
OPENSEARCH_CONTAINER_NAME ?= $(POD_NAME)-opensearch
OTEL_COLLECTOR_CONTAINER_NAME ?= $(POD_NAME)-otel-collector
LOKI_CONTAINER_NAME ?= $(POD_NAME)-loki
GRAFANA_CONTAINER_NAME ?= $(POD_NAME)-grafana
# Database info user to run the tests
POSTGRES_USER ?= companies
POSTGRES_PASSWORD ?= companies
Expand All @@ -25,6 +27,8 @@ DATABASE_RESTORE_FILE ?= contrib/data/queridodiariodb.tar
RUN_INTEGRATION_TESTS ?= 0

OTEL_COLLECTOR_PORT := 4317
LOKI_PORT := 3100
GRAFANA_PORT := 3000
API_PORT := 8080

run-command=(podman run --rm -ti --volume $(PWD):/mnt/code:rw \
Expand All @@ -38,7 +42,7 @@ wait-for=(podman run --rm -ti --volume $(PWD):/mnt/code:rw \
--pod $(POD_NAME) \
--env PYTHONPATH=/mnt/code \
--user=$(UID):$(UID) \
$(IMAGE_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG) wait-for-it --timeout=30 $1)
$(IMAGE_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG) wait-for-it --timeout=60 $1)

.PHONY: black
black:
Expand Down Expand Up @@ -79,6 +83,8 @@ create-pod: setup-environment destroy-pod
--publish $(OPENSEARCH_PORT1):$(OPENSEARCH_PORT1) \
--publish $(OPENSEARCH_PORT2):$(OPENSEARCH_PORT2) \
--publish $(OTEL_COLLECTOR_PORT):$(OTEL_COLLECTOR_PORT) \
--publish $(LOKI_PORT):$(LOKI_PORT) \
--publish $(GRAFANA_PORT):$(GRAFANA_PORT) \
--name $(POD_NAME)

.PHONY: setup-environment
Expand Down Expand Up @@ -127,7 +133,7 @@ shell:
bash

.PHONY: run
run: create-pod opensearch database otel-collector load-data re-run
run: create-pod opensearch database otel-collector loki grafana load-data re-run

.PHONY:load-data
load-data:
Expand Down Expand Up @@ -205,3 +211,35 @@ wait-otel-collector:
otel-auto-instrumentation-list:
@echo "These packages were detected and can be auto-instrumented (maybe add/update them in requirements.txt):"
@$(call run-command, opentelemetry-bootstrap -a requirements)

.PHONY: loki
loki: stop-loki start-loki wait-loki

start-loki:
podman run -d --rm -ti \
--name $(LOKI_CONTAINER_NAME) \
--pod $(POD_NAME) \
--volume $(PWD)/config/loki-config.yaml:/mnt/config/loki-config.yaml \
docker.io/grafana/loki:3.0.0 "-config.file=/mnt/config/loki-config.yaml"

stop-loki:
podman rm --force --ignore $(LOKI_CONTAINER_NAME)

wait-loki:
$(call wait-for, localhost:3100)

.PHONY: grafana
grafana: stop-grafana start-grafana wait-grafana

start-grafana:
podman run -d --rm -ti \
--name $(GRAFANA_CONTAINER_NAME) \
--pod $(POD_NAME) \
--volume $(PWD)/config/grafana/datasource.yaml:/etc/grafana/provisioning/datasources/datasource.yml \
docker.io/grafana/grafana:10.4.2

stop-grafana:
podman rm --force --ignore $(GRAFANA_CONTAINER_NAME)

wait-grafana:
$(call wait-for, localhost:3000)
17 changes: 17 additions & 0 deletions config/grafana/datasource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: 1

datasources:
- uid: loki
orgId: 1
name: Loki
type: loki
typeName: Loki
access: proxy
url: http://localhost:3100
password: ''
user: ''
database: ''
basicAuth: false
isDefault: false
readOnly: false
editable: true
49 changes: 49 additions & 0 deletions config/loki-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
auth_enabled: false

server:
http_listen_port: 3100
grpc_listen_port: 9096

limits_config:
allow_structured_metadata: true
otlp_config:
resource_attributes:
attributes_config:
- action: index_label
attributes:
- service.group

common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory

query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100

schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h

ruler:
alertmanager_url: http://localhost:9093

analytics:
reporting_enabled: false
4 changes: 3 additions & 1 deletion config/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ receivers:
exporters:
debug:
verbosity: detailed
otlphttp:
endpoint: http://localhost:3100/otlp
processors:
batch:
service:
pipelines:
logs:
receivers: [otlp]
exporters: [debug]
exporters: [debug, otlphttp]
processors: [batch]
traces:
receivers: [otlp]
Expand Down

0 comments on commit 2086946

Please sign in to comment.