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

✨ add log monitoring dashboard #131

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation 'com.google.firebase:firebase-admin:9.3.0'
implementation 'com.auth0:java-jwt:4.4.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
implementation 'com.github.loki4j:loki-logback-appender:1.5.1'

runtimeOnly 'mysql:mysql-connector-java:8.0.33'
runtimeOnly 'com.h2database:h2'
Expand Down
37 changes: 36 additions & 1 deletion backend/src/main/resources/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,41 @@ services:
environment:
JASYPT_PASSWORD: ${JASYPT_PASSWORD}
ports:
- 7848:8080
- 8080:8080
links:
- db
- loki

loki:
image: grafana/loki
command: -config.file=/etc/loki/local-config.yaml

grafana:
environment:
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
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
ports:
- 3000:3000
links:
- loki
36 changes: 36 additions & 0 deletions backend/src/main/resources/docker-compose-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,39 @@ services:
command:
- --character-set-server=utf8
- --collation-server=utf8_general_ci

loki:
image: grafana/loki
ports:
- 3100:3100
command: -config.file=/etc/loki/local-config.yaml

grafana:
environment:
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
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
ports:
- 3000:3000
links:
- loki
41 changes: 41 additions & 0 deletions backend/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProfile name="local">
<property name="LOKI_URL" value="http://localhost:3100/loki/api/v1/push"/>
</springProfile>

<springProfile name="test">
<property name="LOKI_URL" value="http://localhost:3100/loki/api/v1/push"/>
</springProfile>

Comment on lines +7 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트를 위한 부분도 추가해주어야 하는군요 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트할 때의 로그는 수집하지 않지만 없을 경우 아래쪽 ${LOKI_URL} 을 읽지를 못하여 ContextLoad 에 실패하더군요. 그래서 더미 값을 추가했습니다!

<springProfile name="dev">
<property name="LOKI_URL" value="http://loki:3100/loki/api/v1/push"/>
</springProfile>

<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>${LOKI_URL}</url>
</http>
<format>
<label>
<pattern>app=Pengcook,host=${HOSTNAME},level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>
{
"level":"%level",
"class":"%logger{36}",
"thread":"%thread",
"message": "%message",
"requestId": "%X{X-Request-ID}"
}
</pattern>
</message>
</format>
</appender>

<root level="INFO">
<appender-ref ref="LOKI"/>
</root>
</configuration>
Loading