Skip to content
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

Integrations always running regardless of enabled flag #689

Merged
merged 17 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ func main() {
if cfg != nil {
cfg.Server.Log = cfgLogger
}
// Iterate over the configurations and remove any that Enabled = false, this works by setting i to the last element
// and then returning the array minus the last element. This loses order but is performant.
for i := 0; i < len(cfg.Integrations.Integrations);{
if !cfg.Integrations.Integrations[i].CommonConfig().Enabled {
cfg.Integrations.Integrations[i] = cfg.Integrations.Integrations[len(cfg.Integrations.Integrations)-1]
cfg.Integrations.Integrations = cfg.Integrations.Integrations[:len(cfg.Integrations.Integrations)-1]
} else {
i++
}
}

return cfg, err
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/integrations/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ func (m *Manager) ApplyConfig(cfg ManagerConfig) error {
// No-op
}

// Before applying any configurations, remove them from the array if enabled = false

// Iterate over our integrations. New or changed integrations will be
// started, with their existing counterparts being shut down.
for _, ic := range cfg.Integrations {
Expand All @@ -220,9 +222,14 @@ func (m *Manager) ApplyConfig(cfg ManagerConfig) error {
continue
}
p.stop()
m.im.DeleteConfig(key)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beforehand the scraper was not stopping, but the integration was.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following how this is necessary, the second loop should be deleting the config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the addition of the enabled check around line 227 the integration process is not started so the integration isn't added to the to m.integrations.

delete(m.integrations, key)
}

if !ic.CommonConfig().Enabled {
continue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think a function to return a slice of enabled integrations would be easier to follow than having to maintain this check across the two loops, IMO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need the integrations in the array to disable/remove them, ie going from enabled -> disabled on reload.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is in here twice :)


l := log.With(m.logger, "integration", ic.Name())
i, err := ic.NewIntegration(l)
if err != nil {
Expand Down Expand Up @@ -258,6 +265,10 @@ func (m *Manager) ApplyConfig(cfg ManagerConfig) error {
foundConfig := false
for _, ic := range cfg.Integrations {
if integrationKey(ic.Name()) == key {
// If this is disabled then we should delete from integrations
if !ic.CommonConfig().Enabled {
break
}
foundConfig = true
break
}
Expand All @@ -268,6 +279,7 @@ func (m *Manager) ApplyConfig(cfg ManagerConfig) error {

_ = m.im.DeleteConfig(key)
process.stop()
m.im.DeleteConfig(key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to call this twice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all and removed.

delete(m.integrations, key)
}

Expand Down