composer: use logrus hook instead of k8s sidecar

for splunk log forwarding
Fixes COMPOSER-2051
This commit is contained in:
Diaa Sami 2023-11-13 11:03:59 +01:00 committed by Sanne Raymaekers
parent 6b6af41e1d
commit 6cfa26399f
9 changed files with 436 additions and 57 deletions

View file

@ -18,6 +18,9 @@ type ComposerConfigFile struct {
LogLevel string `toml:"log_level"`
LogFormat string `toml:"log_format"`
DNFJson string `toml:"dnf-json"`
SplunkHost string `env:"SPLUNK_HEC_HOST"`
SplunkPort string `env:"SPLUNK_HEC_PORT"`
SplunkToken string `env:"SPLUNK_HEC_TOKEN"`
}
type KojiAPIConfig struct {

View file

@ -1,10 +1,12 @@
package main
import (
"context"
"flag"
"os"
"github.com/coreos/go-systemd/activation"
slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/syslog"
)
@ -60,6 +62,15 @@ func main() {
logrus.Fatalf("Error printing configuration: %v", err)
}
if config.SplunkHost != "" {
hook, err := slogger.NewSplunkHook(context.Background(), config.SplunkHost, config.SplunkPort, config.SplunkToken, "composer")
if err != nil {
panic(err)
}
logrus.AddHook(hook)
}
stateDir, ok := os.LookupEnv("STATE_DIRECTORY")
if !ok {
logrus.Fatal("STATE_DIRECTORY is not set. Is the service file missing StateDirectory=?")