Skip to content

Commit

Permalink
Experimental logback-spring setup for Loki and Grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Villavicencio authored and Daniel Villavicencio committed May 19, 2024
1 parent 8cd0393 commit 34830c4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ext {
set('mapStructVersion', '1.5.5.Final')
set('resilienceReactorVersion', '1.6.1')
set('resilienceRateLimiterVersion', '1.6.1')
set('lokiLogbackAppenderVersion', '1.5.1')
}

jar {
Expand All @@ -69,6 +70,7 @@ dependencies {
implementation "commons-codec:commons-codec:${commonsCodecVersion}"
implementation "software.pando.crypto:salty-coffee:${pandoCryptoVersion}"
implementation "org.apache.commons:commons-collections4:${apacheCollectionsVersion}"
implementation "com.github.loki4j:loki-logback-appender:${lokiLogbackAppenderVersion}"
implementation 'org.springframework.boot:spring-boot-starter-actuator'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
37 changes: 37 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
riven-of-a-thousand-servers:
container_name: rivenbot
image: ${DOCKER_IMAGE_NAME}
env_file:
- .env
Expand All @@ -20,11 +21,13 @@ services:
- bungie_client_id
- bungie_client_secret
redis:
container_name: redis
hostname: redis
image: "redis:7.0.11"
ports:
- "6379:6379"
mongodb:
container_name: mongodb
hostname: mongo
image: "mongo:7.0.3"
ports:
Expand All @@ -36,6 +39,40 @@ services:
secrets:
- "mongo_username"
- "mongo_password"
loki:
container_name: loki
image: grafana/loki:2.9.0
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
grafana:
container_name: 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-oss:latest
ports:
- "3000:3000"

secrets:
mongo_username:
Expand Down
49 changes: 49 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- local configuration -->
<springProfile name="local">
<configuration>
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://localhost:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>%-5level [%.5(${HOSTNAME})] %.10thread %logger{20} | %msg %ex</pattern>
</message>
</format>
</appender>

<root level="INFO">
<appender-ref ref="LOKI"/>
</root>
</configuration>
<!-- prod configuration -->
</springProfile>
<springProfile name="prod">
<configuration>
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://loki:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>%-5level [%.5(${HOSTNAME})] %.10thread %logger{20} | %msg %ex</pattern>
</message>
</format>
</appender>

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

0 comments on commit 34830c4

Please sign in to comment.