Skip to content

Commit 6e3afb2

Browse files
committed
Add logger; change function name
1 parent 8e50cf7 commit 6e3afb2

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
lines changed

internal/mode/static/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (h *eventHandlerImpl) parseAndCaptureEvent(ctx context.Context, logger logr
300300
func (h *eventHandlerImpl) updateNginxConf(conf dataplane.Configuration) error {
301301
files := h.cfg.generator.Generate(conf)
302302

303-
h.cfg.nginxUpdater.UpdateNginxConfig(len(files))
303+
h.cfg.nginxUpdater.UpdateConfig(len(files))
304304

305305
// If using NGINX Plus, update upstream servers using the API.
306306
if h.cfg.plus {

internal/mode/static/handler_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ var _ = Describe("eventHandler", func() {
6464
Expect(fakeGenerator.GenerateCallCount()).Should(Equal(1))
6565
Expect(fakeGenerator.GenerateArgsForCall(0)).Should(Equal(expectedConf))
6666

67-
Expect(fakeNginxUpdater.UpdateNginxConfigCallCount()).Should(Equal(1))
68-
lenFiles := fakeNginxUpdater.UpdateNginxConfigArgsForCall(0)
67+
Expect(fakeNginxUpdater.UpdateConfigCallCount()).Should(Equal(1))
68+
lenFiles := fakeNginxUpdater.UpdateConfigArgsForCall(0)
6969
Expect(expectedFiles).To(HaveLen(lenFiles))
7070

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

435435
Expect(fakeGenerator.GenerateCallCount()).To(Equal(1))
436-
Expect(fakeNginxUpdater.UpdateNginxConfigCallCount()).To(Equal(1))
436+
Expect(fakeNginxUpdater.UpdateConfigCallCount()).To(Equal(1))
437437
Expect(fakeNginxUpdater.UpdateUpstreamServersCallCount()).To(Equal(0))
438438
})
439439
})

internal/mode/static/manager.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ func StartManager(cfg config.Config) error {
177177
})
178178

179179
eventHandler := newEventHandlerImpl(eventHandlerConfig{
180-
nginxUpdater: &agent.NginxUpdaterImpl{},
180+
nginxUpdater: &agent.NginxUpdaterImpl{
181+
Logger: cfg.Logger.WithName("nginxUpdater"),
182+
Plus: cfg.Plus,
183+
},
181184
metricsCollector: handlerCollector,
182185
statusUpdater: groupStatusUpdater,
183186
processor: processor,
+10-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
package agent
22

3-
import "fmt"
3+
import (
4+
"github.com/go-logr/logr"
5+
)
46

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

79
//counterfeiter:generate . NginxUpdater
810

911
// NginxUpdater is an interface for updating NGINX using the NGINX agent.
1012
type NginxUpdater interface {
11-
UpdateNginxConfig(int)
13+
UpdateConfig(int)
1214
UpdateUpstreamServers()
1315
}
1416

1517
// NginxUpdaterImpl implements the NginxUpdater interface.
1618
type NginxUpdaterImpl struct {
17-
Plus bool
19+
Logger logr.Logger
20+
Plus bool
1821
}
1922

20-
// UpdateNginxConfig sends the nginx configuration to the agent.
21-
func (n *NginxUpdaterImpl) UpdateNginxConfig(files int) {
22-
fmt.Println("Sending nginx configuration to agent.", "numFiles", files)
23+
// UpdateConfig sends the nginx configuration to the agent.
24+
func (n *NginxUpdaterImpl) UpdateConfig(files int) {
25+
n.Logger.Info("Sending nginx configuration to agent.", "numFiles", files)
2326
}
2427

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

32-
fmt.Println("Updating upstream servers using NGINX Plus API.")
35+
n.Logger.Info("Updating upstream servers using NGINX Plus API.")
3336
}

internal/mode/static/nginx/agent/agentfakes/fake_nginx_updater.go

+24-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)