-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report FQDN on host.name enabled by a feature flag #34456
Changes from 1 commit
928bc15
49b89c4
3794a07
d1b5207
a6e6639
f234781
cf14a68
34f2b22
bd20db1
e7bec79
700952d
4976c23
e04d543
9dc4895
2c8cb44
50dc5b4
ab468d1
0aacfd7
57f2279
682e9fa
6f143e5
0b14c40
05279e5
1bb2211
4a9c251
3a2eac6
948e03f
0077053
e8a6249
d7cbd45
1cd2534
9ee01d4
8bf6ccf
d56f1f4
bc195d5
c2f9610
c634c52
f302f12
07427c6
0e1d221
a607532
fb2cbb3
08578e6
392e995
fce4ef4
cf2ad11
5a3981b
8b00241
63950dc
86b4618
444db78
e8fa727
1213ab3
db1a51f
4ff2c87
1af8780
d164036
c7ee641
7520fac
cd8f901
a7e4145
542d54a
70f654f
1a82458
4757a5a
77772ca
66a748c
fd09ab8
4444a16
4a4b223
b0e457f
920a61e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import ( | |
) | ||
|
||
var ( | ||
// flags configs | ||
mu sync.Mutex | ||
|
||
flags fflags | ||
|
@@ -20,42 +19,52 @@ type fflags struct { | |
fqdnEnabled bool | ||
} | ||
|
||
// type configs struct { | ||
// FQDN struct { | ||
// Enabled bool `json:"enabled" yaml:"enabled" config:"enabled"` | ||
// } `json:"fqdn" yaml:"fqdn" config:"fqdn"` | ||
// } | ||
func UpdateFromProto(f *proto.Features) { | ||
logp.L().Info("features.UpdateFromProto invoked") | ||
|
||
func Update(f *proto.Features) { | ||
if f == nil { | ||
logp.L().Info("feature flag proto is nil!") | ||
return | ||
} | ||
|
||
mu.Lock() | ||
defer mu.Unlock() | ||
flags = fflags{fqdnEnabled: f.Fqdn.Enabled} | ||
|
||
logp.L().Infof("features.UpdateFromProto: fqdn: %t", flags.fqdnEnabled) | ||
} | ||
|
||
func Parse(c *conf.C) error { | ||
logp.L().Info("features.Parse invoked") | ||
func ParseFromConfig(c *conf.C) error { | ||
logp.L().Info("features.ParseFromConfig invoked") | ||
if c == nil { | ||
logp.L().Info("feature flag config is nil!") | ||
return nil | ||
} | ||
|
||
enabled, err := c.Bool("features.fqdn.enabled", -1) | ||
if err != nil { | ||
return fmt.Errorf("could not FQDN feature config: %w", err) | ||
type cfg struct { | ||
Features struct { | ||
FQDN *conf.C `json:"fqdn" yaml:"fqdn" config:"fqdn"` | ||
} `json:"features" yaml:"features" config:"features"` | ||
} | ||
|
||
parsedFlags := cfg{} | ||
if err := c.Unpack(&parsedFlags); err != nil { | ||
logp.L().Errorf("could not Unpack features config: %v", err) | ||
|
||
return fmt.Errorf("could not Unpack features config: %w", err) | ||
} | ||
|
||
mu.Lock() | ||
defer mu.Unlock() | ||
flags.fqdnEnabled = enabled | ||
flags.fqdnEnabled = parsedFlags.Features.FQDN.Enabled() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we hit nil ref with FQDN or features? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't hit a nil ref with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, if So I think we're good here? Or do you think we should add a guard anyway? |
||
|
||
logp.L().Infof("features.ParseFromConfig: fqdn: %t", flags.fqdnEnabled) | ||
|
||
return nil | ||
} | ||
|
||
// FQDN reports if FQDN should be used instead of hostname for host.name. | ||
// If it hasn't been set by ParseFromConfig or UpdateFromProto, it returns false. | ||
func FQDN() bool { | ||
return flags.fqdnEnabled | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,72 @@ | ||
package features | ||
|
||
// const configYAML = ` | ||
// features: | ||
// fqdn: | ||
// enabled: true | ||
// ` | ||
// | ||
// func TestParse(t *testing.T) { | ||
// c, err := config.NewConfigFrom(configYAML) | ||
// if err != nil { | ||
// t.Fatalf("could not parse config YAML: %v", err) | ||
// } | ||
// | ||
// err = Parse(c) | ||
// if err != nil { | ||
// t.Fatalf("Parse failed: %v", err) | ||
// } | ||
// } | ||
import ( | ||
"testing" | ||
|
||
"github.com/elastic/elastic-agent-libs/config" | ||
) | ||
|
||
func TestFQDN(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
yaml string | ||
want bool | ||
}{ | ||
{ | ||
name: "FQDN enabled", | ||
yaml: ` | ||
features: | ||
fqdn: | ||
enabled: true`, | ||
want: true, | ||
}, | ||
{ | ||
name: "FQDN disabled", | ||
yaml: ` | ||
features: | ||
fqdn: | ||
enabled: false`, | ||
want: false, | ||
}, | ||
{ | ||
name: "FQDN only {}", | ||
yaml: ` | ||
features: | ||
fqdn: {}`, | ||
want: true, | ||
}, | ||
{ | ||
name: "FQDN empty", | ||
yaml: ` | ||
features: | ||
fqdn:`, | ||
want: false, | ||
}, | ||
{ | ||
name: "FQDN absent", | ||
yaml: ` | ||
features:`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please test config without features There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a case for this. |
||
want: false, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
|
||
c, err := config.NewConfigFrom(tc.yaml) | ||
if err != nil { | ||
t.Fatalf("could not parse config YAML: %v", err) | ||
} | ||
|
||
err = ParseFromConfig(c) | ||
if err != nil { | ||
t.Fatalf("ParseFromConfig failed: %v", err) | ||
} | ||
|
||
got := FQDN() | ||
if got != tc.want { | ||
t.Errorf("want: %t, got %t", tc.want, got) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: s/Unpack/unpack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.