Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Loki Log Streaming #1385

Merged
merged 24 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
59cb815
feat: docker compose config for promtail, grafana and loki services
amanji Oct 7, 2024
61ee803
feat: websocket package
amanji Oct 7, 2024
803955d
feat: API websocket support
amanji Oct 7, 2024
d43478b
update: vscode settings
amanji Oct 7, 2024
bfddbb0
feat: add jwonwebtoken package
amanji Oct 9, 2024
504056f
feat: API websocket token authentication
amanji Oct 9, 2024
bbe6591
feat: log store and component
amanji Oct 9, 2024
da4c622
chore: update test snapshots
amanji Oct 9, 2024
19b03fc
chore: suppress unrelated ts build error
amanji Oct 9, 2024
592789b
chore: parameterize URLs
amanji Oct 9, 2024
86fb430
Merge branch 'main' into bcgov/feature/loki-log-streaming
amanji Oct 11, 2024
48818a4
chore: suppress unrelated ts build error
amanji Oct 16, 2024
8ba3e44
Merge remote-tracking branch 'upstream/main' into bcgov/feature/loki-…
amanji Oct 16, 2024
2a94893
chore: audit and update dependencies
amanji Oct 16, 2024
f3729c7
chore: update env variables
amanji Oct 21, 2024
200cdd5
Merge remote-tracking branch 'upstream/main' into bcgov/feature/loki-…
amanji Oct 21, 2024
57edbcf
update: chart values
amanji Oct 22, 2024
155a340
update: chart values
amanji Oct 22, 2024
2b6b472
Merge branch 'bcgov/main' into bcgov/feature/loki-log-streaming
amanji Jan 9, 2025
2e3909f
fix: filter out log if logStreamUrl is not configured
amanji Jan 10, 2025
96ab1cc
fix: test snapshots
amanji Jan 10, 2025
ffbb082
Fix TS no-unsafe-optional-chaining errors
loneil Jan 10, 2025
4f31372
Optionalizing logging setup
loneil Jan 16, 2025
aa263fd
blank default
loneil Jan 16, 2025
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
2 changes: 2 additions & 0 deletions charts/traction/templates/ui/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data:
FRONTEND_SESSION_TIMEOUT_SECONDS: {{ .Values.ui.oidc.session.timeoutSeconds | quote }}
FRONTEND_SESSION_COUNTDOWN_SECONDS: {{ .Values.ui.oidc.session.countdownSeconds | quote }}
FRONTEND_TENANT_PROXY_URL: https://{{ include "tenant_proxy.host" . }}
FRONTEND_LOG_STREAM_URL: wss://{{ include "tenant-ui.fullname" . }}:{{ .Values.ui.service.httpPort }}/logStream
SERVER_OIDC_JWKS: {{ .Values.ui.oidc.jwksUri | quote }}
SERVER_OIDC_REALM: {{ .Values.ui.oidc.realm | quote }}
SERVER_OIDC_ROLE: {{ .Values.ui.oidc.roleName | quote }}
Expand All @@ -29,6 +30,7 @@ data:
SERVER_SMTP_SECURE: {{ .Values.ui.smtp.secure | quote }}
SERVER_SMTP_USER: {{ .Values.ui.smtp.user | quote }}
SERVER_TRACTION_URL: http://{{ include "tenant_proxy.fullname" . }}:{{ .Values.tenant_proxy.service.port }}
SERVER_LOKI_URL: http://{{ include "loki.fullname" . }}:{{ .Values.loki.service.port }}
esune marked this conversation as resolved.
Show resolved Hide resolved
UX_APP_INNKEEPER_TITLE: {{ .Values.ui.ux.appInnkeeperTitle | quote }}
UX_APP_TITLE: {{ .Values.ui.ux.appTitle | quote }}
UX_COPYRIGHT: {{ .Values.ui.ux.copyright | quote }}
Expand Down
12 changes: 12 additions & 0 deletions charts/traction/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,18 @@ tenant_proxy:
##
tolerations: []

## @section Loki configuration
##
loki:
## Loki service configuration
##
service:
## @param loki.service.type Kubernetes Service type
##
type: ClusterIP
## @param loki.service.port Port to expose for http services
port: 3100

