Skip to content

Commit 1ecca95

Browse files
committed
add plus conf file
1 parent a6e00f7 commit 1ecca95

File tree

3 files changed

+11
-63
lines changed

3 files changed

+11
-63
lines changed

internal/model/config.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package model
77

88
import (
9-
"log/slog"
109
"reflect"
1110

1211
"github.com/nginx/agent/v3/api/grpc/mpi/v1"
@@ -82,54 +81,35 @@ func (ncc *NginxConfigContext) Equal(otherNginxConfigContext *NginxConfigContext
8281
if ncc.StubStatus.URL != otherNginxConfigContext.StubStatus.URL || ncc.StubStatus.Listen !=
8382
otherNginxConfigContext.StubStatus.Listen || ncc.StubStatus.Location !=
8483
otherNginxConfigContext.StubStatus.Location {
85-
slog.Info("stub status not equal")
86-
slog.Info("URL", "ncc", ncc.StubStatus.URL, "other",
87-
otherNginxConfigContext.StubStatus.URL)
88-
slog.Info("Listen", "ncc", ncc.StubStatus.Listen, "other",
89-
otherNginxConfigContext.StubStatus.Listen)
90-
slog.Info("URL", "ncc", ncc.StubStatus.Location, "other",
91-
otherNginxConfigContext.StubStatus.Location)
92-
9384
return false
9485
}
9586

9687
if ncc.PlusAPI.URL != otherNginxConfigContext.PlusAPI.URL || ncc.PlusAPI.Listen !=
9788
otherNginxConfigContext.PlusAPI.Listen || ncc.PlusAPI.Location !=
9889
otherNginxConfigContext.PlusAPI.Location {
99-
slog.Info("plus api not equal")
100-
10190
return false
10291
}
10392

10493
if ncc.InstanceID != otherNginxConfigContext.InstanceID {
105-
slog.Info("id not equal")
106-
10794
return false
10895
}
10996

11097
if !ncc.areFileEqual(otherNginxConfigContext.Files) {
111-
slog.Info("files not equal")
112-
11398
return false
11499
}
115100

116101
if !reflect.DeepEqual(ncc.AccessLogs, otherNginxConfigContext.AccessLogs) {
117-
slog.Info("access logs not equal")
118102
return false
119103
}
120104

121105
if !reflect.DeepEqual(ncc.ErrorLogs, otherNginxConfigContext.ErrorLogs) {
122-
slog.Info("error logs not equal")
123106
return false
124107
}
125108

126109
if !reflect.DeepEqual(ncc.NAPSysLogServers, otherNginxConfigContext.NAPSysLogServers) {
127-
slog.Info("nap syslog servers not equal")
128110
return false
129111
}
130112

131-
slog.Info("config is equal")
132-
133113
return true
134114
}
135115

internal/watcher/instance/instance_watcher_service.go

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,12 @@ func (iw *InstanceWatcherService) ReparseConfig(ctx context.Context, instanceID
168168
}
169169
}
170170

171-
slog.Info("Send Config Context Update - Reparse config", "instance_id", instanceID)
172171
iw.sendNginxConfigContextUpdate(ctx, nginxConfigContext)
173-
iw.updateCache(nginxConfigContext)
172+
iw.nginxConfigCache[nginxConfigContext.InstanceID] = nginxConfigContext
174173
updatesRequired = proto.UpdateNginxInstanceRuntime(instance, nginxConfigContext)
175174
}
176175

