diff --git a/cmd/cc-metric-store/cli.go b/cmd/cc-metric-store/cli.go deleted file mode 100644 index 7e2f205..0000000 --- a/cmd/cc-metric-store/cli.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) NHR@FAU, University Erlangen-Nuremberg. -// All rights reserved. This file is part of cc-metric-store. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -// Package main provides the entry point for the ClusterCockpit metric store server. -// This file defines all command-line flags and their default values. -package main - -import "flag" - -var ( - flagGops, flagVersion, flagDev, flagLogDateTime bool - flagConfigFile, flagLogLevel string -) - -func cliInit() { - flag.BoolVar(&flagGops, "gops", false, "Listen via github.com/google/gops/agent (for debugging)") - flag.BoolVar(&flagDev, "dev", false, "Enable development component: Swagger UI") - flag.BoolVar(&flagVersion, "version", false, "Show version information and exit") - flag.BoolVar(&flagLogDateTime, "logdate", false, "Set this flag to add date and time to log messages") - flag.StringVar(&flagConfigFile, "config", "./config.json", "Specify alternative path to `config.json`") - flag.StringVar(&flagLogLevel, "loglevel", "warn", "Sets the logging level: `[debug, info, warn (default), err, crit]`") - flag.Parse() -} diff --git a/cmd/cc-metric-store/main.go b/cmd/cc-metric-store/main.go index 9a22ba1..9072ce2 100644 --- a/cmd/cc-metric-store/main.go +++ b/cmd/cc-metric-store/main.go @@ -7,6 +7,7 @@ package main import ( "context" + "flag" "fmt" "os" "os/signal" @@ -28,46 +29,17 @@ var ( version string ) +var ( + flagGops, flagVersion, flagDev, flagLogDateTime bool + flagConfigFile, flagLogLevel string +) + func printVersion() { fmt.Printf("Version:\t%s\n", version) fmt.Printf("Git hash:\t%s\n", commit) fmt.Printf("Build time:\t%s\n", date) } -func initGops() error { - if !flagGops && !config.Keys.Debug.EnableGops { - return nil - } - - if err := agent.Listen(agent.Options{}); err != nil { - return fmt.Errorf("starting gops agent: %w", err) - } - return nil -} - -func initConfiguration() error { - ccconf.Init(flagConfigFile) - - cfg := ccconf.GetPackageConfig("main") - if cfg == nil { - return fmt.Errorf("main configuration must be present") - } - - config.Init(cfg) - return nil -} - -func initSubsystems() error { - // Initialize nats client - natsConfig := ccconf.GetPackageConfig("nats") - if err := nats.Init(natsConfig); err != nil { - cclog.Warnf("initializing (optional) nats client: %s", err.Error()) - } - nats.Connect() - - return nil -} - func runServer(ctx context.Context) error { var wg sync.WaitGroup @@ -131,36 +103,42 @@ func runServer(ctx context.Context) error { } func run() error { - cliInit() + flag.BoolVar(&flagGops, "gops", false, "Listen via github.com/google/gops/agent (for debugging)") + flag.BoolVar(&flagDev, "dev", false, "Enable development component: Swagger UI") + flag.BoolVar(&flagVersion, "version", false, "Show version information and exit") + flag.BoolVar(&flagLogDateTime, "logdate", false, "Set this flag to add date and time to log messages") + flag.StringVar(&flagConfigFile, "config", "./config.json", "Specify alternative path to `config.json`") + flag.StringVar(&flagLogLevel, "loglevel", "warn", "Sets the logging level: `[debug, info, warn (default), err, crit]`") + flag.Parse() if flagVersion { printVersion() return nil } - // Initialize logger cclog.Init(flagLogLevel, flagLogDateTime) - // Initialize gops agent - if err := initGops(); err != nil { - return err + if flagGops || config.Keys.Debug.EnableGops { + if err := agent.Listen(agent.Options{}); err != nil { + return fmt.Errorf("starting gops agent: %w", err) + } } - // Initialize subsystems in dependency order: - // 1. Load configuration from config.json - // 2. Initialize subsystems like nats + ccconf.Init(flagConfigFile) - // Load configuration - if err := initConfiguration(); err != nil { - return err + cfg := ccconf.GetPackageConfig("main") + if cfg == nil { + return fmt.Errorf("main configuration must be present") } - // Initialize subsystems (nats, etc.) - if err := initSubsystems(); err != nil { - return err - } + config.Init(cfg) + + natsConfig := ccconf.GetPackageConfig("nats") + if err := nats.Init(natsConfig); err != nil { + cclog.Warnf("initializing (optional) nats client: %s", err.Error()) + } + nats.Connect() - // Run server with context ctx, cancel := context.WithCancel(context.Background()) defer cancel()