From b52476971425d396cfd63306d53193a3e9f54df6 Mon Sep 17 00:00:00 2001 From: Kent Rancourt Date: Tue, 28 Jun 2022 14:55:51 -0400 Subject: [PATCH] feat: implement consistent startup messages for all components (#9800) * feat: implement consistent startup messages for all components Signed-off-by: Kent * DRY up previous commit Signed-off-by: Kent --- .../commands/argocd_application_controller.go | 15 +++++++++----- .../commands/applicationset_controller.go | 20 +++++++++++-------- .../commands/argocd_cmp_server.go | 3 +++ cmd/argocd-dex/commands/argocd_dex.go | 15 ++++++++++---- .../commands/controller.go | 12 ++++++++++- .../commands/argocd_repo_server.go | 12 +++++++++-- cmd/argocd-server/commands/argocd_server.go | 15 ++++++++++---- common/version.go | 12 +++++++++++ 8 files changed, 80 insertions(+), 24 deletions(-) diff --git a/cmd/argocd-application-controller/commands/argocd_application_controller.go b/cmd/argocd-application-controller/commands/argocd_application_controller.go index e345d078066a4..4eec3d1f5d3d7 100644 --- a/cmd/argocd-application-controller/commands/argocd_application_controller.go +++ b/cmd/argocd-application-controller/commands/argocd_application_controller.go @@ -67,6 +67,16 @@ func NewCommand() *cobra.Command { Long: "ArgoCD application controller is a Kubernetes controller that continuously monitors running applications and compares the current, live state against the desired target state (as specified in the repo). This command runs Application Controller in the foreground. It can be configured by following options.", DisableAutoGenTag: true, RunE: func(c *cobra.Command, args []string) error { + vers := common.GetVersion() + namespace, _, err := clientConfig.Namespace() + errors.CheckError(err) + vers.LogStartupInfo( + "ArgoCD Application Controller", + map[string]any{ + "namespace": namespace, + }, + ) + cli.SetLogFormat(cmdutil.LogFormat) cli.SetLogLevel(cmdutil.LogLevel) cli.SetGLogLevel(glogLevel) @@ -74,15 +84,11 @@ func NewCommand() *cobra.Command { config, err := clientConfig.ClientConfig() errors.CheckError(err) errors.CheckError(v1alpha1.SetK8SConfigDefaults(config)) - vers := common.GetVersion() config.UserAgent = fmt.Sprintf("argocd-application-controller/%s (%s)", vers.Version, vers.Platform) kubeClient := kubernetes.NewForConfigOrDie(config) appClient := appclientset.NewForConfigOrDie(config) - namespace, _, err := clientConfig.Namespace() - errors.CheckError(err) - hardResyncDuration := time.Duration(appHardResyncPeriod) * time.Second var resyncDuration time.Duration @@ -146,7 +152,6 @@ func NewCommand() *cobra.Command { errors.CheckError(err) cacheutil.CollectMetrics(redisClient, appController.GetMetricsServer()) - log.Infof("Application Controller (version: %s, built: %s) starting (namespace: %s)", vers.Version, vers.BuildDate, namespace) stats.RegisterStackDumper() stats.StartStatsTicker(10 * time.Minute) stats.RegisterHeapDumper("memprofile") diff --git a/cmd/argocd-applicationset-controller/commands/applicationset_controller.go b/cmd/argocd-applicationset-controller/commands/applicationset_controller.go index 99ba630403395..7a18b2d4f050d 100644 --- a/cmd/argocd-applicationset-controller/commands/applicationset_controller.go +++ b/cmd/argocd-applicationset-controller/commands/applicationset_controller.go @@ -60,24 +60,28 @@ func NewCommand() *cobra.Command { Use: "controller", Short: "Starts Argo CD ApplicationSet controller", RunE: func(c *cobra.Command, args []string) error { + vers := common.GetVersion() + namespace, _, err := clientConfig.Namespace() + errors.CheckError(err) + vers.LogStartupInfo( + "ArgoCD ApplicationSet Controller", + map[string]any{ + "namespace": namespace, + }, + ) + restConfig, err := clientConfig.ClientConfig() if err != nil { return err } - vers := common.GetVersion() + restConfig.UserAgent = fmt.Sprintf("argocd-applicationset-controller/%s (%s)", vers.Version, vers.Platform) - if namespace == "" { - namespace, _, err = clientConfig.Namespace() - if err != nil { - return err - } - } + level, err := log.ParseLevel(logLevel) if err != nil { return err } log.SetLevel(level) - log.Info(fmt.Sprintf("ApplicationSet controller %s using namespace '%s' ", vers.Version, namespace), "namespace", namespace, "COMMIT_ID", vers.GitCommit) switch strings.ToLower(logFormat) { case "json": log.SetFormatter(&log.JSONFormatter{}) diff --git a/cmd/argocd-cmp-server/commands/argocd_cmp_server.go b/cmd/argocd-cmp-server/commands/argocd_cmp_server.go index f9efe9f5bdaf9..2ba46a153e1f2 100644 --- a/cmd/argocd-cmp-server/commands/argocd_cmp_server.go +++ b/cmd/argocd-cmp-server/commands/argocd_cmp_server.go @@ -34,6 +34,9 @@ func NewCommand() *cobra.Command { Long: "ArgoCD ConfigManagementPlugin Server is an internal service which runs as sidecar container in reposerver deployment. It can be configured by following options.", DisableAutoGenTag: true, RunE: func(c *cobra.Command, args []string) error { + vers := common.GetVersion() + vers.LogStartupInfo("ArgoCD ConfigManagementPlugin Server", nil) + cli.SetLogFormat(cmdutil.LogFormat) cli.SetLogLevel(cmdutil.LogLevel) diff --git a/cmd/argocd-dex/commands/argocd_dex.go b/cmd/argocd-dex/commands/argocd_dex.go index b8777fc483236..a706388fc02cf 100644 --- a/cmd/argocd-dex/commands/argocd_dex.go +++ b/cmd/argocd-dex/commands/argocd_dex.go @@ -51,16 +51,23 @@ func NewRunDexCommand() *cobra.Command { Use: "rundex", Short: "Runs dex generating a config using settings from the Argo CD configmap and secret", RunE: func(c *cobra.Command, args []string) error { + vers := common.GetVersion() + namespace, _, err := clientConfig.Namespace() + errors.CheckError(err) + vers.LogStartupInfo( + "ArgoCD Dex Server", + map[string]any{ + "namespace": namespace, + }, + ) + cli.SetLogFormat(cmdutil.LogFormat) cli.SetLogLevel(cmdutil.LogLevel) - _, err := exec.LookPath("dex") + _, err = exec.LookPath("dex") errors.CheckError(err) config, err := clientConfig.ClientConfig() errors.CheckError(err) - vers := common.GetVersion() config.UserAgent = fmt.Sprintf("argocd-dex/%s (%s)", vers.Version, vers.Platform) - namespace, _, err := clientConfig.Namespace() - errors.CheckError(err) kubeClientset := kubernetes.NewForConfigOrDie(config) settingsMgr := settings.NewSettingsManager(context.Background(), kubeClientset, namespace) diff --git a/cmd/argocd-notification/commands/controller.go b/cmd/argocd-notification/commands/controller.go index d5bd041cef6a7..4c4330d540410 100644 --- a/cmd/argocd-notification/commands/controller.go +++ b/cmd/argocd-notification/commands/controller.go @@ -9,6 +9,7 @@ import ( "github.com/argoproj/argo-cd/v2/common" + "github.com/argoproj/argo-cd/v2/util/errors" service "github.com/argoproj/argo-cd/v2/util/notification/argocd" notificationscontroller "github.com/argoproj/argo-cd/v2/notification_controller/controller" @@ -57,11 +58,20 @@ func NewCommand() *cobra.Command { Use: "controller", Short: "Starts Argo CD Notifications controller", RunE: func(c *cobra.Command, args []string) error { + vers := common.GetVersion() + namespace, _, err := clientConfig.Namespace() + errors.CheckError(err) + vers.LogStartupInfo( + "ArgoCD Notifications Controller", + map[string]any{ + "namespace": namespace, + }, + ) + restConfig, err := clientConfig.ClientConfig() if err != nil { return err } - vers := common.GetVersion() restConfig.UserAgent = fmt.Sprintf("argocd-notifications-controller/%s (%s)", vers.Version, vers.Platform) dynamicClient, err := dynamic.NewForConfig(restConfig) if err != nil { diff --git a/cmd/argocd-repo-server/commands/argocd_repo_server.go b/cmd/argocd-repo-server/commands/argocd_repo_server.go index 733db6764bbd2..3644151dc1dfa 100644 --- a/cmd/argocd-repo-server/commands/argocd_repo_server.go +++ b/cmd/argocd-repo-server/commands/argocd_repo_server.go @@ -88,6 +88,14 @@ func NewCommand() *cobra.Command { Long: "ArgoCD Repository Server is an internal service which maintains a local cache of the Git repository holding the application manifests, and is responsible for generating and returning the Kubernetes manifests. This command runs Repository Server in the foreground. It can be configured by following options.", DisableAutoGenTag: true, RunE: func(c *cobra.Command, args []string) error { + vers := common.GetVersion() + vers.LogStartupInfo( + "ArgoCD Repository Server", + map[string]any{ + "port": listenPort, + }, + ) + cli.SetLogFormat(cmdutil.LogFormat) cli.SetLogLevel(cmdutil.LogLevel) @@ -107,7 +115,7 @@ func NewCommand() *cobra.Command { metricsServer := metrics.NewMetricsServer() cacheutil.CollectMetrics(redisClient, metricsServer) server, err := reposerver.NewServer(metricsServer, cache, tlsConfigCustomizer, repository.RepoServerInitConstants{ - ParallelismLimit: parallelismLimit, + ParallelismLimit: parallelismLimit, PauseGenerationAfterFailedGenerationAttempts: getPauseGenerationAfterFailedGenerationAttempts(), PauseGenerationOnFailureForMinutes: getPauseGenerationOnFailureForMinutes(), PauseGenerationOnFailureForRequests: getPauseGenerationOnFailureForRequests(), @@ -169,7 +177,7 @@ func NewCommand() *cobra.Command { go func() { errors.CheckError(reposerver.StartGPGWatcher(getGnuPGSourcePath())) }() } - log.Infof("argocd-repo-server %s serving on %s", common.GetVersion(), listener.Addr()) + log.Infof("argocd-repo-server is listening on %s", listener.Addr()) stats.RegisterStackDumper() stats.StartStatsTicker(10 * time.Minute) stats.RegisterHeapDumper("memprofile") diff --git a/cmd/argocd-server/commands/argocd_server.go b/cmd/argocd-server/commands/argocd_server.go index a5d2f8c2efdbe..2c7b20a366880 100644 --- a/cmd/argocd-server/commands/argocd_server.go +++ b/cmd/argocd-server/commands/argocd_server.go @@ -74,6 +74,17 @@ func NewCommand() *cobra.Command { Long: "The API server is a gRPC/REST server which exposes the API consumed by the Web UI, CLI, and CI/CD systems. This command runs API server in the foreground. It can be configured by following options.", DisableAutoGenTag: true, Run: func(c *cobra.Command, args []string) { + vers := common.GetVersion() + namespace, _, err := clientConfig.Namespace() + errors.CheckError(err) + vers.LogStartupInfo( + "ArgoCD API Server", + map[string]any{ + "namespace": namespace, + "port": listenPort, + }, + ) + cli.SetLogFormat(cmdutil.LogFormat) cli.SetLogLevel(cmdutil.LogLevel) cli.SetGLogLevel(glogLevel) @@ -82,9 +93,6 @@ func NewCommand() *cobra.Command { errors.CheckError(err) errors.CheckError(v1alpha1.SetK8SConfigDefaults(config)) - namespace, _, err := clientConfig.Namespace() - errors.CheckError(err) - tlsConfigCustomizer, err := tlsConfigCustomizerSrc() errors.CheckError(err) cache, err := cacheSrc() @@ -95,7 +103,6 @@ func NewCommand() *cobra.Command { appclientsetConfig, err := clientConfig.ClientConfig() errors.CheckError(err) errors.CheckError(v1alpha1.SetK8SConfigDefaults(appclientsetConfig)) - vers := common.GetVersion() config.UserAgent = fmt.Sprintf("argocd-server/%s (%s)", vers.Version, vers.Platform) if failureRetryCount > 0 { diff --git a/common/version.go b/common/version.go index b06976877f9b2..8598f98c3171d 100644 --- a/common/version.go +++ b/common/version.go @@ -3,6 +3,8 @@ package common import ( "fmt" "runtime" + + log "github.com/sirupsen/logrus" ) // Version information set by link flags during build. We fall back to these sane @@ -33,6 +35,16 @@ func (v Version) String() string { return v.Version } +func (v Version) LogStartupInfo(componentName string, fields map[string]any) { + if fields == nil { + fields = map[string]any{} + } + fields["version"] = v.Version + fields["commit"] = v.GitCommit + fields["built"] = v.BuildDate + log.WithFields(log.Fields(fields)).Infof("%s is starting", componentName) +} + // GetVersion returns the version information func GetVersion() Version { var versionStr string