Skip to content

Commit b0abb43

Browse files
authored
feat: allow configurable json logging for besu (#12)
## Summary - add a logFormat toggle for Besu nodes supporting plain or json output - generate a Log4j2 JSON layout configmap and wire LOG4J env + mount when selected - document the new option in the network-nodes chart values ## Testing - bun run typecheck - bun run check - bun run test - helm template charts/network - helm template charts/network --set network-nodes.config.logFormat=json ## Summary by Sourcery Add a logFormat toggle to the network-nodes Helm chart to enable JSON logging for Besu nodes by generating a Log4j2 JSON layout configmap, mounting it in the pods, and updating documentation New Features: - Support configurable logFormat in network-nodes chart to toggle between plain and JSON output - Generate and conditionally mount a Log4j2 JSON layout configuration and set LOG4J_CONFIGURATION_FILE env var when JSON logging is enabled - Document the logFormat option in values.yaml and README
1 parent 862012b commit b0abb43

7 files changed

Lines changed: 63 additions & 2 deletions

File tree

charts/network/charts/network-nodes/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: network-nodes
33
description: A Helm chart for Kubernetes
44
type: application
55
version: 0.1.1
6-
appVersion: "0.1.0"
6+
appVersion: "0.1.1"
77
maintainers:
88
- name: SettleMint
99
email: support@settlemint.com

charts/network/charts/network-nodes/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# network-nodes
22

3-
![Version: 0.1.1](https://img.shields.io/badge/Version-0.1.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.1.0](https://img.shields.io/badge/AppVersion-0.1.0-informational?style=flat-square)
3+
![Version: 0.1.1](https://img.shields.io/badge/Version-0.1.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.1.1](https://img.shields.io/badge/AppVersion-0.1.1-informational?style=flat-square)
44

55
A Helm chart for Kubernetes
66

@@ -30,6 +30,7 @@ A Helm chart for Kubernetes
3030
| config.http.maxActiveConnections | int | `2000` | Maximum concurrent HTTP JSON-RPC connections. |
3131
| config.http.maxBatchSize | int | `512` | Maximum number of batched JSON-RPC calls per request. |
3232
| config.http.maxRequestContentLength | int | `524288000` | Maximum HTTP request body size in bytes. |
33+
| config.logFormat | string | `"plain"` | Log output format. Supports "plain" (default) or "json". |
3334
| config.logging | string | `"INFO"` | Log verbosity level for Besu components. |
3435
| config.metrics.categories | list | `["BLOCKCHAIN","ETHEREUM","EXECUTORS","JVM","NETWORK","PEERS","PROCESS","PRUNER","RPC","SYNCHRONIZER","TRANSACTION_POOL"]` | Metrics categories exposed to Prometheus. |
3536
| config.metrics.enabled | bool | `true` | Enable the Prometheus metrics endpoint. |

charts/network/charts/network-nodes/templates/_helpers.tpl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ If release name contains chart name it will be used as a full name.
2121
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
2222
{{- end }}
2323
{{- end }}
24+
2425
{{- end }}
2526

2627
{{/*
@@ -61,6 +62,28 @@ Create the name of the service account to use
6162
{{- end }}
6263
{{- end }}
6364

65+
{{/*
66+
Render optional Log4j environment variables when structured logging is enabled.
67+
*/}}
68+
{{- define "nodes.log4jEnv" -}}
69+
{{- if eq (default "plain" .Values.config.logFormat) "json" }}
70+
- name: LOG4J_CONFIGURATION_FILE
71+
value: /etc/besu/log-config.xml
72+
{{- end }}
73+
{{- end }}
74+
75+
{{/*
76+
Render optional volume mounts for the Log4j configuration file.
77+
*/}}
78+
{{- define "nodes.log4jVolumeMount" -}}
79+
{{- if eq (default "plain" .Values.config.logFormat) "json" }}
80+
- name: besu-config
81+
mountPath: /etc/besu/log-config.xml
82+
subPath: log-config.xml
83+
readOnly: true
84+
{{- end }}
85+
{{- end }}
86+
6487
{{/*
6588
Resolve the number of validator replicas, falling back to global overrides when provided.
6689
*/}}

charts/network/charts/network-nodes/templates/configmap.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata:
88
{{- $persistenceEnabled := default false (get $persistence "enabled") }}
99
{{- $mountPath := default "" (get $persistence "mountPath") }}
1010
{{- $privateKeyFilename := default "privateKey" .Values.config.privateKeyFilename }}
11+
{{- $logFormat := default "plain" .Values.config.logFormat }}
1112
data:
1213
config.toml: |-
1314
data-path="/data"
@@ -61,3 +62,21 @@ data:
6162
metrics-host={{ .Values.config.metrics.host | quote }}
6263
metrics-port={{ .Values.service.ports.metrics | int }}
6364
metrics-category={{ .Values.config.metrics.categories | toJson }}
65+
{{- if eq $logFormat "json" }}
66+
log-config.xml: |-
67+
<?xml version="1.0" encoding="UTF-8"?>
68+
<Configuration status="INFO" monitorInterval="5">
69+
<Appenders>
70+
<Console name="Console" target="SYSTEM_OUT">
71+
<JsonLayout compact="false" eventEol="true" properties="true" stacktrace="true">
72+
<KeyValuePair key="container" value="${hostName}" />
73+
</JsonLayout>
74+
</Console>
75+
</Appenders>
76+
<Loggers>
77+
<Root level="{{ .Values.config.logging }}">
78+
<AppenderRef ref="Console" />
79+
</Root>
80+
</Loggers>
81+
</Configuration>
82+
{{- end }}

charts/network/charts/network-nodes/templates/statefulset-rpc.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ spec:
8585
valueFrom:
8686
fieldRef:
8787
fieldPath: status.podIP
88+
{{- $log4jEnv := include "nodes.log4jEnv" . }}
89+
{{- if $log4jEnv }}
90+
{{ $log4jEnv | nindent 12 }}
91+
{{- end }}
8892
{{- with .Values.securityContext }}
8993
securityContext:
9094
{{- toYaml . | nindent 12 }}
@@ -141,6 +145,10 @@ spec:
141145
mountPath: /etc/besu/config.toml
142146
subPath: config.toml
143147
readOnly: true
148+
{{- $log4jMount := include "nodes.log4jVolumeMount" . }}
149+
{{- if $log4jMount }}
150+
{{ $log4jMount | nindent 12 }}
151+
{{- end }}
144152
- name: besu-genesis
145153
mountPath: /etc/besu/genesis.json
146154
subPath: genesis.json

charts/network/charts/network-nodes/templates/statefulset-validator.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ spec:
8484
valueFrom:
8585
fieldRef:
8686
fieldPath: status.podIP
87+
{{- $log4jEnv := include "nodes.log4jEnv" . }}
88+
{{- if $log4jEnv }}
89+
{{ $log4jEnv | nindent 12 }}
90+
{{- end }}
8791
{{- with .Values.securityContext }}
8892
securityContext:
8993
{{- toYaml . | nindent 12 }}
@@ -140,6 +144,10 @@ spec:
140144
mountPath: /etc/besu/config.toml
141145
subPath: config.toml
142146
readOnly: true
147+
{{- $log4jMount := include "nodes.log4jVolumeMount" . }}
148+
{{- if $log4jMount }}
149+
{{ $log4jMount | nindent 12 }}
150+
{{- end }}
143151
- name: besu-genesis
144152
mountPath: /etc/besu/genesis.json
145153
subPath: genesis.json

charts/network/charts/network-nodes/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ service:
8787
config:
8888
# -- (string) Log verbosity level for Besu components.
8989
logging: INFO
90+
# -- (string) Log output format. Supports "plain" (default) or "json".
91+
logFormat: plain
9092
# -- (string) Ledger storage backend (FOREST or BONSAI).
9193
dataStorageFormat: FOREST
9294
# -- (string) Filename containing each node's private key within mounted secrets.

0 commit comments

Comments
 (0)