Skip to content

Commit 6cfa263

Browse files
diaasamicroissanne
authored andcommitted
composer: use logrus hook instead of k8s sidecar
for splunk log forwarding Fixes COMPOSER-2051
1 parent 6b6af41 commit 6cfa263

File tree

9 files changed

+436
-57
lines changed

9 files changed

+436
-57
lines changed

cmd/osbuild-composer/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ type ComposerConfigFile struct {
1818
LogLevel string `toml:"log_level"`
1919
LogFormat string `toml:"log_format"`
2020
DNFJson string `toml:"dnf-json"`
21+
SplunkHost string `env:"SPLUNK_HEC_HOST"`
22+
SplunkPort string `env:"SPLUNK_HEC_PORT"`
23+
SplunkToken string `env:"SPLUNK_HEC_TOKEN"`
2124
}
2225

2326
type KojiAPIConfig struct {

cmd/osbuild-composer/main.go

+11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package main
22

33
import (
4+
"context"
45
"flag"
56
"os"
67

78
"github.com/coreos/go-systemd/activation"
9+
slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger"
810
"github.com/sirupsen/logrus"
911
"github.com/sirupsen/logrus/hooks/syslog"
1012
)
@@ -60,6 +62,15 @@ func main() {
6062
logrus.Fatalf("Error printing configuration: %v", err)
6163
}
6264

65+
if config.SplunkHost != "" {
66+
hook, err := slogger.NewSplunkHook(context.Background(), config.SplunkHost, config.SplunkPort, config.SplunkToken, "composer")
67+
68+
if err != nil {
69+
panic(err)
70+
}
71+
logrus.AddHook(hook)
72+
}
73+
6374
stateDir, ok := os.LookupEnv("STATE_DIRECTORY")
6475
if !ok {
6576
logrus.Fatal("STATE_DIRECTORY is not set. Is the service file missing StateDirectory=?")

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ require (
3232
github.com/openshift-online/ocm-sdk-go v0.1.385
3333
github.com/oracle/oci-go-sdk/v54 v54.0.0
3434
github.com/osbuild/images v0.18.0
35+
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20231117174845-e969a9dc3cd1
3536
github.com/osbuild/pulp-client v0.1.0
3637
github.com/prometheus/client_golang v1.17.0
3738
github.com/segmentio/ksuid v1.0.4

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ github.com/oracle/oci-go-sdk/v54 v54.0.0 h1:CDLjeSejv2aDpElAJrhKpi6zvT/zhZCZuXch
455455
github.com/oracle/oci-go-sdk/v54 v54.0.0/go.mod h1:+t+yvcFGVp+3ZnztnyxqXfQDsMlq8U25faBLa+mqCMc=
456456
github.com/osbuild/images v0.18.0 h1:I/tOO7DCECciJptrXVq+oykJI5dP1rwkzJqmf2rKuqw=
457457
github.com/osbuild/images v0.18.0/go.mod h1:Zr+AkaX/Rpxyff6Zxh8kkwGKFtJsSukGo1Vv/j9HsxA=
458+
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20231117174845-e969a9dc3cd1 h1:UFEJIcPa46W8gtWgOYzriRKYyy1t6SWL0BI7fPTuVvc=
459+
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20231117174845-e969a9dc3cd1/go.mod h1:z+WA+dX6qMwc7fqY5jCzESDIlg4WR2sBQezxsoXv9Ik=
458460
github.com/osbuild/pulp-client v0.1.0 h1:L0C4ezBJGTamN3BKdv+rKLuq/WxXJbsFwz/Hj7aEmJ8=
459461
github.com/osbuild/pulp-client v0.1.0/go.mod h1:rd/MLdfwwO2cQI1s056h8z32zAi3Bo90XhlAAryIvWc=
460462
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=

templates/composer.yml

+16-57
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,21 @@ objects:
103103
value: "${PGSSLMODE}"
104104
- name: PGMAXCONNS
105105
value: "${PGMAXCONNS}"
106-
- name: SYSLOG_SERVER
107-
value: "localhost:5140"
106+
# Splunk forwarding
107+
- name: SPLUNK_HEC_TOKEN
108+
valueFrom:
109+
secretKeyRef:
110+
name: splunk
111+
key: token
112+
optional: true
113+
- name: SPLUNK_HEC_HOST
114+
valueFrom:
115+
secretKeyRef:
116+
name: splunk
117+
key: url
118+
optional: true
119+
- name: SPLUNK_HEC_PORT
120+
value: "${SPLUNK_HEC_PORT}"
108121
ports:
109122
- name: composer-api
110123
protocol: TCP
@@ -123,32 +136,6 @@ objects:
123136
mountPath: "/var/lib/osbuild-composer"
124137
- name: cache-directory
125138
mountPath: "/var/cache/osbuild-composer"
126-
- image: "quay.io/app-sre/fluentd-hec:1.2.13"
127-
name: fluentd-sidecar
128-
resources:
129-
requests:
130-
cpu: "${FLUENTD_CPU_REQUEST}"
131-
memory: "${MEMORY_REQUEST}"
132-
limits:
133-
cpu: "${FLUENTD_CPU_LIMIT}"
134-
memory: "${MEMORY_LIMIT}"
135-
env:
136-
- name: SPLUNK_HEC_TOKEN
137-
valueFrom:
138-
secretKeyRef:
139-
name: splunk
140-
key: token
141-
optional: false
142-
- name: SPLUNK_HEC_URL
143-
valueFrom:
144-
secretKeyRef:
145-
name: splunk
146-
key: url
147-
optional: false
148-
volumeMounts:
149-
- name: fluentd-config
150-
mountPath: /fluentd/etc
151-
readOnly: true
152139
volumes:
153140
- name: composer-config
154141
configMap:
@@ -157,9 +144,6 @@ objects:
157144
emptyDir: {}
158145
- name: cache-directory
159146
emptyDir: {}
160-
- name: fluentd-config
161-
configMap:
162-
name: fluentd-config
163147
initContainers:
164148
- name: composer-migrate
165149
image: "${IMAGE_NAME}:${IMAGE_TAG}"
@@ -273,30 +257,6 @@ objects:
273257
jwt_keys_urls = ["${RH_SSO_BASE_URL}/protocol/openid-connect/certs"]
274258
jwt_acl_file = "${COMPOSER_CONFIG_DIR}/acl.yml"
275259
jwt_tenant_provider_fields = ["rh-org-id", "account_id"]
276-
- apiVersion: v1
277-
kind: ConfigMap
278-
metadata:
279-
name: fluentd-config
280-
data:
281-
fluent.conf: |
282-
<source>
283-
@type syslog
284-
port 5140
285-
bind 127.0.0.1
286-
<transport tcp>
287-
</transport>
288-
tag osbuild-composer
289-
<parse>
290-
time_format %Y-%m-%dT%H:%M:%SZ
291-
</parse>
292-
</source>
293-
294-
<match **>
295-
@type splunk_hec
296-
hec_host "#{ENV['SPLUNK_HEC_URL']}"
297-
hec_port "${SPLUNK_HEC_PORT}"
298-
hec_token "#{ENV['SPLUNK_HEC_TOKEN']}"
299-
</match>
300260
- apiVersion: batch/v1
301261
kind: CronJob
302262
metadata:
@@ -523,7 +483,6 @@ parameters:
523483
name: MAINTENANCE_MAX_CONCURRENT_REQUESTS
524484
value: "10"
525485
required: true
526-
- description: fluentd-hec splunk port
486+
- description: Splunk HTTP Event Collector port
527487
name: SPLUNK_HEC_PORT
528488
value: "443"
529-
required: true

vendor/github.com/osbuild/osbuild-composer/pkg/splunk_logger/LICENSE

+201
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)