Skip to content

Commit

Permalink
feat: implement consistent startup messages for all components (#9800)
Browse files Browse the repository at this point in the history
* feat: implement consistent startup messages for all components

Signed-off-by: Kent <[email protected]>

* DRY up previous commit

Signed-off-by: Kent <[email protected]>
  • Loading branch information
krancour authored Jun 28, 2022
1 parent 202001a commit b524769
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,28 @@ 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)

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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
3 changes: 3 additions & 0 deletions cmd/argocd-cmp-server/commands/argocd_cmp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 11 additions & 4 deletions cmd/argocd-dex/commands/argocd_dex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion cmd/argocd-notification/commands/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 10 additions & 2 deletions cmd/argocd-repo-server/commands/argocd_repo_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(),
Expand Down Expand Up @@ -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")
Expand Down
15 changes: 11 additions & 4 deletions cmd/argocd-server/commands/argocd_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b524769

Please sign in to comment.