diff --git a/x-pack/elastic-agent/pkg/agent/application/noop_status_controller.go b/x-pack/elastic-agent/pkg/agent/application/noop_status_controller.go index 9fc189575bf..b229f3cff08 100644 --- a/x-pack/elastic-agent/pkg/agent/application/noop_status_controller.go +++ b/x-pack/elastic-agent/pkg/agent/application/noop_status_controller.go @@ -11,8 +11,10 @@ import ( type noopController struct{} -func (*noopController) RegisterComponent(_ string) status.Reporter { return &noopReporter{} } -func (*noopController) RegisterComponentWithPersistance(_ string, _ bool) status.Reporter { return &noopReporter{} } +func (*noopController) RegisterComponent(_ string) status.Reporter { return &noopReporter{} } +func (*noopController) RegisterComponentWithPersistance(_ string, _ bool) status.Reporter { + return &noopReporter{} +} func (*noopController) RegisterApp(_ string, _ string) status.Reporter { return &noopReporter{} } func (*noopController) Status() status.AgentStatus { return status.AgentStatus{Status: status.Healthy} } func (*noopController) StatusCode() status.AgentStatusCode { return status.Healthy } diff --git a/x-pack/elastic-agent/pkg/capabilities/capabilities.go b/x-pack/elastic-agent/pkg/capabilities/capabilities.go index efafa4b654c..b03bef73d8c 100644 --- a/x-pack/elastic-agent/pkg/capabilities/capabilities.go +++ b/x-pack/elastic-agent/pkg/capabilities/capabilities.go @@ -8,6 +8,8 @@ import ( "errors" "os" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/state" + "gopkg.in/yaml.v2" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" @@ -85,7 +87,7 @@ func Load(capsFile string, log *logger.Logger, sc status.Controller) (Capability func (mgr *capabilitiesManager) Apply(in interface{}) (interface{}, error) { var err error // reset health on start, child caps will update to fail if needed - mgr.reporter.Update(status.Healthy) + mgr.reporter.Update(state.Healthy, "") for _, cap := range mgr.caps { in, err = cap.Apply(in) if err != nil { diff --git a/x-pack/elastic-agent/pkg/capabilities/capabilities_test.go b/x-pack/elastic-agent/pkg/capabilities/capabilities_test.go index d59b7c62939..46107463151 100644 --- a/x-pack/elastic-agent/pkg/capabilities/capabilities_test.go +++ b/x-pack/elastic-agent/pkg/capabilities/capabilities_test.go @@ -135,7 +135,7 @@ func TestCapabilityManager(t *testing.T) { caps: []Capability{ filterKeywordCap{keyWord: "filter"}, }, - reporter: status.NewController(l).Register("test"), + reporter: status.NewController(l).RegisterComponent("test"), } newIn, err := mgr.Apply(m) @@ -160,7 +160,7 @@ func TestCapabilityManager(t *testing.T) { filterKeywordCap{keyWord: "filter"}, blockCap{}, }, - reporter: status.NewController(l).Register("test"), + reporter: status.NewController(l).RegisterComponent("test"), } newIn, err := mgr.Apply(m) @@ -185,7 +185,7 @@ func TestCapabilityManager(t *testing.T) { filterKeywordCap{keyWord: "filter"}, blockCap{}, }, - reporter: status.NewController(l).Register("test"), + reporter: status.NewController(l).RegisterComponent("test"), } newIn, err := mgr.Apply(m) @@ -210,7 +210,7 @@ func TestCapabilityManager(t *testing.T) { filterKeywordCap{keyWord: "filter"}, keepAsIsCap{}, }, - reporter: status.NewController(l).Register("test"), + reporter: status.NewController(l).RegisterComponent("test"), } newIn, err := mgr.Apply(m) @@ -235,7 +235,7 @@ func TestCapabilityManager(t *testing.T) { filterKeywordCap{keyWord: "filter"}, keepAsIsCap{}, }, - reporter: status.NewController(l).Register("test"), + reporter: status.NewController(l).RegisterComponent("test"), } newIn, err := mgr.Apply(m) @@ -260,7 +260,7 @@ func TestCapabilityManager(t *testing.T) { filterKeywordCap{keyWord: "filter"}, filterKeywordCap{keyWord: "key"}, }, - reporter: status.NewController(l).Register("test"), + reporter: status.NewController(l).RegisterComponent("test"), } newIn, err := mgr.Apply(m) @@ -283,7 +283,7 @@ func TestCapabilityManager(t *testing.T) { filterKeywordCap{keyWord: "key"}, filterKeywordCap{keyWord: "filter"}, }, - reporter: status.NewController(l).Register("test"), + reporter: status.NewController(l).RegisterComponent("test"), } newIn, err := mgr.Apply(m) diff --git a/x-pack/elastic-agent/pkg/capabilities/input.go b/x-pack/elastic-agent/pkg/capabilities/input.go index 7ddc1a22496..6515bd5b715 100644 --- a/x-pack/elastic-agent/pkg/capabilities/input.go +++ b/x-pack/elastic-agent/pkg/capabilities/input.go @@ -7,6 +7,8 @@ package capabilities import ( "fmt" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/state" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/transpiler" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" @@ -150,8 +152,9 @@ func (c *inputCapability) renderInputs(inputs []map[string]interface{}) ([]map[s input[conditionKey] = isSupported if !isSupported { - c.log.Errorf("input '%s' is left out due to capability restriction '%s'", inputType, c.name()) - c.reporter.Update(status.Degraded) + msg := fmt.Sprintf("input '%s' is left out due to capability restriction '%s'", inputType, c.name()) + c.log.Errorf(msg) + c.reporter.Update(state.Degraded, msg) } newInputs = append(newInputs, input) diff --git a/x-pack/elastic-agent/pkg/capabilities/input_test.go b/x-pack/elastic-agent/pkg/capabilities/input_test.go index 8416a81649b..7a2707d8f83 100644 --- a/x-pack/elastic-agent/pkg/capabilities/input_test.go +++ b/x-pack/elastic-agent/pkg/capabilities/input_test.go @@ -8,11 +8,12 @@ import ( "fmt" "testing" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/state" + "github.com/stretchr/testify/assert" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/transpiler" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" - "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/status" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/fleetapi" ) @@ -394,5 +395,5 @@ func getInputsMap(tt ...string) map[string]interface{} { type testReporter struct{} -func (*testReporter) Update(status.AgentStatus) {} -func (*testReporter) Unregister() {} +func (*testReporter) Update(state.Status, string) {} +func (*testReporter) Unregister() {} diff --git a/x-pack/elastic-agent/pkg/capabilities/output.go b/x-pack/elastic-agent/pkg/capabilities/output.go index 34a9ca6e055..bf47123f337 100644 --- a/x-pack/elastic-agent/pkg/capabilities/output.go +++ b/x-pack/elastic-agent/pkg/capabilities/output.go @@ -7,6 +7,8 @@ package capabilities import ( "fmt" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/state" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/status" @@ -129,8 +131,9 @@ func (c *outputCapability) renderOutputs(outputs map[string]interface{}) (map[st outputs[outputName] = output if !isSupported { - c.log.Errorf("output '%s' is left out due to capability restriction '%s'", outputName, c.name()) - c.reporter.Update(status.Degraded) + msg := fmt.Sprintf("output '%s' is left out due to capability restriction '%s'", outputName, c.name()) + c.log.Errorf(msg) + c.reporter.Update(state.Degraded, msg) } } diff --git a/x-pack/elastic-agent/pkg/capabilities/upgrade.go b/x-pack/elastic-agent/pkg/capabilities/upgrade.go index 4ca6f9074d4..8712529c841 100644 --- a/x-pack/elastic-agent/pkg/capabilities/upgrade.go +++ b/x-pack/elastic-agent/pkg/capabilities/upgrade.go @@ -8,6 +8,8 @@ import ( "fmt" "strings" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/state" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/transpiler" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/status" @@ -125,8 +127,9 @@ func (c *upgradeCapability) Apply(upgradeMap map[string]interface{}) (map[string // if deny switch the logic if c.Type == denyKey { isSupported = !isSupported - c.log.Errorf("upgrade is blocked out due to capability restriction '%s'", c.name()) - c.reporter.Update(status.Degraded) + msg := fmt.Sprintf("upgrade is blocked out due to capability restriction '%s'", c.name()) + c.log.Errorf(msg) + c.reporter.Update(state.Degraded, msg) } if !isSupported { diff --git a/x-pack/elastic-agent/pkg/core/status/reporter.go b/x-pack/elastic-agent/pkg/core/status/reporter.go index feb7472b23d..d4abd96a990 100644 --- a/x-pack/elastic-agent/pkg/core/status/reporter.go +++ b/x-pack/elastic-agent/pkg/core/status/reporter.go @@ -7,9 +7,10 @@ package status import ( "sync" - "github.com/elastic/elastic-agent-client/v7/pkg/proto" "github.com/google/uuid" + "github.com/elastic/elastic-agent-client/v7/pkg/proto" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/state" )