Skip to content

Commit

Permalink
Fix status reporter initialization (#1341)
Browse files Browse the repository at this point in the history
(cherry picked from commit 177b5fb)
  • Loading branch information
AndersonQ authored and mergify[bot] committed Sep 28, 2022
1 parent 1e38c9a commit d782d9d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/pkg/core/status/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ type controller struct {
// NewController creates a new reporter.
func NewController(log *logger.Logger) Controller {
return &controller{
status: Healthy,
reporters: make(map[string]*reporter),
appReporters: make(map[string]*reporter),
log: log,
status: Healthy,
reporters: make(map[string]*reporter),
localReporters: make(map[string]*reporter),
appReporters: make(map[string]*reporter),
log: log,
}
}

Expand Down Expand Up @@ -154,12 +155,12 @@ func (r *controller) RegisterLocalComponent(componentIdentifier string) Reporter
return rep
}

// Register registers new component for status updates.
// RegisterComponent registers new component for status updates.
func (r *controller) RegisterComponent(componentIdentifier string) Reporter {
return r.RegisterComponentWithPersistance(componentIdentifier, false)
}

// Register registers new component for status updates.
// RegisterComponentWithPersistance registers new component for status updates.
func (r *controller) RegisterComponentWithPersistance(componentIdentifier string, persistent bool) Reporter {
id := componentIdentifier + "-" + uuid.New().String()[:8]
rep := &reporter{
Expand Down
18 changes: 18 additions & 0 deletions internal/pkg/core/status/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ import (
"github.com/elastic/elastic-agent/pkg/core/logger"
)

func TestNewController_ensure_all_is_initialzed(t *testing.T) {
l, _ := logger.New("", false)

newController := NewController(l)

c, ok := newController.(*controller)
if !ok {
t.Fatalf("expected c %T, not c %T", controller{}, newController)
}

c.reporters["ignore"] = &reporter{}
c.localReporters["ignore"] = &reporter{}
c.appReporters["ignore"] = &reporter{}
if c.log == nil {
t.Error("logger shouldn't be nil, it was not correctly assigned")
}
}

func TestReporter(t *testing.T) {
l, _ := logger.New("", false)
t.Run("healthy by default", func(t *testing.T) {
Expand Down

0 comments on commit d782d9d

Please sign in to comment.