@marcos_feitoza/loki 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +41 -0
- package/CHANGELOG.md +7 -0
- package/README.md +95 -0
- package/helm/Chart.yaml +6 -0
- package/helm/prod-values.yaml +29 -0
- package/helm/templates/configmap.yaml +59 -0
- package/helm/templates/deployment.yaml +67 -0
- package/helm/templates/pvc.yaml +15 -0
- package/helm/templates/service.yaml +15 -0
- package/helm/values.yaml +29 -0
- package/package.json +29 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
|
|
3
|
+
jobs:
|
|
4
|
+
release:
|
|
5
|
+
docker:
|
|
6
|
+
- image: circleci/node:latest
|
|
7
|
+
steps:
|
|
8
|
+
- checkout
|
|
9
|
+
|
|
10
|
+
- run:
|
|
11
|
+
name: Install dependencies
|
|
12
|
+
command: npm ci
|
|
13
|
+
|
|
14
|
+
- run:
|
|
15
|
+
name: Ensure full Git history
|
|
16
|
+
command: |
|
|
17
|
+
git fetch --prune --unshallow || true
|
|
18
|
+
git fetch --all --tags
|
|
19
|
+
|
|
20
|
+
- run:
|
|
21
|
+
name: Configure Git remote with GH_TOKEN
|
|
22
|
+
command: |
|
|
23
|
+
git config user.name "circleci-bot"
|
|
24
|
+
git config user.email "ci@users.noreply.github.com"
|
|
25
|
+
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/MarcosOps/loki.git"
|
|
26
|
+
|
|
27
|
+
- run:
|
|
28
|
+
name: Run semantic-release
|
|
29
|
+
command: npx semantic-release
|
|
30
|
+
|
|
31
|
+
workflows:
|
|
32
|
+
release:
|
|
33
|
+
jobs:
|
|
34
|
+
- release:
|
|
35
|
+
context:
|
|
36
|
+
- shared-ci-secrets
|
|
37
|
+
filters:
|
|
38
|
+
branches:
|
|
39
|
+
only:
|
|
40
|
+
- main
|
|
41
|
+
- /^AB#.*/
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Loki (Armazenamento e consulta de logs)
|
|
2
|
+
|
|
3
|
+
Este repositório entrega o Loki para armazenamento centralizado de logs Kubernetes.
|
|
4
|
+
|
|
5
|
+
## Papel na arquitetura
|
|
6
|
+
|
|
7
|
+
- Recebe logs do Vector.
|
|
8
|
+
- Indexa por labels e armazena conteúdo.
|
|
9
|
+
- Responde consultas LogQL para Grafana.
|
|
10
|
+
|
|
11
|
+
## Integração com Vector e Grafana
|
|
12
|
+
|
|
13
|
+
Fluxo:
|
|
14
|
+
|
|
15
|
+
- `Pods -> Vector -> Loki -> Grafana`
|
|
16
|
+
|
|
17
|
+
Onde:
|
|
18
|
+
|
|
19
|
+
- Vector envia JSON com labels (`namespace`, `app`, `pod`, `container`, `node`).
|
|
20
|
+
- Grafana usa datasource Loki (`uid: loki`) para dashboards e Explore.
|
|
21
|
+
|
|
22
|
+
## Configuração principal
|
|
23
|
+
|
|
24
|
+
Arquivo de referência:
|
|
25
|
+
|
|
26
|
+
- `helm/prod-values.yaml`
|
|
27
|
+
|
|
28
|
+
Pontos atuais:
|
|
29
|
+
|
|
30
|
+
- Imagem: `grafana/loki:3.6.5`
|
|
31
|
+
- Serviço: `ClusterIP:3100`
|
|
32
|
+
- Retention: `168h` (7 dias)
|
|
33
|
+
- Persistência: `disabled` (logs efêmeros em caso de restart)
|
|
34
|
+
|
|
35
|
+
## Verificação rápida
|
|
36
|
+
|
|
37
|
+
- Pod Loki:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
kubectl -n monitoring get pods -l app.kubernetes.io/name=loki -o wide
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- Logs Loki:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
kubectl -n monitoring logs -l app.kubernetes.io/name=loki --tail=200
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Teste de saúde via serviço:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
kubectl -n monitoring exec <grafana-pod> -- sh -c "wget -qO- http://loki.monitoring.svc.cluster.local:3100/ready"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- Query de teste no Grafana Explore:
|
|
56
|
+
|
|
57
|
+
```logql
|
|
58
|
+
{namespace="monitoring"}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Queries úteis (LogQL)
|
|
62
|
+
|
|
63
|
+
- Logs de um app:
|
|
64
|
+
|
|
65
|
+
```logql
|
|
66
|
+
{namespace="app", app="personal-finance-backend-market-data-crypto"}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- Busca por texto no payload:
|
|
70
|
+
|
|
71
|
+
```logql
|
|
72
|
+
{namespace="app", app=~".*crypto.*"} |= "Finished Investment Balance Calculation"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- Busca ampla por termo:
|
|
76
|
+
|
|
77
|
+
```logql
|
|
78
|
+
{namespace="app"} |~ "(?i)crypto"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Troubleshooting comum
|
|
82
|
+
|
|
83
|
+
- Explore funciona, dashboard não:
|
|
84
|
+
- Revisar variáveis e filtros do painel.
|
|
85
|
+
- Validar datasource do painel (`Loki`, `uid=loki`).
|
|
86
|
+
- Sem ingestão:
|
|
87
|
+
- Checar logs do Vector e endpoint Loki.
|
|
88
|
+
- Verificar readiness de Loki.
|
|
89
|
+
- Perda de histórico após restart:
|
|
90
|
+
- Esperado com `persistence.enabled: false`.
|
|
91
|
+
|
|
92
|
+
## Recomendações
|
|
93
|
+
|
|
94
|
+
- Para retenção real em homelab, habilitar `persistence`.
|
|
95
|
+
- Manter estratégia de labels estáveis para consultas eficientes.
|
package/helm/Chart.yaml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
image:
|
|
2
|
+
repository: grafana/loki
|
|
3
|
+
tag: "3.6.5"
|
|
4
|
+
pullPolicy: IfNotPresent
|
|
5
|
+
|
|
6
|
+
service:
|
|
7
|
+
type: ClusterIP
|
|
8
|
+
port: 3100
|
|
9
|
+
|
|
10
|
+
persistence:
|
|
11
|
+
enabled: false
|
|
12
|
+
size: 10Gi
|
|
13
|
+
storageClassName: local-storage
|
|
14
|
+
|
|
15
|
+
resources:
|
|
16
|
+
requests:
|
|
17
|
+
cpu: 100m
|
|
18
|
+
memory: 256Mi
|
|
19
|
+
limits:
|
|
20
|
+
cpu: 500m
|
|
21
|
+
memory: 1Gi
|
|
22
|
+
|
|
23
|
+
retention:
|
|
24
|
+
enabled: true
|
|
25
|
+
period: 168h
|
|
26
|
+
|
|
27
|
+
nodeSelector: {}
|
|
28
|
+
tolerations: []
|
|
29
|
+
affinity: {}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
apiVersion: v1
|
|
2
|
+
kind: ConfigMap
|
|
3
|
+
metadata:
|
|
4
|
+
name: loki-config
|
|
5
|
+
data:
|
|
6
|
+
loki.yaml: |
|
|
7
|
+
auth_enabled: false
|
|
8
|
+
|
|
9
|
+
server:
|
|
10
|
+
http_listen_port: 3100
|
|
11
|
+
|
|
12
|
+
common:
|
|
13
|
+
instance_addr: 127.0.0.1
|
|
14
|
+
path_prefix: /loki
|
|
15
|
+
replication_factor: 1
|
|
16
|
+
ring:
|
|
17
|
+
kvstore:
|
|
18
|
+
store: inmemory
|
|
19
|
+
storage:
|
|
20
|
+
filesystem:
|
|
21
|
+
chunks_directory: /loki/chunks
|
|
22
|
+
rules_directory: /loki/rules
|
|
23
|
+
|
|
24
|
+
schema_config:
|
|
25
|
+
configs:
|
|
26
|
+
- from: "2024-01-01"
|
|
27
|
+
store: tsdb
|
|
28
|
+
object_store: filesystem
|
|
29
|
+
schema: v13
|
|
30
|
+
index:
|
|
31
|
+
prefix: index_
|
|
32
|
+
period: 24h
|
|
33
|
+
|
|
34
|
+
limits_config:
|
|
35
|
+
allow_structured_metadata: true
|
|
36
|
+
ingestion_rate_mb: 8
|
|
37
|
+
ingestion_burst_size_mb: 16
|
|
38
|
+
|
|
39
|
+
compactor:
|
|
40
|
+
working_directory: /loki/compactor
|
|
41
|
+
compaction_interval: 10m
|
|
42
|
+
delete_request_store: filesystem
|
|
43
|
+
|
|
44
|
+
ruler:
|
|
45
|
+
storage:
|
|
46
|
+
type: local
|
|
47
|
+
local:
|
|
48
|
+
directory: /loki/rules
|
|
49
|
+
ring:
|
|
50
|
+
kvstore:
|
|
51
|
+
store: inmemory
|
|
52
|
+
rule_path: /tmp/loki/rules
|
|
53
|
+
enable_api: true
|
|
54
|
+
|
|
55
|
+
{{- if .Values.retention.enabled }}
|
|
56
|
+
table_manager:
|
|
57
|
+
retention_deletes_enabled: true
|
|
58
|
+
retention_period: {{ .Values.retention.period | quote }}
|
|
59
|
+
{{- end }}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
apiVersion: apps/v1
|
|
2
|
+
kind: Deployment
|
|
3
|
+
metadata:
|
|
4
|
+
name: loki
|
|
5
|
+
labels:
|
|
6
|
+
app.kubernetes.io/name: loki
|
|
7
|
+
spec:
|
|
8
|
+
replicas: 1
|
|
9
|
+
selector:
|
|
10
|
+
matchLabels:
|
|
11
|
+
app.kubernetes.io/name: loki
|
|
12
|
+
template:
|
|
13
|
+
metadata:
|
|
14
|
+
labels:
|
|
15
|
+
app.kubernetes.io/name: loki
|
|
16
|
+
spec:
|
|
17
|
+
containers:
|
|
18
|
+
- name: loki
|
|
19
|
+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
|
20
|
+
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
|
21
|
+
args:
|
|
22
|
+
- -config.file=/etc/loki/loki.yaml
|
|
23
|
+
ports:
|
|
24
|
+
- containerPort: 3100
|
|
25
|
+
name: http
|
|
26
|
+
livenessProbe:
|
|
27
|
+
httpGet:
|
|
28
|
+
path: /ready
|
|
29
|
+
port: http
|
|
30
|
+
initialDelaySeconds: 30
|
|
31
|
+
timeoutSeconds: 5
|
|
32
|
+
readinessProbe:
|
|
33
|
+
httpGet:
|
|
34
|
+
path: /ready
|
|
35
|
+
port: http
|
|
36
|
+
initialDelaySeconds: 10
|
|
37
|
+
timeoutSeconds: 5
|
|
38
|
+
resources:
|
|
39
|
+
{{- toYaml .Values.resources | nindent 12 }}
|
|
40
|
+
volumeMounts:
|
|
41
|
+
- name: config
|
|
42
|
+
mountPath: /etc/loki
|
|
43
|
+
- name: data
|
|
44
|
+
mountPath: /loki
|
|
45
|
+
volumes:
|
|
46
|
+
- name: config
|
|
47
|
+
configMap:
|
|
48
|
+
name: loki-config
|
|
49
|
+
- name: data
|
|
50
|
+
{{- if .Values.persistence.enabled }}
|
|
51
|
+
persistentVolumeClaim:
|
|
52
|
+
claimName: loki
|
|
53
|
+
{{- else }}
|
|
54
|
+
emptyDir: {}
|
|
55
|
+
{{- end }}
|
|
56
|
+
{{- with .Values.nodeSelector }}
|
|
57
|
+
nodeSelector:
|
|
58
|
+
{{- toYaml . | nindent 8 }}
|
|
59
|
+
{{- end }}
|
|
60
|
+
{{- with .Values.affinity }}
|
|
61
|
+
affinity:
|
|
62
|
+
{{- toYaml . | nindent 8 }}
|
|
63
|
+
{{- end }}
|
|
64
|
+
{{- with .Values.tolerations }}
|
|
65
|
+
tolerations:
|
|
66
|
+
{{- toYaml . | nindent 8 }}
|
|
67
|
+
{{- end }}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{{- if .Values.persistence.enabled }}
|
|
2
|
+
apiVersion: v1
|
|
3
|
+
kind: PersistentVolumeClaim
|
|
4
|
+
metadata:
|
|
5
|
+
name: loki
|
|
6
|
+
spec:
|
|
7
|
+
accessModes:
|
|
8
|
+
- ReadWriteOnce
|
|
9
|
+
resources:
|
|
10
|
+
requests:
|
|
11
|
+
storage: {{ .Values.persistence.size }}
|
|
12
|
+
{{- if .Values.persistence.storageClassName }}
|
|
13
|
+
storageClassName: {{ .Values.persistence.storageClassName }}
|
|
14
|
+
{{- end }}
|
|
15
|
+
{{- end }}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
apiVersion: v1
|
|
2
|
+
kind: Service
|
|
3
|
+
metadata:
|
|
4
|
+
name: loki
|
|
5
|
+
labels:
|
|
6
|
+
app.kubernetes.io/name: loki
|
|
7
|
+
spec:
|
|
8
|
+
type: {{ .Values.service.type }}
|
|
9
|
+
selector:
|
|
10
|
+
app.kubernetes.io/name: loki
|
|
11
|
+
ports:
|
|
12
|
+
- name: http
|
|
13
|
+
port: {{ .Values.service.port }}
|
|
14
|
+
targetPort: http
|
|
15
|
+
protocol: TCP
|
package/helm/values.yaml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
image:
|
|
2
|
+
repository: grafana/loki
|
|
3
|
+
tag: "3.6.5"
|
|
4
|
+
pullPolicy: IfNotPresent
|
|
5
|
+
|
|
6
|
+
service:
|
|
7
|
+
type: ClusterIP
|
|
8
|
+
port: 3100
|
|
9
|
+
|
|
10
|
+
persistence:
|
|
11
|
+
enabled: false
|
|
12
|
+
size: 10Gi
|
|
13
|
+
storageClassName: local-storage
|
|
14
|
+
|
|
15
|
+
resources:
|
|
16
|
+
requests:
|
|
17
|
+
cpu: 100m
|
|
18
|
+
memory: 256Mi
|
|
19
|
+
limits:
|
|
20
|
+
cpu: 500m
|
|
21
|
+
memory: 1Gi
|
|
22
|
+
|
|
23
|
+
retention:
|
|
24
|
+
enabled: true
|
|
25
|
+
period: 168h
|
|
26
|
+
|
|
27
|
+
nodeSelector: {}
|
|
28
|
+
tolerations: []
|
|
29
|
+
affinity: {}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@marcos_feitoza/loki",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"release": "semantic-release"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"semantic-release": "^18.0.0",
|
|
12
|
+
"@semantic-release/changelog": "^6.0.0",
|
|
13
|
+
"@semantic-release/git": "^10.0.0",
|
|
14
|
+
"@semantic-release/github": "^8.0.0"
|
|
15
|
+
},
|
|
16
|
+
"release": {
|
|
17
|
+
"branches": [
|
|
18
|
+
"main"
|
|
19
|
+
],
|
|
20
|
+
"plugins": [
|
|
21
|
+
"@semantic-release/commit-analyzer",
|
|
22
|
+
"@semantic-release/release-notes-generator",
|
|
23
|
+
"@semantic-release/changelog",
|
|
24
|
+
"@semantic-release/npm",
|
|
25
|
+
"@semantic-release/github",
|
|
26
|
+
"@semantic-release/git"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|