esune marked this conversation as resolved.
Show resolved Hide resolved
## @section Tenant-UI Configuration
##
ui:
Expand Down
2 changes: 2 additions & 0 deletions scripts/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ TENANT_UI_PORT=5101
# which traction api are we using?
# naming convention follows what is used by the tenant ui config
SERVER_TRACTION_URL=http://localhost:8032
SERVER_LOKI_URL=ws://localhost:3100
FRONTEND_TENANT_PROXY_URL=http://localhost:8032
FRONTEND_LOG_STREAM_URL=ws://localhost:5101/logStream
IMAGE_BUILDTIME=
IMAGE_TAG=scripts_tenant-ui:latest
IMAGE_VERSION=latest
Expand Down
2 changes: 1 addition & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ docker build -f ./Dockerfile --tag traction:plugins-acapy ..
cd ../../services/aca-py
docker build -f ./Dockerfile.acapy --tag traction:traction-agent .
cd ../../scripts
docker compose up
docker compose -f docker-compose.logs.yml -f docker-compose.yml up
```

If there are still errors, try turning buildkit off. In the terminal where you are running your builds:
Expand Down
84 changes: 84 additions & 0 deletions scripts/configs/promtail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
server:
http_listen_address: 0.0.0.0
http_listen_port: 9080

positions:
filename: /tmp/positions.yaml

clients:
- url: http://loki:3100/loki/api/v1/push

scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log

- job_name: journal
journal:
json: false
max_age: 12h
path: /var/log/journal
# matches: _syslog_identifier=dockerd
labels:
job: systemd-journal
relabel_configs:
- source_labels:
- __journal__systemd_unit
target_label: systemd_unit
- source_labels:
- __journal__hostname
target_label: hostname
- source_labels:
- __journal_syslog_identifier
target_label: syslog_identifier
- source_labels:
- __journal__transport
target_label: transport

- job_name: containers
static_configs:
- targets:
- localhost
labels:
job: containerlogs
__path__: /var/lib/docker/containers/*/*log

# --log-opt tag="{{.Name}}"
pipeline_stages:

- json:
expressions:
stream: stream
attrs: attrs
tag: attrs.tag

- regex:
expression: (?P<container_name>(?:[^|]*[^|]))
source: "tag"

- labels:
tag:
stream:
container_name:

- job_name: flog_scrape
docker_sd_configs:
- host: unix:///var/run/docker.sock
refresh_interval: 5s
filters:
- name: name
values: [flog]
relabel_configs:
- source_labels: ['__meta_docker_container_name']
regex: '/(.*)\.[0-9]\..*'
target_label: 'name'
- source_labels: ['__meta_docker_container_name']
regex: '/(.*)\.[0-9a-z]*\..*'
target_label: 'name'
- source_labels: ['__meta_docker_container_name']
regex: '/.*\.([0-9]{1,2})\..*'
target_label: 'replica'
62 changes: 62 additions & 0 deletions scripts/docker-compose.logs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: "3.9"

x-logging: &default-logging
driver: loki
options:
loki-url: http://localhost:3100/loki/api/v1/push
loki-retries: 5
loki-batch-size: 400

services:
loki:
image: grafana/loki:2.9.2
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
logging: *default-logging
networks:
- loki

promtail:
image: grafana/promtail:2.9.2
volumes:
- /var/log:/var/log
- /var/lib/docker/containers:/var/lib/docker/containers
- ./configs/promtail.yml:/etc/promtail/config.yml
command: -config.file=/etc/promtail/config.yml
networks:
- loki

grafana:
environment:
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
logging: *default-logging
entrypoint:
- sh
- -euc
- |
mkdir -p /etc/grafana/provisioning/datasources
cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
orgId: 1
url: http://loki:3100
basicAuth: false
isDefault: true
version: 1
editable: false
EOF
/run.sh
image: grafana/grafana:latest
ports:
- "3000:3000"
networks:
- loki

networks:
loki:
18 changes: 18 additions & 0 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
version: "3.12"
x-logging: &default-logging
driver: loki
options:
loki-url: http://localhost:3100/loki/api/v1/push
loki-retries: 5
loki-batch-size: 400

services:
ngrok-traction-agent:
image: ngrok/ngrok
logging: *default-logging
environment:
- NGROK_AUTHTOKEN=${NGROK_AUTHTOKEN}
- TRACTION_ACAPY_HTTP_PORT=${TRACTION_ACAPY_HTTP_PORT}
Expand All @@ -11,6 +19,7 @@ services:

traction-acapy-image-builder:
pull_policy: missing
logging: *default-logging
build:
context: ../plugins
dockerfile: ./docker/Dockerfile
Expand All @@ -24,6 +33,7 @@ services:
context: ../services/aca-py
dockerfile: Dockerfile.acapy
image: traction:traction-agent
logging: *default-logging
depends_on:
traction-acapy-image-builder:
condition: service_started
Expand Down Expand Up @@ -95,6 +105,7 @@ services:

traction-db:
image: "postgres:14.5"
logging: *default-logging
environment:
- POSTGRES_USER=${POSTGRESQL_USER}
- POSTGRES_PASSWORD=${POSTGRESQL_PASSWORD}
Expand All @@ -113,6 +124,7 @@ services:

tenant-ui:
pull_policy: missing
logging: *default-logging
build:
context: ../services/tenant-ui
dockerfile: Dockerfile
Expand All @@ -122,7 +134,9 @@ services:
condition: service_started
environment:
- SERVER_TRACTION_URL=${SERVER_TRACTION_URL}
- SERVER_LOKI_URL=${SERVER_LOKI_URL}
- FRONTEND_TENANT_PROXY_URL=${FRONTEND_TENANT_PROXY_URL}
- FRONTEND_LOG_STREAM_URL=${FRONTEND_LOG_STREAM_URL}
esune marked this conversation as resolved.
Show resolved Hide resolved
- IMAGE_BUILDTIME=${IMAGE_BUILDTIME}
- IMAGE_TAG=${IMAGE_TAG}
- IMAGE_VERSION=${IMAGE_VERSION}
Expand All @@ -146,6 +160,7 @@ services:

tenant-proxy:
pull_policy: missing
logging: *default-logging
build:
context: ../plugins
dockerfile: ./docker/Dockerfile.tenant-proxy
Expand All @@ -167,6 +182,7 @@ services:
depends_on:
endorser-db:
condition: service_healthy
logging: *default-logging
ports:
- ${ACAPY_ENDORSER_ADMIN_PORT}:${ACAPY_ENDORSER_ADMIN_PORT}
- ${ACAPY_ENDORSER_HTTP_PORT}:${ACAPY_ENDORSER_HTTP_PORT}
Expand Down Expand Up @@ -205,6 +221,7 @@ services:
depends_on:
endorser-db:
condition: service_healthy
logging: *default-logging
ports:
- ${ACAPY_ENDORSER_1_ADMIN_PORT}:${ACAPY_ENDORSER_1_ADMIN_PORT}
- ${ACAPY_ENDORSER_1_HTTP_PORT}:${ACAPY_ENDORSER_1_HTTP_PORT}
Expand Down Expand Up @@ -240,6 +257,7 @@ services:

endorser-db:
image: "postgres:14.5"
logging: *default-logging
environment:
- POSTGRES_USER=${POSTGRESQL_USER}
- POSTGRES_PASSWORD=${POSTGRESQL_PASSWORD}
Expand Down
7 changes: 4 additions & 3 deletions scripts/manage
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ generate_traction_ascii_art() {

# Global variable to hold Docker Compose command
compose_cmd=""
compose_files_opt="-f docker-compose.logs.yml -f docker-compose.yml"

# Function to determine the correct Docker Compose command
get_docker_compose_command() {
if command -v "docker" > /dev/null && docker compose version > /dev/null 2>&1; then
compose_cmd="docker compose"
compose_cmd="docker compose $compose_files_opt"
elif command -v docker-compose > /dev/null 2>&1; then
compose_cmd="docker-compose"
compose_cmd="docker-compose $compose_files_opt"
else
echo "Error: Neither 'docker compose' nor 'docker-compose' is installed." >&2
exit 1
Expand Down Expand Up @@ -65,7 +66,7 @@ build_docker_images() {
fi

built_services="traction-acapy-image-builder tenant-ui tenant-proxy endorser-api endorser-api-1"
pulled_services="ngrok-traction-agent traction-db endorser-db endorser-db-1 maildev endorser-agent endorser-agent-1"
pulled_services="loki promtail grafana ngrok-traction-agent traction-db endorser-db endorser-db-1 maildev endorser-agent endorser-agent-1"
$compose_cmd build $built_services --no-cache --parallel
$compose_cmd pull $pulled_services
}
Expand Down
17 changes: 4 additions & 13 deletions services/tenant-ui/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
{
"name": "backend - run dev",
"request": "launch",
"runtimeArgs": [
"run-script",
"dev"
],
"runtimeArgs": ["run-script", "dev"],
"runtimeExecutable": "npm",
"skipFiles": [],
"type": "node",
Expand All @@ -19,11 +16,8 @@
{
"name": "frontend - run dev",
"request": "launch",
"cwd":"${workspaceFolder}/frontend",
"runtimeArgs": [
"run-script",
"dev"
],
"cwd": "${workspaceFolder}/frontend",
"runtimeArgs": ["run-script", "dev", "--", "--host"],
"runtimeExecutable": "npm",
"skipFiles": [],
"type": "node",
Expand All @@ -39,9 +33,6 @@
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
}
},



}
]
}
2 changes: 1 addition & 1 deletion services/tenant-ui/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"prettier.enable": true,
"[javascript]": {
Expand Down
4 changes: 3 additions & 1 deletion services/tenant-ui/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"frontend": {
"tenantProxyPath": "FRONTEND_TENANT_PROXY_URL",
"logStreamUrl": "FRONTEND_LOG_STREAM_URL",
"showInnkeeperReservationPassword": "FRONTEND_INNKEEPER_SHOW_RESERVATION_PASSWORD",
"showInnkeeperAdminLogin": "FRONTEND_INNKEEPER_SHOW_ADMIN",
"showWritableComponents": "FRONTEND_TENANT_SHOW_WRITABLE_COMPONENTS",
Expand Down Expand Up @@ -46,6 +47,7 @@
},
"server": {
"tractionUrl": "SERVER_TRACTION_URL",
"lokiUrl": "SERVER_LOKI_URL",
"oidc": {
"jwksUri": "SERVER_OIDC_JWKS",
"realm": "SERVER_OIDC_REALM",
Expand All @@ -65,4 +67,4 @@
"innkeeperInbox": "SERVER_SMTP_INNKEEPER_INBOX"
}
}
}
}
Loading
Loading