Skip to content

Commit 3beb451

Browse files
committed
fix: make generateid available for others to use
1 parent d6b9ef4 commit 3beb451

20 files changed

+91
-85
lines changed

internal/command/command_plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
1515
"github.com/nginx/agent/v3/internal/bus"
1616
"github.com/nginx/agent/v3/internal/config"
17-
"github.com/nginx/agent/v3/internal/datasource/proto"
1817
"github.com/nginx/agent/v3/internal/grpc"
1918
"github.com/nginx/agent/v3/internal/logger"
2019
pkgConfig "github.com/nginx/agent/v3/pkg/config"
20+
"github.com/nginx/agent/v3/pkg/id"
2121
)
2222

2323
var _ bus.Plugin = (*CommandPlugin)(nil)
@@ -275,7 +275,7 @@ func (cp *CommandPlugin) createDataPlaneResponse(correlationID string, status mp
275275
) *mpi.DataPlaneResponse {
276276
return &mpi.DataPlaneResponse{
277277
MessageMeta: &mpi.MessageMeta{
278-
MessageId: proto.GenerateMessageID(),
278+
MessageId: id.GenerateMessageID(),
279279
CorrelationId: correlationID,
280280
Timestamp: timestamppb.Now(),
281281
},

internal/command/command_plugin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"time"
1313

1414
pkg "github.com/nginx/agent/v3/pkg/config"
15+
"github.com/nginx/agent/v3/pkg/id"
1516

16-
"github.com/nginx/agent/v3/internal/datasource/proto"
1717
"google.golang.org/protobuf/types/known/timestamppb"
1818

1919
"github.com/nginx/agent/v3/internal/bus/busfakes"
@@ -340,7 +340,7 @@ func TestMonitorSubscribeChannel(t *testing.T) {
340340
func Test_createDataPlaneResponse(t *testing.T) {
341341
expected := &mpi.DataPlaneResponse{
342342
MessageMeta: &mpi.MessageMeta{
343-
MessageId: proto.GenerateMessageID(),
343+
MessageId: id.GenerateMessageID(),
344344
CorrelationId: "dfsbhj6-bc92-30c1-a9c9-85591422068e",
345345
Timestamp: timestamppb.Now(),
346346
},

internal/command/command_service.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020

2121
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
2222
"github.com/nginx/agent/v3/internal/config"
23-
"github.com/nginx/agent/v3/internal/datasource/proto"
2423
"github.com/nginx/agent/v3/internal/grpc"
2524
"github.com/nginx/agent/v3/internal/logger"
25+
"github.com/nginx/agent/v3/pkg/id"
2626

2727
"google.golang.org/protobuf/types/known/timestamppb"
2828

@@ -96,7 +96,7 @@ func (cs *CommandService) UpdateDataPlaneStatus(
9696

9797
request := &mpi.UpdateDataPlaneStatusRequest{
9898
MessageMeta: &mpi.MessageMeta{
99-
MessageId: proto.GenerateMessageID(),
99+
MessageId: id.GenerateMessageID(),
100100
CorrelationId: correlationID,
101101
Timestamp: timestamppb.Now(),
102102
},
@@ -150,7 +150,7 @@ func (cs *CommandService) UpdateDataPlaneHealth(ctx context.Context, instanceHea
150150

151151
request := &mpi.UpdateDataPlaneHealthRequest{
152152
MessageMeta: &mpi.MessageMeta{
153-
MessageId: proto.GenerateMessageID(),
153+
MessageId: id.GenerateMessageID(),
154154
CorrelationId: correlationID,
155155
Timestamp: timestamppb.Now(),
156156
},
@@ -233,7 +233,7 @@ func (cs *CommandService) CreateConnection(
233233

234234
request := &mpi.CreateConnectionRequest{
235235
MessageMeta: &mpi.MessageMeta{
236-
MessageId: proto.GenerateMessageID(),
236+
MessageId: id.GenerateMessageID(),
237237
CorrelationId: correlationID,
238238
Timestamp: timestamppb.Now(),
239239
},
@@ -332,7 +332,7 @@ func (cs *CommandService) sendResponseForQueuedConfigApplyRequests(
332332
for i := 0; i < indexOfConfigApplyRequest; i++ {
333333
newResponse := response
334334

335-
newResponse.GetMessageMeta().MessageId = proto.GenerateMessageID()
335+
newResponse.GetMessageMeta().MessageId = id.GenerateMessageID()
336336

337337
request := cs.configApplyRequestQueue[instanceID][i]
338338
newResponse.GetMessageMeta().CorrelationId = request.GetMessageMeta().GetCorrelationId()
@@ -525,7 +525,7 @@ func (cs *CommandService) checkIfInstanceExists(
525525

526526
response := &mpi.DataPlaneResponse{
527527
MessageMeta: &mpi.MessageMeta{
528-
MessageId: proto.GenerateMessageID(),
528+
MessageId: id.GenerateMessageID(),
529529
CorrelationId: request.GetMessageMeta().GetCorrelationId(),
530530
Timestamp: timestamppb.Now(),
531531
},

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"strconv"
1818
"strings"
1919

20+
uuidLibrary "github.com/nginx/agent/v3/pkg/id"
2021
selfsignedcerts "github.com/nginx/agent/v3/pkg/tls"
21-
uuidLibrary "github.com/nginx/agent/v3/pkg/uuid"
2222
"github.com/spf13/cobra"
2323
flag "github.com/spf13/pflag"
2424
"github.com/spf13/viper"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) F5, Inc.
2+
//
3+
// This source code is licensed under the Apache License, Version 2.0 license found in the
4+
// LICENSE file in the root directory of this source tree.
5+
6+
package proto
7+
8+
import (
9+
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
10+
agentid "github.com/nginx/agent/v3/pkg/id"
11+
"google.golang.org/protobuf/types/known/timestamppb"
12+
)
13+
14+
func CreateDataPlaneResponse(correlationID string, status mpi.CommandResponse_CommandStatus,
15+
message, instanceID, err string,
16+
) *mpi.DataPlaneResponse {
17+
return &mpi.DataPlaneResponse{
18+
MessageMeta: &mpi.MessageMeta{
19+
MessageId: agentid.GenerateMessageID(),
20+
CorrelationId: correlationID,
21+
Timestamp: timestamppb.Now(),
22+
},
23+
CommandResponse: &mpi.CommandResponse{
24+
Status: status,
25+
Message: message,
26+
Error: err,
27+
},
28+
InstanceId: instanceID,
29+
}
30+
}

internal/file/file_manager_service.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"sync"
1717
"sync/atomic"
1818

19-
"github.com/nginx/agent/v3/internal/datasource/proto"
2019
"github.com/nginx/agent/v3/internal/model"
2120

2221
"github.com/cenkalti/backoff/v4"
@@ -26,6 +25,7 @@ import (
2625
"github.com/nginx/agent/v3/internal/grpc"
2726
"github.com/nginx/agent/v3/internal/logger"
2827
"github.com/nginx/agent/v3/pkg/files"
28+
"github.com/nginx/agent/v3/pkg/id"
2929
"google.golang.org/protobuf/types/known/timestamppb"
3030

3131
backoffHelpers "github.com/nginx/agent/v3/internal/backoff"
@@ -104,7 +104,7 @@ func (fms *FileManagerService) UpdateOverview(
104104

105105
request := &mpi.UpdateOverviewRequest{
106106
MessageMeta: &mpi.MessageMeta{
107-
MessageId: proto.GenerateMessageID(),
107+
MessageId: id.GenerateMessageID(),
108108
CorrelationId: correlationID,
109109
Timestamp: timestamppb.Now(),
110110
},
@@ -224,7 +224,7 @@ func (fms *FileManagerService) UpdateFile(
224224
Contents: contents,
225225
},
226226
MessageMeta: &mpi.MessageMeta{
227-
MessageId: proto.GenerateMessageID(),
227+
MessageId: id.GenerateMessageID(),
228228
CorrelationId: correlationID,
229229
Timestamp: timestamppb.Now(),
230230
},
@@ -382,7 +382,7 @@ func (fms *FileManagerService) fileUpdate(ctx context.Context, file *mpi.File) e
382382
getFile := func() (*mpi.GetFileResponse, error) {
383383
return fms.fileServiceClient.GetFile(ctx, &mpi.GetFileRequest{
384384
MessageMeta: &mpi.MessageMeta{
385-
MessageId: proto.GenerateMessageID(),
385+
MessageId: id.GenerateMessageID(),
386386
CorrelationId: logger.GetCorrelationID(ctx),
387387
Timestamp: timestamppb.Now(),
388388
},

internal/file/file_plugin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"log/slog"
1212

1313
"github.com/nginx/agent/v3/pkg/files"
14+
"github.com/nginx/agent/v3/pkg/id"
1415

1516
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
1617
"github.com/nginx/agent/v3/internal/bus"
1718
"github.com/nginx/agent/v3/internal/config"
18-
"github.com/nginx/agent/v3/internal/datasource/proto"
1919
"github.com/nginx/agent/v3/internal/grpc"
2020
"github.com/nginx/agent/v3/internal/logger"
2121
"github.com/nginx/agent/v3/internal/model"
@@ -319,7 +319,7 @@ func (fp *FilePlugin) handleConfigUploadRequest(ctx context.Context, msg *bus.Me
319319

320320
response := &mpi.DataPlaneResponse{
321321
MessageMeta: &mpi.MessageMeta{
322-
MessageId: proto.GenerateMessageID(),
322+
MessageId: id.GenerateMessageID(),
323323
CorrelationId: correlationID,
324324
Timestamp: timestamppb.Now(),
325325
},
@@ -343,7 +343,7 @@ func (fp *FilePlugin) createDataPlaneResponse(correlationID string, status mpi.C
343343
) *mpi.DataPlaneResponse {
344344
return &mpi.DataPlaneResponse{
345345
MessageMeta: &mpi.MessageMeta{
346-
MessageId: proto.GenerateMessageID(),
346+
MessageId: id.GenerateMessageID(),
347347
CorrelationId: correlationID,
348348
Timestamp: timestamppb.Now(),
349349
},

internal/file/file_plugin_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"time"
1414

1515
"github.com/nginx/agent/v3/internal/bus/busfakes"
16-
"github.com/nginx/agent/v3/internal/datasource/proto"
17-
1816
"google.golang.org/protobuf/types/known/timestamppb"
1917

2018
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
@@ -24,6 +22,7 @@ import (
2422
"github.com/nginx/agent/v3/internal/grpc/grpcfakes"
2523
"github.com/nginx/agent/v3/internal/model"
2624
"github.com/nginx/agent/v3/pkg/files"
25+
"github.com/nginx/agent/v3/pkg/id"
2726
"github.com/nginx/agent/v3/test/helpers"
2827
"github.com/nginx/agent/v3/test/protos"
2928
"github.com/nginx/agent/v3/test/types"
@@ -445,7 +444,7 @@ func TestFilePlugin_Process_ConfigApplyRollbackCompleteTopic(t *testing.T) {
445444

446445
expectedResponse := &mpi.DataPlaneResponse{
447446
MessageMeta: &mpi.MessageMeta{
448-
MessageId: proto.GenerateMessageID(),
447+
MessageId: id.GenerateMessageID(),
449448
CorrelationId: "dfsbhj6-bc92-30c1-a9c9-85591422068e",
450449
Timestamp: timestamppb.Now(),
451450
},

internal/logger/logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"strings"
1515

1616
"github.com/nginx/agent/v3/internal/config"
17-
"github.com/nginx/agent/v3/internal/datasource/proto"
17+
"github.com/nginx/agent/v3/pkg/id"
1818
)
1919

2020
const (
@@ -121,7 +121,7 @@ func (h contextHandler) observe(ctx context.Context) (as []slog.Attr) {
121121
}
122122

123123
func GenerateCorrelationID() slog.Attr {
124-
return slog.Any(CorrelationIDKey, proto.GenerateMessageID())
124+
return slog.Any(CorrelationIDKey, id.GenerateMessageID())
125125
}
126126

127127
func GetCorrelationID(ctx context.Context) string {

internal/resource/nginx_plus_actions.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"log/slog"
1212

1313
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
14-
"github.com/nginx/agent/v3/internal/datasource/proto"
14+
response "github.com/nginx/agent/v3/internal/datasource/proto"
1515
"github.com/nginx/agent/v3/internal/logger"
1616
)
1717

@@ -33,15 +33,15 @@ func (a *APIAction) HandleUpdateStreamServersRequest(ctx context.Context, action
3333
slog.ErrorContext(ctx, "Unable to update stream servers of upstream", "request",
3434
action.GetUpdateHttpUpstreamServers(), "error", err)
3535

36-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
36+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
3737
"", instanceID, err.Error())
3838
}
3939

4040
slog.DebugContext(ctx, "Successfully updated stream upstream servers", "http_upstream_name",
4141
action.GetUpdateHttpUpstreamServers().GetHttpUpstreamName(), "add", len(add), "update", len(update),
4242
"delete", len(del))
4343

44-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
44+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
4545
"Successfully updated stream upstream servers", instanceID, "")
4646
}
4747

@@ -55,7 +55,7 @@ func (a *APIAction) HandleGetStreamUpstreamsRequest(ctx context.Context,
5555
streamUpstreams, err := a.ResourceService.GetStreamUpstreams(ctx, instance)
5656
if err != nil {
5757
slog.ErrorContext(ctx, "Unable to get stream upstreams", "error", err)
58-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
58+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
5959
"", instanceID, err.Error())
6060
}
6161

@@ -67,7 +67,7 @@ func (a *APIAction) HandleGetStreamUpstreamsRequest(ctx context.Context,
6767
streamUpstreamsResponse = string(streamUpstreamsJSON)
6868
}
6969

70-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
70+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
7171
streamUpstreamsResponse, instanceID, "")
7272
}
7373

@@ -80,7 +80,7 @@ func (a *APIAction) HandleGetUpstreamsRequest(ctx context.Context, instance *mpi
8080
if err != nil {
8181
slog.InfoContext(ctx, "Unable to get upstreams", "error", err)
8282

83-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
83+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
8484
"", instanceID, err.Error())
8585
}
8686

@@ -92,7 +92,7 @@ func (a *APIAction) HandleGetUpstreamsRequest(ctx context.Context, instance *mpi
9292
upstreamsResponse = string(upstreamsJSON)
9393
}
9494

95-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
95+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
9696
upstreamsResponse, instanceID, "")
9797
}
9898

@@ -109,15 +109,15 @@ func (a *APIAction) HandleUpdateHTTPUpstreamsRequest(ctx context.Context, action
109109
slog.ErrorContext(ctx, "Unable to update HTTP servers of upstream", "request",
110110
action.GetUpdateHttpUpstreamServers(), "error", err)
111111

112-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
112+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
113113
"", instanceID, err.Error())
114114
}
115115

116116
slog.DebugContext(ctx, "Successfully updated http upstream servers", "http_upstream_name",
117117
action.GetUpdateHttpUpstreamServers().GetHttpUpstreamName(), "add", len(add), "update", len(update),
118118
"delete", len(del))
119119

120-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
120+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
121121
"Successfully updated HTTP Upstreams", instanceID, "")
122122
}
123123

@@ -132,7 +132,7 @@ func (a *APIAction) HandleGetHTTPUpstreamsServersRequest(ctx context.Context, ac
132132
action.GetGetHttpUpstreamServers().GetHttpUpstreamName())
133133
if err != nil {
134134
slog.ErrorContext(ctx, "Unable to get HTTP servers of upstream", "error", err)
135-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
135+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_FAILURE,
136136
"", instanceID, err.Error())
137137
}
138138

@@ -144,6 +144,6 @@ func (a *APIAction) HandleGetHTTPUpstreamsServersRequest(ctx context.Context, ac
144144
upstreamsResponse = string(upstreamsJSON)
145145
}
146146

147-
return proto.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
147+
return response.CreateDataPlaneResponse(correlationID, mpi.CommandResponse_COMMAND_STATUS_OK,
148148
upstreamsResponse, instanceID, "")
149149
}

0 commit comments

Comments
 (0)