Skip to content

Commit

Permalink
Cleanup from merge into master.
Browse files Browse the repository at this point in the history
  • Loading branch information
blakerouse committed Feb 16, 2021
1 parent 059e8de commit b78c551
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 3 additions & 1 deletion x-pack/elastic-agent/pkg/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions x-pack/elastic-agent/pkg/capabilities/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions x-pack/elastic-agent/pkg/capabilities/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions x-pack/elastic-agent/pkg/capabilities/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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() {}
7 changes: 5 additions & 2 deletions x-pack/elastic-agent/pkg/capabilities/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

Expand Down
7 changes: 5 additions & 2 deletions x-pack/elastic-agent/pkg/capabilities/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/elastic-agent/pkg/core/status/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit b78c551

Please sign in to comment.