Skip to content

Commit af3b01a

Browse files
committed
fix
1 parent de72bd7 commit af3b01a

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

internal/watcher/instance/nginx-app-protect-instance-watcher.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
1818
"github.com/nginx/agent/v3/internal/config"
1919
"github.com/nginx/agent/v3/pkg/id"
20+
"google.golang.org/protobuf/proto"
2021
)
2122

2223
var (
@@ -268,19 +269,28 @@ func (w *NginxAppProtectInstanceWatcher) updateInstance(ctx context.Context) {
268269
w.instanceMutex.Lock()
269270
defer w.instanceMutex.Unlock()
270271

271-
w.nginxAppProtectInstance.GetInstanceMeta().Version = w.version
272-
runtimeInfo := w.nginxAppProtectInstance.GetInstanceRuntime().GetNginxAppProtectRuntimeInfo()
273-
if runtimeInfo == nil {
274-
slog.ErrorContext(ctx, "Error updating NGINX App Protect instance runtimeInfo, instance no longer exists")
275-
return
276-
}
272+
instanceCopy, ok := proto.Clone(w.nginxAppProtectInstance).(*mpi.Instance)
273+
274+
if ok {
275+
instanceCopy.GetInstanceMeta().Version = w.version
276+
runtimeInfo := instanceCopy.GetInstanceRuntime().GetNginxAppProtectRuntimeInfo()
277+
if runtimeInfo == nil {
278+
slog.ErrorContext(ctx, "Error updating NGINX App Protect instance runtimeInfo, instance no longer exists")
279+
return
280+
}
277281

278-
runtimeInfo.Release = w.release
279-
runtimeInfo.AttackSignatureVersion = w.attackSignatureVersion
280-
runtimeInfo.ThreatCampaignVersion = w.threatCampaignVersion
281-
runtimeInfo.EnforcerEngineVersion = w.enforcerEngineVersion
282+
runtimeInfo.Release = w.release
283+
runtimeInfo.AttackSignatureVersion = w.attackSignatureVersion
284+
runtimeInfo.ThreatCampaignVersion = w.threatCampaignVersion
285+
runtimeInfo.EnforcerEngineVersion = w.enforcerEngineVersion
282286

283-
slog.InfoContext(ctx, "NGINX App Protect instance updated")
287+
w.nginxAppProtectInstance = instanceCopy
288+
289+
slog.InfoContext(ctx, "NGINX App Protect instance updated")
290+
} else {
291+
slog.WarnContext(ctx, "Unable to clone instance while updating instance", "instance",
292+
w.NginxAppProtectInstance())
293+
}
284294
}
285295

286296
func (w *NginxAppProtectInstanceWatcher) haveVersionsChanged() bool {

internal/watcher/instance/nginx-app-protect-instance-watcher_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import (
1111
"testing"
1212
"time"
1313

14+
"github.com/nginx/agent/v3/internal/config"
1415
"github.com/stretchr/testify/assert"
1516
"google.golang.org/protobuf/proto"
1617

17-
"github.com/nginx/agent/v3/internal/config"
18-
1918
"github.com/nginx/agent/v3/pkg/id"
2019
"github.com/nginx/agent/v3/test/protos"
2120

0 commit comments

Comments
 (0)