Skip to content

Commit b4f1451

Browse files
committed
Merge branch 'v3' into chore/report-nap-instances
2 parents 10ab393 + 1e49c2f commit b4f1451

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1181
-551
lines changed

api/grpc/mpi/v1/files.pb.go

Lines changed: 63 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/files.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ message X509Name {
272272
repeated string postal_code = 7 [(buf.validate.field).repeated.items.string.min_len = 1];
273273

274274
// Serial Number (SN): Unique identifier or serial number.
275-
string serial_number = 8 [(buf.validate.field).string.min_len = 0];
275+
string serial_number = 8;
276276

277277
// Common Name (CN): Typically the person’s or entity's full name.
278-
string common_name = 9 [(buf.validate.field).string.min_len = 1];
278+
string common_name = 9;
279279

280280
// Parsed attributes including any non-standard attributes, as specified in RFC 2253.
281281
// These attributes are parsed but not marshaled by this package.

internal/bus/topics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const (
1515
ConfigUploadRequestTopic = "config-upload-request"
1616
DataPlaneResponseTopic = "data-plane-response"
1717
ConnectionCreatedTopic = "connection-created"
18+
CredentialUpdatedTopic = "credential-updated"
19+
ConnectionResetTopic = "connection-reset"
1820
ConfigApplyRequestTopic = "config-apply-request"
1921
WriteConfigSuccessfulTopic = "write-config-successful"
2022
ConfigApplySuccessfulTopic = "config-apply-successful"

internal/collector/nginxossreceiver/internal/scraper/stubstatus/stub_status_scraper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func (s *NginxStubStatusScraper) ID() component.ID {
5959

6060
func (s *NginxStubStatusScraper) Start(_ context.Context, _ component.Host) error {
6161
httpClient := http.DefaultClient
62+
httpClient.Timeout = s.cfg.ClientConfig.Timeout
63+
6264
if strings.HasPrefix(s.cfg.APIDetails.Listen, "unix:") {
6365
httpClient.Transport = &http.Transport{
6466
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {

internal/collector/nginxplusreceiver/scraper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func newNginxPlusScraper(
4949
endpoint := strings.TrimPrefix(cfg.APIDetails.URL, "unix:")
5050
logger := settings.Logger
5151
logger.Info("Creating NGINX Plus scraper")
52+
5253
httpClient := http.DefaultClient
54+
httpClient.Timeout = cfg.ClientConfig.Timeout
5355

5456
mb := metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings)
5557
rb := mb.NewResourceBuilder()

internal/collector/otel_collector_plugin.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func (oc *Collector) Init(ctx context.Context, mp bus.MessagePipeInterface) erro
120120
oc.processReceivers(ctx, oc.config.Collector.Receivers.OtlpReceivers)
121121
}
122122

123+
if !oc.stopped {
124+
return errors.New("OTel collector already running")
125+
}
126+
123127
bootErr := oc.bootup(runCtx)
124128
if bootErr != nil {
125129
slog.ErrorContext(runCtx, "Unable to start OTel Collector", "error", bootErr)
@@ -219,6 +223,7 @@ func (oc *Collector) Close(ctx context.Context) error {
219223
slog.ErrorContext(ctx, "Failed to shutdown OTel Collector", "error", err, "state", oc.service.GetState())
220224
} else {
221225
slog.InfoContext(ctx, "OTel Collector shutdown", "state", oc.service.GetState())
226+
oc.stopped = true
222227
}
223228
}
224229

@@ -374,6 +379,11 @@ func (oc *Collector) restartCollector(ctx context.Context) {
374379
var runCtx context.Context
375380
runCtx, oc.cancel = context.WithCancel(ctx)
376381

382+
if !oc.stopped {
383+
slog.ErrorContext(ctx, "Unable to restart OTel collector, failed to stop collector")
384+
return
385+
}
386+
377387
bootErr := oc.bootup(runCtx)
378388
if bootErr != nil {
379389
slog.ErrorContext(runCtx, "Unable to start OTel Collector", "error", bootErr)

internal/command/command_plugin.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type (
3131
UpdateDataPlaneStatus(ctx context.Context, resource *mpi.Resource) error
3232
UpdateDataPlaneHealth(ctx context.Context, instanceHealths []*mpi.InstanceHealth) error
3333
SendDataPlaneResponse(ctx context.Context, response *mpi.DataPlaneResponse) error
34+
UpdateClient(client mpi.CommandServiceClient)
3435
Subscribe(ctx context.Context)
3536
IsConnected() bool
3637
CreateConnection(ctx context.Context, resource *mpi.Resource) (*mpi.CreateConnectionResponse, error)
@@ -86,6 +87,8 @@ func (cp *CommandPlugin) Info() *bus.Info {
8687

8788
func (cp *CommandPlugin) Process(ctx context.Context, msg *bus.Message) {
8889
switch msg.Topic {
90+
case bus.ConnectionResetTopic:
91+
cp.processConnectionReset(ctx, msg)
8992
case bus.ResourceUpdateTopic:
9093
cp.processResourceUpdate(ctx, msg)
9194
case bus.InstanceHealthTopic:
@@ -172,8 +175,22 @@ func (cp *CommandPlugin) processDataPlaneResponse(ctx context.Context, msg *bus.
172175
}
173176
}
174177

178+
func (cp *CommandPlugin) processConnectionReset(ctx context.Context, msg *bus.Message) {
179+
slog.DebugContext(ctx, "Command plugin received connection reset")
180+
if newConnection, ok := msg.Data.(grpc.GrpcConnectionInterface); ok {
181+
err := cp.conn.Close(ctx)
182+
if err != nil {
183+
slog.ErrorContext(ctx, "Command plugin: unable to close connection", "error", err)
184+
}
185+
cp.conn = newConnection
186+
cp.commandService.UpdateClient(cp.conn.CommandServiceClient())
187+
slog.DebugContext(ctx, "Command service client reset successfully")
188+
}
189+
}
190+
175191
func (cp *CommandPlugin) Subscriptions() []string {
176192
return []string{
193+
bus.ConnectionResetTopic,
177194
bus.ResourceUpdateTopic,
178195
bus.InstanceHealthTopic,
179196
bus.DataPlaneHealthResponseTopic,

internal/command/command_plugin_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestCommandPlugin_Subscriptions(t *testing.T) {
4545
assert.Equal(
4646
t,
4747
[]string{
48+
bus.ConnectionResetTopic,
4849
bus.ResourceUpdateTopic,
4950
bus.InstanceHealthTopic,
5051
bus.DataPlaneHealthResponseTopic,
@@ -142,6 +143,12 @@ func TestCommandPlugin_Process(t *testing.T) {
142143
})
143144
require.Equal(t, 1, fakeCommandService.UpdateDataPlaneHealthCallCount())
144145
require.Equal(t, 1, fakeCommandService.SendDataPlaneResponseCallCount())
146+
147+
commandPlugin.Process(ctx, &bus.Message{
148+
Topic: bus.ConnectionResetTopic,
149+
Data: commandPlugin.conn,
150+
})
151+
require.Equal(t, 1, fakeCommandService.UpdateClientCallCount())
145152
}
146153

147154
func TestCommandPlugin_monitorSubscribeChannel(t *testing.T) {

0 commit comments

Comments
 (0)