Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions cmd/argocd-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/argoproj-labs/argocd-agent/internal/env"
"github.com/argoproj-labs/argocd-agent/internal/grpcutil"
"github.com/argoproj-labs/argocd-agent/internal/tracing"
"github.com/argoproj-labs/argocd-agent/internal/version"
"github.com/argoproj-labs/argocd-agent/pkg/client"
"github.com/argoproj-labs/argocd-agent/pkg/types"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -113,6 +114,27 @@ func NewAgentRunCommand() *cobra.Command {
ctx, cancelFn := context.WithCancel(context.Background())
defer cancelFn()

if formatter, err := cmdutil.LogFormatter(logFormat); err != nil {
cmdutil.Fatal("%s", err.Error())
} else {
logrus.SetFormatter(formatter)
}

subLoggers := cmdutil.SubSystemLoggers{
ResourceProxyLogger: cmdutil.CreateLogger(logFormat),
RedisProxyLogger: cmdutil.CreateLogger(logFormat),
GrpcEventLogger: cmdutil.CreateLogger(logFormat),
}

if len(logLevels) == 0 {
logLevels = append(logLevels, "info")
}
if len(logLevels) > 0 {
cmdutil.ParseLogLevels(logLevels, &subLoggers)
}

logrus.Infof("Initializing argocd-agent v%s (agent)", version.New("argocd-agent").Version())

// Initialize OpenTelemetry tracing if enabled
if otlpAddress != "" {
shutdownTracer, err := tracing.InitTracer(ctx, "agent-"+agentMode, otlpAddress, otlpInsecure)
Expand Down Expand Up @@ -141,25 +163,6 @@ func NewAgentRunCommand() *cobra.Command {
agentOpts := []agent.AgentOption{}
remoteOpts := []client.RemoteOption{}

if formatter, err := cmdutil.LogFormatter(logFormat); err != nil {
cmdutil.Fatal("%s", err.Error())
} else {
logrus.SetFormatter(formatter)
}

subLoggers := cmdutil.SubSystemLoggers{
ResourceProxyLogger: cmdutil.CreateLogger(logFormat),
RedisProxyLogger: cmdutil.CreateLogger(logFormat),
GrpcEventLogger: cmdutil.CreateLogger(logFormat),
}

if len(logLevels) == 0 {
logLevels = append(logLevels, "info")
}
if len(logLevels) > 0 {
cmdutil.ParseLogLevels(logLevels, &subLoggers)
}

agentOpts = append(agentOpts, agent.WithSubsystemLoggers(subLoggers.ResourceProxyLogger, subLoggers.RedisProxyLogger, subLoggers.GrpcEventLogger))
if namespace == "" {
cmdutil.Fatal("namespace value is empty and must be specified")
Expand Down
41 changes: 22 additions & 19 deletions cmd/argocd-agent/principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/argoproj-labs/argocd-agent/internal/labels"
"github.com/argoproj-labs/argocd-agent/internal/tlsutil"
"github.com/argoproj-labs/argocd-agent/internal/tracing"
"github.com/argoproj-labs/argocd-agent/internal/version"
"github.com/argoproj-labs/argocd-agent/pkg/ha"
"github.com/argoproj-labs/argocd-agent/principal"
cacheutil "github.com/argoproj/argo-cd/v3/util/cache"
Expand Down Expand Up @@ -135,6 +136,27 @@ func NewPrincipalRunCommand() *cobra.Command {
ctx, cancelFn := context.WithCancel(context.Background())
defer cancelFn()

if formatter, err := cmdutil.LogFormatter(logFormat); err != nil {
cmdutil.Fatal("%s", err.Error())
} else {
logrus.SetFormatter(formatter)
}

subLoggers := cmdutil.SubSystemLoggers{
ResourceProxyLogger: cmdutil.CreateLogger(logFormat),
RedisProxyLogger: cmdutil.CreateLogger(logFormat),
GrpcEventLogger: cmdutil.CreateLogger(logFormat),
}

if len(logLevels) == 0 {
logLevels = append(logLevels, "info")
}
if len(logLevels) > 0 {
cmdutil.ParseLogLevels(logLevels, &subLoggers)
}

logrus.Infof("Initializing argocd-agent v%s (principal)", version.New("argocd-agent").Version())

// Initialize OpenTelemetry tracing if enabled
if otlpAddress != "" {
shutdownTracer, err := tracing.InitTracer(ctx, "principal", otlpAddress, otlpInsecure)
Expand All @@ -161,25 +183,6 @@ func NewPrincipalRunCommand() *cobra.Command {
}

opts := []principal.ServerOption{}
if formatter, err := cmdutil.LogFormatter(logFormat); err != nil {
cmdutil.Fatal("%s", err.Error())
} else {
logrus.SetFormatter(formatter)
}

subLoggers := cmdutil.SubSystemLoggers{
ResourceProxyLogger: cmdutil.CreateLogger(logFormat),
RedisProxyLogger: cmdutil.CreateLogger(logFormat),
GrpcEventLogger: cmdutil.CreateLogger(logFormat),
}

if len(logLevels) == 0 {
logLevels = append(logLevels, "info")
}
if len(logLevels) > 0 {
cmdutil.ParseLogLevels(logLevels, &subLoggers)
}

opts = append(opts, principal.WithSubsystemLoggers(subLoggers.ResourceProxyLogger, subLoggers.RedisProxyLogger, subLoggers.GrpcEventLogger))

kubeConfig, err := cmdutil.GetKubeConfig(ctx, namespace, kubeConfig, kubeContext)
Expand Down
Loading