Skip to content

Commit

Permalink
Merge branch 'master' into go-1.16.4
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-laterman committed May 26, 2021
2 parents 5fef088 + 242e2bd commit c475b9a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ VERSION=${DEFAULT_VERSION}
endif

PLATFORM_TARGETS=$(addprefix release-, $(PLATFORMS))
LDFLAGS=-w -s -X main.Version=${VERSION}
COMMIT=$(shell git rev-parse --short HEAD)
LDFLAGS=-w -s -X main.Version=${VERSION} -X main.Commit=${COMMIT}
CMD_COLOR_ON=\033[32m\xE2\x9c\x93
CMD_COLOR_OFF=\033[0m

Expand Down
29 changes: 24 additions & 5 deletions cmd/fleet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,26 @@ func makeCache(cfg *config.Config) (cache.Cache, error) {
return cache.New(cacheCfg)
}

func getRunCommand(version string) func(cmd *cobra.Command, args []string) error {
func initLogger(cfg *config.Config, version, commit string) (*logger.Logger, error) {
l, err := logger.Init(cfg)
if err != nil {
return nil, err
}

log.Info().
Str("version", version).
Str("commit", commit).
Int("pid", os.Getpid()).
Int("ppid", os.Getppid()).
Str("exe", os.Args[0]).
Strs("args", os.Args[1:]).
Msg("boot")
log.Debug().Strs("env", os.Environ()).Msg("environment")

return l, err
}

func getRunCommand(version, commit string) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
cfgObject := cmd.Flags().Lookup("E").Value.(*config.Flag)
cliCfg := cfgObject.Config()
Expand All @@ -85,7 +104,7 @@ func getRunCommand(version string) func(cmd *cobra.Command, args []string) error
if err != nil {
return err
}
l, err = logger.Init(cfg)
l, err = initLogger(cfg, version, commit)
if err != nil {
return err
}
Expand Down Expand Up @@ -119,7 +138,7 @@ func getRunCommand(version string) func(cmd *cobra.Command, args []string) error
return err
}

l, err = logger.Init(cfg)
l, err = initLogger(cfg, version, commit)
if err != nil {
return err
}
Expand Down Expand Up @@ -147,11 +166,11 @@ func getRunCommand(version string) func(cmd *cobra.Command, args []string) error
}
}

func NewCommand(version string) *cobra.Command {
func NewCommand(version, commit string) *cobra.Command {
cmd := &cobra.Command{
Use: "fleet-server",
Short: "Fleet Server controls a fleet of Elastic Agents",
RunE: getRunCommand(version),
RunE: getRunCommand(version, commit),
}
cmd.Flags().StringP("config", "c", "fleet-server.yml", "Configuration for Fleet Server")
cmd.Flags().Bool(kAgentMode, false, "Running under execution of the Elastic Agent")
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/integration/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ELASTICSEARCH_VERSION=8.0.0-bd957996-SNAPSHOT
ELASTICSEARCH_VERSION=8.0.0-5197c308-SNAPSHOT
ELASTICSEARCH_USERNAME=elastic
ELASTICSEARCH_PASSWORD=changeme
TEST_ELASTICSEARCH_HOSTS=localhost:9200
4 changes: 3 additions & 1 deletion internal/pkg/apikey/invalidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
func Invalidate(ctx context.Context, client *elasticsearch.Client, ids ...string) error {

payload := struct {
IDs []string `json:"ids,omitempty"`
IDs []string `json:"ids,omitempty"`
Owner bool `json:"owner"`
}{
ids,
true,
}

body, err := json.Marshal(&payload)
Expand Down
8 changes: 0 additions & 8 deletions internal/pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ func Init(cfg *config.Config) (*Logger, error) {
if !cfg.Logging.Pretty || !cfg.Logging.ToStderr {
zerolog.TimestampFunc = func() time.Time { return time.Now().UTC() }
}

log.Info().
Int("pid", os.Getpid()).
Int("ppid", os.Getppid()).
Str("exe", os.Args[0]).
Strs("args", os.Args[1:]).
Msg("boot")
log.Debug().Strs("env", os.Environ()).Msg("environment")
})
return gLogger, err
}
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ const defaultVersion = "8.0.0"

var (
Version string = defaultVersion
Commit string
)

func main() {
cmd := fleet.NewCommand(Version)
cmd := fleet.NewCommand(Version, Commit)
if err := cmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down

0 comments on commit c475b9a

Please sign in to comment.