Skip to content

Commit

Permalink
Merge pull request #488 from groldan/observability/json_logging_1.8.x
Browse files Browse the repository at this point in the history
[backport 1.8.x] Enable logstash-formatted JSON logging to the console #487
  • Loading branch information
groldan committed Jun 17, 2024
2 parents 60ad9b4 + 8d6b390 commit 1ba3527
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 18 deletions.
29 changes: 20 additions & 9 deletions compose/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,39 @@ TAG=1.8-SNAPSHOT
ACL_TAG=2.2.0
GS_USER="1000:1000"

BASE_PATH=/geoserver/cloud
# geoserver entry point for the gateway
GEOSERVER_BASE_PATH=/geoserver/cloud

GEOSERVER_DEFAULT_PROFILES="default,acl"
# logging profile, either "default" or "json-logs"
LOGGING_PROFILE=json-logs

JDBCCONFIG_DBNAME=geoserver_config
JDBCCONFIG_URL=jdbc:postgresql://database:5432/${JDBCCONFIG_DBNAME}
JDBCCONFIG_USERNAME=geoserver
JDBCCONFIG_PASSWORD=geo5erver
GEOSERVER_DEFAULT_PROFILES="${LOGGING_PROFILE},acl"
GATEWAY_DEFAULT_PROFILES=${LOGGING_PROFILE}
DISCOVERY_SERVER_DEFAULT_PROFILES=${LOGGING_PROFILE}

# Remember to use docker-compose --compatibility
# Either 'git' or 'native' active profile must be set. Use the default sample git repository to download the services configuration from
# If 'git', BEWARE config server will look for a branch called "master", and github changed the default branch name to "main"
# For more information, see https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html#_git_backend
CONFIG_SERVER_DEFAULT_PROFILES=${LOGGING_PROFILE},native,standalone

JAVA_OPTS_DEFAULT=-XX:MaxRAMPercentage=80 -XshowSettings:system -Djndi.postgis.enabled=true

JAVA_OPTS_GEOSERVER=$JAVA_OPTS_DEFAULT
JAVA_OPTS_DEFAULT=-XX:MaxRAMPercentage=80 -XshowSettings:system -Dlogging.config=file:/etc/geoserver/logback-spring.xml

JAVA_OPTS_DISCOVERY=$JAVA_OPTS_DEFAULT
JAVA_OPTS_CONFIG=$JAVA_OPTS_DEFAULT
JAVA_OPTS_GATEWAY=$JAVA_OPTS_DEFAULT

JAVA_OPTS_GEOSERVER=$JAVA_OPTS_DEFAULT -Djndi.postgis.enabled=true

JAVA_OPTS_WFS=$JAVA_OPTS_GEOSERVER
JAVA_OPTS_WMS=$JAVA_OPTS_GEOSERVER
JAVA_OPTS_WCS=$JAVA_OPTS_GEOSERVER
JAVA_OPTS_WPS=$JAVA_OPTS_GEOSERVER
JAVA_OPTS_REST=$JAVA_OPTS_GEOSERVER
JAVA_OPTS_WEBUI=$JAVA_OPTS_GEOSERVER
JAVA_OPTS_GWC=$JAVA_OPTS_GEOSERVER

