Skip to content

Commit c22d281

Browse files
Deprecate fleet.agent.logging.level attribute (#3195)
Deprecate the fleet.agent.logging.level attribute and rely on the top level logging.* attributes instead. Add a unit test to make sure that command line overrides are respected.
1 parent 9f4de48 commit c22d281

File tree

7 files changed

+99
-12
lines changed

7 files changed

+99
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: deprecate fleet.agent.logging.level
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
description: |
20+
Deprecate the fleet.agent.logging.level attribute and rely only on the
21+
top level logging.* attributes to control fleet-server logging. Add a
22+
unit test to ensure logging flags are parsed correctly.
23+
24+
# Affected component; a word indicating the component this changeset affects.
25+
component:
26+
27+
# PR URL; optional; the PR number that added the changeset.
28+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
29+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
30+
# Please provide it if you are adding a fragment for a different PR.
31+
#pr: https://github.com/owner/repo/1234
32+
33+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
34+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
35+
issue: 3126

cmd/fleet/flag_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package fleet
6+
7+
import (
8+
"strings"
9+
"testing"
10+
11+
"github.com/elastic/fleet-server/v7/internal/pkg/build"
12+
"github.com/elastic/fleet-server/v7/internal/pkg/config"
13+
14+
"github.com/stretchr/testify/require"
15+
)
16+
17+
func TestAgentModeFlag(t *testing.T) {
18+
tests := []struct {
19+
name string
20+
flags []string
21+
expect func() *config.Config
22+
}{{
23+
name: "no flags",
24+
flags: []string{},
25+
expect: func() *config.Config {
26+
cfg := &config.Config{}
27+
cfg.InitDefaults()
28+
cfg.Output.Elasticsearch.InitDefaults() // NOTE this is implicitly called when ucfg parses the top level cfg object, but we need to explicitly call it for testing.
29+
return cfg
30+
},
31+
}, {
32+
name: "debug log flag",
33+
flags: []string{"E logging.level=debug"}, // flag is the k:v separated by a space, key does not have the "-" prefix
34+
expect: func() *config.Config {
35+
cfg := &config.Config{}
36+
cfg.InitDefaults()
37+
cfg.Output.Elasticsearch.InitDefaults()
38+
cfg.Logging.Level = "debug"
39+
return cfg
40+
},
41+
}}
42+
43+
for _, tc := range tests {
44+
t.Run(tc.name, func(t *testing.T) {
45+
cmd := NewCommand(build.Info{})
46+
for _, flag := range tc.flags {
47+
arr := strings.Split(flag, " ")
48+
err := cmd.Flags().Set(arr[0], arr[1])
49+
require.NoError(t, err)
50+
}
51+
52+
cfgObj := cmd.Flags().Lookup("E").Value.(*config.Flag) //nolint:errcheck // same as in main
53+
cfgCLI := cfgObj.Config()
54+
cfg, err := config.FromConfig(cfgCLI)
55+
require.NoError(t, err)
56+
require.Equal(t, tc.expect(), cfg)
57+
})
58+
}
59+
}

fleet-server.reference.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ fleet:
5050
id: fleet-server-agent-idv
5151
# # version is the version of the elastic-agent instance
5252
# version:
53-
# # agent logging level may also be specified in top level logging config
53+
# # specify logging level
54+
# # deprecated: Use the top level logging.* attributes instead.
5455
# logging.level: info
5556
# host:
5657
# id:

internal/pkg/config/fleet.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import (
1111
"github.com/rs/zerolog"
1212
)
1313

14-
const defaultLevel = "info"
15-
1614
// AgentLogging is the log level set on the Agent.
15+
// deprectated: Use top level `logging.*` attributes instead.
1716
type AgentLogging struct {
1817
Level string `config:"level"`
1918
}

internal/pkg/config/logging.go

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/rs/zerolog"
1212
)
1313

14+
const defaultLevel = "info"
15+
1416
// LoggingFiles configuration for the logging file output.
1517
type LoggingFiles struct {
1618
Path string `config:"path"`

internal/pkg/logger/logger.go

-6
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,10 @@ func Init(cfg *config.Config, svcName string) (*Logger, error) {
101101
}
102102

103103
func levelChanged(cfg *config.Config) bool {
104-
if cfg.Fleet.Agent.Logging.LogLevel() != zerolog.GlobalLevel() {
105-
return true
106-
}
107104
return level(cfg) != zerolog.GlobalLevel()
108105
}
109106

110107
func level(cfg *config.Config) zerolog.Level {
111-
if cfg.Fleet.Agent.Logging.Level != "" {
112-
return cfg.Fleet.Agent.Logging.LogLevel()
113-
}
114108
return cfg.Logging.LogLevel()
115109
}
116110

internal/pkg/server/agent.go

-3
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,6 @@ func (a *Agent) configFromUnits() (*config.Config, error) {
404404
"agent": map[string]interface{}{
405405
"id": agentID,
406406
"version": agentVersion,
407-
"logging": map[string]interface{}{
408-
"level": logLevel.String(),
409-
},
410407
},
411408
},
412409
"output": map[string]interface{}{

0 commit comments

Comments
 (0)