177176
if updatesRequired {
178-
slog.Info("Instance Update Required")
179177
instanceUpdates := InstanceUpdates{}
180178
instanceUpdates.UpdatedInstances = append(instanceUpdates.UpdatedInstances, instance)
181179
iw.instancesChannel <- InstanceUpdatesMessage{
@@ -185,17 +183,6 @@ func (iw *InstanceWatcherService) ReparseConfig(ctx context.Context, instanceID
185183
}
186184
}
187185

188-
func (iw *InstanceWatcherService) updateCache(nginxConfigContext *model.NginxConfigContext) {
189-
iw.nginxConfigCache[nginxConfigContext.InstanceID] = nginxConfigContext
190-
slog.Info("Instance Update Cache - New Context", "url", &nginxConfigContext.StubStatus.URL,
191-
"location", nginxConfigContext.StubStatus.Location,
192-
"listen", nginxConfigContext.StubStatus.Listen)
193-
slog.Info("Instance Update Cache - Cache ", "url",
194-
iw.nginxConfigCache[nginxConfigContext.InstanceID].StubStatus.URL,
195-
"location", iw.nginxConfigCache[nginxConfigContext.InstanceID].StubStatus.Location,
196-
"listen", iw.nginxConfigCache[nginxConfigContext.InstanceID].StubStatus.Listen)
197-
}
198-
199186
func (iw *InstanceWatcherService) checkForUpdates(
200187
ctx context.Context,
201188
) {
@@ -233,9 +220,8 @@ func (iw *InstanceWatcherService) checkForUpdates(
233220
"error", parseErr,
234221
)
235222
} else {
236-
slog.Info("Send Config Context Update - check for updates")
237223
iw.sendNginxConfigContextUpdate(newCtx, nginxConfigContext)
238-
iw.updateCache(nginxConfigContext)
224+
iw.nginxConfigCache[nginxConfigContext.InstanceID] = nginxConfigContext
239225
proto.UpdateNginxInstanceRuntime(newInstance, nginxConfigContext)
240226
iw.instanceCache[newInstance.GetInstanceMeta().GetInstanceId()] = newInstance
241227
}
@@ -255,28 +241,8 @@ func (iw *InstanceWatcherService) sendNginxConfigContextUpdate(
255241
ctx context.Context,
256242
nginxConfigContext *model.NginxConfigContext,
257243
) {
258-
if iw.nginxConfigCache[nginxConfigContext.InstanceID] == nil {
259-
slog.Info("iw.nginxConfigCache[nginxConfigContext.InstanceID] == nil")
260-
slog.DebugContext(
261-
ctx,
262-
"New NGINX config context",
263-
"instance_id", nginxConfigContext.InstanceID,
264-
"nginx_config_context", nginxConfigContext,
265-
)
266-
267-
iw.nginxConfigContextChannel <- NginxConfigContextMessage{
268-
CorrelationID: logger.GetCorrelationIDAttr(ctx),
269-
NginxConfigContext: nginxConfigContext,
270-
}
271-
} else if !iw.nginxConfigCache[nginxConfigContext.InstanceID].Equal(nginxConfigContext) {
272-
slog.Info("!iw.nginxConfigCache[nginxConfigContext.InstanceID].Equal(nginxConfigContext)")
273-
slog.Info("Check Cache - Cache ", "url",
274-
iw.nginxConfigCache[nginxConfigContext.InstanceID].StubStatus.URL,
275-
"location", iw.nginxConfigCache[nginxConfigContext.InstanceID].StubStatus.Location,
276-
"listen", iw.nginxConfigCache[nginxConfigContext.InstanceID].StubStatus.Listen)
277-
slog.Info("Check Cache - New Context", "url", nginxConfigContext.StubStatus.URL,
278-
"location", nginxConfigContext.StubStatus.Location,
279-
"listen", nginxConfigContext.StubStatus.Listen)
244+
if iw.nginxConfigCache[nginxConfigContext.InstanceID] == nil ||
245+
!iw.nginxConfigCache[nginxConfigContext.InstanceID].Equal(nginxConfigContext) {
280246
slog.DebugContext(
281247
ctx,
282248
"New NGINX config context",

test/integration/grpc_management_plane_api_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net/http"
1414
"os"
1515
"slices"
16+
"sort"
1617
"testing"
1718
"time"
1819

@@ -230,14 +231,15 @@ func TestGrpc_ConfigApply(t *testing.T) {
230231
responses = getManagementPlaneResponses(t, 2)
231232
t.Logf("Config apply responses: %v", responses)
232233

233-
// sort.Slice(responses, func(i, j int) bool {
234-
// return responses[i].GetCommandResponse().GetMessage() < responses[j].GetCommandResponse().GetMessage()
235-
// })
234+
if len(responses) > 1 {
235+
t.Logf("Config apply responses more than 1")
236+
sort.Slice(responses, func(i, j int) bool {
237+
return responses[i].GetCommandResponse().GetMessage() < responses[j].GetCommandResponse().GetMessage()
238+
})
239+
}
236240

237241
assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
238242
assert.Equal(t, "Config apply successful", responses[0].GetCommandResponse().GetMessage())
239-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[1].GetCommandResponse().GetStatus())
240-
// assert.Equal(t, "Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
241243
})
242244

243245
t.Run("Test 3: Invalid config", func(t *testing.T) {

0 commit comments

Comments
 (0)