JDBCCONFIG_DBNAME=geoserver_config
JDBCCONFIG_URL=jdbc:postgresql://database:5432/${JDBCCONFIG_DBNAME}
JDBCCONFIG_USERNAME=geoserver
JDBCCONFIG_PASSWORD=geo5erver
10 changes: 4 additions & 6 deletions compose/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ services:
user: ${GS_USER}
environment:
JAVA_OPTS: "${JAVA_OPTS_CONFIG}"
# Either 'git' or 'native'. Use the default sample git repository to download the services configuration from
# If 'git', BEWARE config server will look for a branch called "master", and github changed the default branch name to "main"
# For more information, see https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html#_git_backend
SPRING_PROFILES_ACTIVE: native,standalone
SPRING_PROFILES_ACTIVE: "${CONFIG_SERVER_DEFAULT_PROFILES}"
# 'git' profile config
CONFIG_GIT_URI: https://github.com/geoserver/geoserver-cloud-config
CONFIG_GIT_BASEDIR: /tmp/git_config
Expand All @@ -82,6 +79,7 @@ services:
user: ${GS_USER}
environment:
JAVA_OPTS: "${JAVA_OPTS_DISCOVERY}"
SPRING_PROFILES_ACTIVE: "${DISCOVERY_SERVER_DEFAULT_PROFILES}"
ports:
- 8761:8761 # for development, so services can be run from localhost and find the discovery service running on docker
restart: unless-stopped
Expand All @@ -103,9 +101,9 @@ services:
condition: service_healthy
environment:
JAVA_OPTS: "${JAVA_OPTS_GATEWAY}"
SPRING_PROFILES_ACTIVE: dev #exposes the catalog and config API at /api/v1/**
# eat our own dogfood and set a base path
GEOSERVER_BASE_PATH: ${BASE_PATH}
GEOSERVER_BASE_PATH: ${GEOSERVER_BASE_PATH}
SPRING_PROFILES_ACTIVE: "${GATEWAY_DEFAULT_PROFILES}"
ports:
- 9090:8080
deploy:
Expand Down
3 changes: 2 additions & 1 deletion compose/infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ services:
user: ${GS_USER}
tmpfs:
- /var/lib/rabbitmq
#volumes:
volumes:
- $PWD/../config/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
# - rabbitmq_data:/var/lib/rabbitmq
ports:
- "5672:5672"
Expand Down
2 changes: 1 addition & 1 deletion config
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
<artifactId>gs-cloud-starter-wms-extensions</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.geoserver.cloud</groupId>
<artifactId>gs-cloud-starter-observability</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.geoserver.cloud.catalog</groupId>
<artifactId>gs-cloud-catalog-plugin</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions src/apps/base-images/spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<groupId>org.geoserver.cloud</groupId>
<artifactId>gs-cloud-spring-boot-starter</artifactId>
</dependency>
<dependency>
<!-- include the observability libraries in the base spring boot image -->
<groupId>org.geoserver.cloud</groupId>
<artifactId>gs-cloud-starter-observability</artifactId>
</dependency>
<dependency>
<groupId>org.geoserver.cloud.apps</groupId>
<artifactId>gs-cloud-base-jre</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions src/apps/geoserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<groupId>org.geoserver.cloud</groupId>
<artifactId>gs-cloud-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.geoserver.cloud</groupId>
<artifactId>gs-cloud-starter-observability</artifactId>
</dependency>
<dependency>
<groupId>org.geoserver.cloud</groupId>
<artifactId>spring-boot-simplejndi</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion src/apps/geoserver/wms/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ spring:
# override default of true, this service does not use the registry (when eureka client is enabled)
eureka.client.fetch-registry: false

logging.level:
logging:
level:
'[org.springframework.retry]': debug
---
# local profile, used for development only. Other settings like config and eureka urls in gs_cloud_bootstrap_profiles.yml
Expand Down
4 changes: 4 additions & 0 deletions src/apps/infrastructure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.geoserver.cloud</groupId>
<artifactId>gs-cloud-starter-observability</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions src/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@
-->
<aws.version>2.20.117</aws.version>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<!-- logstash-logback-encoder:7.4+ requires logback 1.3+ and slf4j 2.0+, only available on spring-boot 3.0+ -->
<logstash-logback-encoder.version>7.3</logstash-logback-encoder.version>
</properties>
<dependencyManagement>
<!-- Note dependencies added purely to satisfy the dependencyConvergence maven-enforcer-plugin rule are in the dependencyConvergence maven profile -->
<dependencies>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>${logstash-logback-encoder.version}</version>
</dependency>
<dependency>
<!-- Upgrade to snakeyaml 2.0 to get rid of several CVE's from
the 1.30 version included with spring-boot -->
Expand Down
21 changes: 21 additions & 0 deletions src/starters/observability/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Observability starter

Spring-Boot starter project to treat application observability (logging, metrics, tracing) as a cross-cutting concern.

## Dependency

Add dependency

```xml
<dependency>
<groupId>org.geoserver.cloud</groupId>
<artifactId>gs-cloud-starter-observability</artifactId>
<version>${project.verison}</version>
</dependency>
```

## Logstash formatted JSON Logging

The `net.logstash.logback:logstash-logback-encoder` dependency allows to write logging entries as JSON-formatted objects in Logstash scheme.

The application must be run with the `json-logs` Spring profile, as defined in [logback-spring.xml](src/main/resources/logback-spring.xml).
18 changes: 18 additions & 0 deletions src/starters/observability/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geoserver.cloud</groupId>
<artifactId>gs-cloud-starters</artifactId>
<version>${revision}</version>
</parent>
<artifactId>gs-cloud-starter-observability</artifactId>
<packaging>jar</packaging>
<description>Spring boot starter for application observability (logging, metrics, tracing)</description>
<dependencies>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
</dependency>
</dependencies>
</project>
17 changes: 17 additions & 0 deletions src/starters/observability/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<configuration>

<springProfile name="default">
<include resource="org/springframework/boot/logging/logback/base.xml" />
</springProfile>

<springProfile name="json-logs">
<appender name="jsonConsoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>

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

</configuration>
1 change: 1 addition & 0 deletions src/starters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<module>webmvc</module>
<module>wms-extensions</module>
<module>security</module>
<module>observability</module>
</modules>
<dependencies>
<dependency>
Expand Down

0 comments on commit 1ba3527

Please sign in to comment.