Skip to content

Commit

Permalink
Enable logstash-formatted JSON logging to the console
Browse files Browse the repository at this point in the history
To enable JSON logging, the applications must be run with the
`json-logs` Spring profile.

The default configuration in the Docker images at `/etc/geoserver/`
include logback and rabbitmq config files for JSON logging:

* `logback-spring.xml` defines a logstash compatible JSON console
  appender for spring boot apps. This default file is identical to the
  one included in the applications classpath already. In order to use
  this one, for example, may it require some tunning, the application
  must be run with `-Dlogging.config=file:/etc/geoserver/logback-spring.xml`,
  or any other location where the xml config file is placed.
* A sample `rabbitmq.conf` file declaring console json logging output
  for rabbitmq. Must be mounted at `/etc/rabbitmq/rabbitmq.conf`, or use
  it as a guideline to enhance rabbitmq's configuration.
  • Loading branch information
groldan committed Jun 17, 2024
1 parent d1b3ba9 commit ee781d6
Show file tree
Hide file tree
Showing 7 changed files with 67 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.9-SNAPSHOT
ACL_TAG=2.3-SNAPSHOT
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
Submodule config updated 2 files
+17 −0 logback-spring.xml
+5 −0 rabbitmq.conf
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
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).
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>

0 comments on commit ee781d6

Please sign in to comment.