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

[NDMII-3310] add support for HA integrations #33828

Closed
Show file tree
Hide file tree
Changes from 7 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ func (c *CheckWrapper) GetDiagnoses() ([]diagnosis.Diagnosis, error) {
func (c *CheckWrapper) IsHAEnabled() bool {
return c.inner.IsHAEnabled()
}

// IsHASupported implements Check#IsHASupported
func (c *CheckWrapper) IsHASupported() bool {
return c.inner.IsHASupported()
}
2 changes: 2 additions & 0 deletions pkg/collector/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type Check interface {
GetDiagnoses() ([]diagnosis.Diagnosis, error)
// IsHAEnabled returns if High Availability is enabled for this check
IsHAEnabled() bool
// IsHASupported returns if the check is compatible with High Availability
IsHASupported() bool
Copy link
Contributor

Choose a reason for hiding this comment

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

CheckWrapper#IsHASupported is the only place where this interface method is called. Since we don't call anywhere useful, this can be safely removed.

}

// Info is an interface to pull information from types capable to run checks. This is a subsection from the Check
Expand Down
3 changes: 3 additions & 0 deletions pkg/collector/check/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ func (c *StubCheck) GetDiagnoses() ([]diagnosis.Diagnosis, error) { return nil,

// IsHAEnabled returns false
func (c *StubCheck) IsHAEnabled() bool { return false }

// IsHASupported returns false
func (c *StubCheck) IsHASupported() bool { return false }
8 changes: 8 additions & 0 deletions pkg/collector/corechecks/checkbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (c *CheckBase) CommonConfigure(senderManager sender.SenderManager, initConf

if commonOptions.HAEnabled != nil {
c.haEnabled = *commonOptions.HAEnabled
if c.haEnabled && !c.IsHASupported() {
return fmt.Errorf("High Availability is enabled for check %s but this integration does not support it", string(c.ID()))
}
}

c.source = source
Expand Down Expand Up @@ -295,3 +298,8 @@ func (c *CheckBase) GetDiagnoses() ([]diagnosis.Diagnosis, error) {
func (c *CheckBase) IsHAEnabled() bool {
return c.haEnabled
}

// IsHASupported returns if the check is compatible with High Availability
func (c *CheckBase) IsHASupported() bool {
return false
Copy link
Contributor

Choose a reason for hiding this comment

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

How checks would opt-in? Since go doesn't support virtual methods, CommonConfigure will always call this exact implementation, and will always get false.

}
20 changes: 20 additions & 0 deletions pkg/collector/corechecks/checkbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ foo_init: bar_init
min_collection_interval: 60
empty_default_hostname: true
name: foobar
`
haConfig = `
foo_init: bar_init
ha_enabled: true
`
)

Expand Down Expand Up @@ -68,3 +72,19 @@ func TestCommonConfigureCustomID(t *testing.T) {
assert.Equal(t, string(mycheck.ID()), "test:foobar:a934df33209f45f4")
mockSender.AssertExpectations(t)
}

func TestCommonConfigureNotHASupported(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please also add a test that a check can actually opt-in?

checkName := "test"
mycheck := &dummyCheck{
CheckBase: NewCheckBase(checkName),
}
mockSender := mocksender.NewMockSender(mycheck.ID())

err := mycheck.CommonConfigure(mockSender.GetSenderManager(), nil, []byte(haConfig), "test")
assert.Error(t, err)
assert.Contains(t, err.Error(), "High Availability is enabled for check test but this integration does not support it")

err = mycheck.CommonConfigure(mockSender.GetSenderManager(), []byte(haConfig), nil, "test")
assert.Error(t, err)
assert.Contains(t, err.Error(), "High Availability is enabled for check test but this integration does not support it")
}
5 changes: 5 additions & 0 deletions pkg/collector/corechecks/embed/apm/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ func (c *APMCheck) IsHAEnabled() bool {
return false
}

// IsHASupported returns if the check is compatible with High Availability
func (c *APMCheck) IsHASupported() bool {
return false
}

// Factory creates a new check factory
func Factory() option.Option[func() check.Check] {
return option.New(newCheck)
Expand Down
5 changes: 5 additions & 0 deletions pkg/collector/corechecks/embed/process/process_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ func (c *ProcessAgentCheck) IsHAEnabled() bool {
return false
}

// IsHASupported returns if the check is compatible with High Availability
func (c *ProcessAgentCheck) IsHASupported() bool {
return false
}

// Factory creates a new check factory
func Factory() option.Option[func() check.Check] {
return option.New(newCheck)
Expand Down
5 changes: 5 additions & 0 deletions pkg/collector/corechecks/longrunning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (m *mockLongRunningCheck) IsHAEnabled() bool {
return args.Bool(0)
}

func (m *mockLongRunningCheck) IsHASupported() bool {
args := m.Called()
return args.Bool(0)
}

func (m *mockLongRunningCheck) GetSender() (sender.Sender, error) {
args := m.Called()
s := args.Get(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ func (c *CiscoSdwanCheck) Interval() time.Duration {
return c.interval
}

// IsHASupported returns true if the check supports HA
func (c *CiscoSdwanCheck) IsHASupported() bool {
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

Could not configure check cisco_sdwan: High Availability is enabled for check cisco_sdwan:2a628ec07bc21842 but this integration does not support it

}

func boolPointer(b bool) *bool {
return &b
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/collector/corechecks/networkpath/networkpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func (c *Check) Configure(senderManager sender.SenderManager, integrationConfigD
return nil
}

// IsHASupported returns true if the check supports HA
func (c *Check) IsHASupported() bool {
return true
}

// Factory creates a new check factory
func Factory(telemetry telemetryComp.Component) option.Option[func() check.Check] {
return option.New(func() check.Check {
Expand Down
5 changes: 5 additions & 0 deletions pkg/collector/corechecks/snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func (c *Check) GetDiagnoses() ([]diagnosis.Diagnosis, error) {
return c.singleDeviceCk.GetDiagnoses(), nil
}

// IsHASupported returns true if the check supports HA
func (c *Check) IsHASupported() bool {
return true
}

// Factory creates a new check factory
func Factory(agentConfig config.Component) option.Option[func() check.Check] {
return option.New(func() check.Check {
Expand Down
7 changes: 7 additions & 0 deletions pkg/collector/python/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ func (c *PythonCheck) IsHAEnabled() bool {
return c.haEnabled
}

// IsHASupported is actually not used, the HA Supported is defined at Python Check level as a class attribute
// An exception is raised if a non HA Supported check is configured with ha_enabled config in the __init__ method of the AgentCheck class
// https://github.com/DataDog/integrations-core/blob/master/datadog_checks_base/datadog_checks/base/checks/base.py#L98
func (c *PythonCheck) IsHASupported() bool {
return false
}

// pythonCheckFinalizer is a finalizer that decreases the reference count on the PyObject refs owned
// by the PythonCheck.
func pythonCheckFinalizer(c *PythonCheck) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/jmxfetch/jmxfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ type checkInstanceCfg struct {
JavaOptions string `yaml:"java_options,omitempty"`
ToolsJarPath string `yaml:"tools_jar_path,omitempty"`
ProcessNameRegex string `yaml:"process_name_regex,omitempty"`
HAEnabled bool `yaml:"ha_enabled,omitempty"`
}

type checkInitCfg struct {
CustomJarPaths []string `yaml:"custom_jar_paths,omitempty"`
ToolsJarPath string `yaml:"tools_jar_path,omitempty"`
JavaBinPath string `yaml:"java_bin_path,omitempty"`
JavaOptions string `yaml:"java_options,omitempty"`
HAEnabled bool `yaml:"ha_enabled,omitempty"`
}

func NewJMXFetch(logger jmxlogger.Component) *JMXFetch {
Expand Down Expand Up @@ -478,6 +480,9 @@ func (j *JMXFetch) ConfigureFromInitConfig(initConfig integration.Data) error {
j.JavaCustomJarPaths = initConf.CustomJarPaths
}
}
if initConf.HAEnabled {
return fmt.Errorf("High Availability is not supported in JMX integrations")
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to propagate to agent status the same way that other integrations report this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems that no configuration errors in jmx integrations appears in the status 🤔
https://github.com/DataDog/datadog-agent/blob/jed/flag-integrations-ha-compatible/pkg/jmxfetch/scheduler.go#L59-L62

}

return nil
}
Expand Down Expand Up @@ -508,6 +513,9 @@ func (j *JMXFetch) ConfigureFromInstance(instance integration.Data) error {
j.JavaToolsJarPath = instanceConf.ToolsJarPath
}
}
if instanceConf.HAEnabled {
return fmt.Errorf("High Availability is not supported in JMX integrations")
}

return nil
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/jmxfetch/jmxfetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,18 @@ func TestConflictingInstanceInitJavaOptions(t *testing.T) {
require.Contains(t, j.JavaOptions, "Xmx200m")
require.NotContains(t, j.JavaOptions, "Xmx444m")
}

func TestCheckHAIsNotSupported(t *testing.T) {
j := NewJMXFetch(nil)

var configOne integration.Data = integration.Data("{\"ha_enabled\": true}")
var configTwo integration.Data = integration.Data("{\"ha_enabled\": true}")

err := j.ConfigureFromInitConfig(configOne)
require.Error(t, err)
require.Contains(t, err.Error(), "High Availability is not supported in JMX integrations")

err = j.ConfigureFromInstance(configTwo)
require.Error(t, err)
require.Contains(t, err.Error(), "High Availability is not supported in JMX integrations")
}
Loading