Skip to content

Commit

Permalink
Add logger; change function name
Browse files Browse the repository at this point in the history
  • Loading branch information
sjberman committed Dec 26, 2024
1 parent 8e50cf7 commit 6e3afb2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion internal/mode/static/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (h *eventHandlerImpl) parseAndCaptureEvent(ctx context.Context, logger logr
func (h *eventHandlerImpl) updateNginxConf(conf dataplane.Configuration) error {
files := h.cfg.generator.Generate(conf)

h.cfg.nginxUpdater.UpdateNginxConfig(len(files))
h.cfg.nginxUpdater.UpdateConfig(len(files))

// If using NGINX Plus, update upstream servers using the API.
if h.cfg.plus {
Expand Down
6 changes: 3 additions & 3 deletions internal/mode/static/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ var _ = Describe("eventHandler", func() {
Expect(fakeGenerator.GenerateCallCount()).Should(Equal(1))
Expect(fakeGenerator.GenerateArgsForCall(0)).Should(Equal(expectedConf))

Expect(fakeNginxUpdater.UpdateNginxConfigCallCount()).Should(Equal(1))
lenFiles := fakeNginxUpdater.UpdateNginxConfigArgsForCall(0)
Expect(fakeNginxUpdater.UpdateConfigCallCount()).Should(Equal(1))
lenFiles := fakeNginxUpdater.UpdateConfigArgsForCall(0)
Expect(expectedFiles).To(HaveLen(lenFiles))

Expect(fakeStatusUpdater.UpdateGroupCallCount()).Should(Equal(2))
Expand Down Expand Up @@ -433,7 +433,7 @@ var _ = Describe("eventHandler", func() {
Expect(helpers.Diff(handler.GetLatestConfiguration(), &dcfg)).To(BeEmpty())

Expect(fakeGenerator.GenerateCallCount()).To(Equal(1))
Expect(fakeNginxUpdater.UpdateNginxConfigCallCount()).To(Equal(1))
Expect(fakeNginxUpdater.UpdateConfigCallCount()).To(Equal(1))
Expect(fakeNginxUpdater.UpdateUpstreamServersCallCount()).To(Equal(0))
})
})
Expand Down
5 changes: 4 additions & 1 deletion internal/mode/static/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ func StartManager(cfg config.Config) error {
})

eventHandler := newEventHandlerImpl(eventHandlerConfig{
nginxUpdater: &agent.NginxUpdaterImpl{},
nginxUpdater: &agent.NginxUpdaterImpl{
Logger: cfg.Logger.WithName("nginxUpdater"),
Plus: cfg.Plus,
},
metricsCollector: handlerCollector,
statusUpdater: groupStatusUpdater,
processor: processor,
Expand Down
17 changes: 10 additions & 7 deletions internal/mode/static/nginx/agent/agent.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package agent

import "fmt"
import (
"github.com/go-logr/logr"
)

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate

//counterfeiter:generate . NginxUpdater

// NginxUpdater is an interface for updating NGINX using the NGINX agent.
type NginxUpdater interface {
UpdateNginxConfig(int)
UpdateConfig(int)
UpdateUpstreamServers()
}

// NginxUpdaterImpl implements the NginxUpdater interface.
type NginxUpdaterImpl struct {
Plus bool
Logger logr.Logger
Plus bool
}

// UpdateNginxConfig sends the nginx configuration to the agent.
func (n *NginxUpdaterImpl) UpdateNginxConfig(files int) {
fmt.Println("Sending nginx configuration to agent.", "numFiles", files)
// UpdateConfig sends the nginx configuration to the agent.
func (n *NginxUpdaterImpl) UpdateConfig(files int) {
n.Logger.Info("Sending nginx configuration to agent.", "numFiles", files)
}

// UpdateUpstreamServers sends an APIRequest to the agent to update upstream servers using the NGINX Plus API.
Expand All @@ -29,5 +32,5 @@ func (n *NginxUpdaterImpl) UpdateUpstreamServers() {
return
}

fmt.Println("Updating upstream servers using NGINX Plus API.")
n.Logger.Info("Updating upstream servers using NGINX Plus API.")
}
48 changes: 24 additions & 24 deletions internal/mode/static/nginx/agent/agentfakes/fake_nginx_updater.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e3afb2

Please sign in to comment.