-
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
[Heartbeat] Refactor config system #23467
Changes from 43 commits
6a0b645
2c48c55
1ab0fd6
168c6a0
e94fe34
a6581ba
3ba5203
d5aacfe
3e47422
f7971f4
fd4d03d
d27f695
47320ce
7c05aa6
367548c
70f5281
3c66ed1
a96277f
44628b0
75250bb
54eff79
c57c81e
9b9f6b1
1c10922
faac3c9
100dead
5c7d981
0956aff
d587a67
8554370
8081b1c
2332b13
fde5765
c82c155
24ced05
95d695d
ebcfb03
34469bf
8ed3ad1
4002755
b7c8d19
6e1a49b
3c47a5c
4d8c07b
8248900
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ import ( | |
"net" | ||
"net/url" | ||
|
||
"github.com/elastic/beats/v7/heartbeat/monitors/plugin" | ||
|
||
"github.com/elastic/beats/v7/heartbeat/eventext" | ||
"github.com/elastic/beats/v7/heartbeat/look" | ||
"github.com/elastic/beats/v7/heartbeat/monitors" | ||
|
@@ -35,30 +37,29 @@ import ( | |
var debugf = logp.MakeDebug("icmp") | ||
|
||
func init() { | ||
monitors.RegisterActive("icmp", create) | ||
monitors.RegisterActive("synthetics/icmp", create) | ||
plugin.Register("icmp", create, "synthetics/icmp") | ||
} | ||
|
||
func create( | ||
name string, | ||
commonConfig *common.Config, | ||
) (jobs []jobs.Job, endpoints int, err error) { | ||
) (p plugin.Plugin, err error) { | ||
loop, err := getStdLoop() | ||
if err != nil { | ||
logp.Warn("Failed to initialize ICMP loop %v", err) | ||
return nil, 0, err | ||
return plugin.Plugin{}, err | ||
} | ||
|
||
config := DefaultConfig | ||
if err := commonConfig.Unpack(&config); err != nil { | ||
return nil, 0, err | ||
return plugin.Plugin{}, err | ||
} | ||
|
||
jf, err := newJobFactory(config, monitors.NewStdResolver(), loop) | ||
if err != nil { | ||
return nil, 0, err | ||
return plugin.Plugin{}, err | ||
} | ||
return jf.makeJobs() | ||
return jf.makePlugin() | ||
|
||
} | ||
|
||
|
@@ -89,29 +90,30 @@ func (jf *jobFactory) checkConfig() error { | |
return nil | ||
} | ||
|
||
func (jf *jobFactory) makeJobs() (j []jobs.Job, endpoints int, err error) { | ||
func (jf *jobFactory) makePlugin() (plugin2 plugin.Plugin, err error) { | ||
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. Why the names returned parameters? Seems that the code always defines the return in the statement of the function. |
||
if err := jf.loop.checkNetworkMode(jf.ipVersion); err != nil { | ||
return nil, 0, err | ||
return plugin.Plugin{}, err | ||
} | ||
|
||
pingFactory := jf.pingIPFactory(&jf.config) | ||
|
||
var j []jobs.Job | ||
for _, host := range jf.config.Hosts { | ||
job, err := monitors.MakeByHostJob(host, jf.config.Mode, monitors.NewStdResolver(), pingFactory) | ||
|
||
if err != nil { | ||
return nil, 0, err | ||
return plugin.Plugin{}, err | ||
} | ||
|
||
u, err := url.Parse(fmt.Sprintf("icmp://%s", host)) | ||
if err != nil { | ||
return nil, 0, err | ||
return plugin.Plugin{}, err | ||
} | ||
|
||
j = append(j, wrappers.WithURLField(u, job)) | ||
} | ||
|
||
return j, len(jf.config.Hosts), nil | ||
return plugin.Plugin{Jobs: j, Close: nil, Endpoints: len(jf.config.Hosts)}, nil | ||
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. Instead of having the caller know if Or add a 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. Will do in a follow-up! |
||
} | ||
|
||
func (jf *jobFactory) pingIPFactory(config *Config) func(*net.IPAddr) jobs.Job { | ||
|
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.
I think this can be change to
RunMonitors
, seems that there is only one type of monitor at this level of the code.