Skip to content

Commit 112052d

Browse files
author
Aalyria Technologies, Inc
committed
Import changes.
- e9266a2f7bca606f2c5c73d4529fa59d7676f927 GitOrigin-RevId: e9266a2f7bca606f2c5c73d4529fa59d7676f927
1 parent d6d92a8 commit 112052d

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

agent/internal/agentcli/agentcli.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"os"
3333
"os/signal"
3434
"strings"
35+
"syscall"
3536
"time"
3637

3738
"github.com/jonboulle/clockwork"
@@ -44,6 +45,7 @@ import (
4445
otelsdktrace "go.opentelemetry.io/otel/sdk/trace"
4546
semconv "go.opentelemetry.io/otel/semconv/v1.34.0"
4647
oteltracenoop "go.opentelemetry.io/otel/trace/noop"
48+
4749
"golang.org/x/sync/errgroup"
4850
"google.golang.org/grpc"
4951
"google.golang.org/grpc/backoff"
@@ -57,6 +59,7 @@ import (
5759
agent "aalyria.com/spacetime/agent"
5860
"aalyria.com/spacetime/agent/enactment"
5961
enact_extproc "aalyria.com/spacetime/agent/enactment/extproc"
62+
6063
"aalyria.com/spacetime/agent/internal/configpb"
6164
"aalyria.com/spacetime/agent/internal/protofmt"
6265
"aalyria.com/spacetime/agent/internal/snmp"
@@ -175,7 +178,7 @@ func (ac AgentConf) Run(ctx context.Context, args []string) (err error) {
175178
}
176179
defer shutdownTracer()
177180

178-
ctx, stop := signal.NotifyContext(ctx, os.Interrupt)
181+
ctx, stop := signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
179182
defer stop()
180183

181184
g, ctx := errgroup.WithContext(ctx)
@@ -197,7 +200,17 @@ func (ac AgentConf) Run(ctx context.Context, args []string) (err error) {
197200
}
198201
return nil
199202
})
200-
return g.Wait()
203+
204+
// Wait for all goroutines to complete
205+
err = g.Wait()
206+
// Treat context cancellation (from Ctrl+C or SIGTERM) as normal shutdown
207+
// TODO: Check whether this is intended behaviour
208+
if errors.Is(err, context.Canceled) {
209+
log := zerolog.Ctx(ctx)
210+
log.Info().Msg("agent shutdown complete")
211+
return nil
212+
}
213+
return err
201214
}
202215

203216
const defaultMinConnectTimeout = 20 * time.Second
@@ -492,6 +505,7 @@ enactmentSwitch:
492505

493506
case *configpb.SdnAgent_EnactmentDriver_Snmp:
494507
fmt.Print("TODO: SdnAgent_EnactmentDriver_Snmp")
508+
495509
case *configpb.SdnAgent_EnactmentDriver_Dynamic:
496510
dialOpts, err := getDialOpts(ctx, node.EnactmentDriver.GetConnectionParams(), clock)
497511
if err != nil {

agent/internal/configpb/config.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ message SnmpObject {
221221

222222
// An SDN agent, controlling any number of commandable elements.
223223
message SdnAgent {
224+
224225
// An external command is a delegate process that handles implementing some
225226
// aspect of the SBI contract. Exit codes within the range of the canonical
226227
// gRPC status codes will be transformed (alongside any messages written to
@@ -276,6 +277,7 @@ message SdnAgent {
276277
// E2 enactment driver configuration (currently empty, for future use).
277278
message E2Enactment {
278279
}
280+
279281

280282
// An EnactmentDriver is responsible for processing incoming enactments for
281283
// a given node.
@@ -293,6 +295,7 @@ message SdnAgent {
293295
// SNMPv3 for enactments
294296
SnmpEnactment snmp = 5;
295297

298+
296299
// Use an agent-specific driver to process enactments.
297300
google.protobuf.Any dynamic = 4;
298301

@@ -327,7 +330,7 @@ message SdnAgent {
327330
// How often the metrics will be gathered and reported.
328331
google.protobuf.Duration collection_period = 3;
329332

330-
// The port on which the metrics will be scrapable as Prometheus metrics
333+
// The port on which the metrics will be scrapable as Prometheus metrics.
331334
int32 prometheus_port = 4;
332335
}
333336

@@ -363,6 +366,7 @@ message SdnAgent {
363366
// Use SNMPv3 GET calls to gather telemetry.
364367
SnmpTelemetry snmp = 5;
365368

369+
366370
// Use an agent-specific driver to gather telemetry.
367371
google.protobuf.Any dynamic = 4;
368372

agent/node_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ func (a *Agent) newNodeController(node *node, done func()) (*nodeController, err
8080
}
8181
nc.closers = append(nc.closers, telemetryConn.Close)
8282

83+
// If the telemetry driver implements io.Closer, register it for cleanup
84+
if closer, ok := node.td.(interface{ Close() error }); ok {
85+
nc.closers = append(nc.closers, closer.Close)
86+
}
87+
8388
telemetryClient := telemetrypb.NewTelemetryClient(telemetryConn)
8489

8590
ts := nc.newTelemetryService(telemetryClient, node.td)

agent/telemetry/periodic_driver.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,12 @@ func (pd *PeriodicDriver) Run(
8484
}
8585
}
8686
}
87+
88+
// Close shuts down the PeriodicDriver. If the underlying ReportGenerator
89+
// implements Close() error, it will be called for cleanup.
90+
func (pd *PeriodicDriver) Close() error {
91+
if closer, ok := pd.ReportGenerator.(interface{ Close() error }); ok {
92+
return closer.Close()
93+
}
94+
return nil
95+
}

0 commit comments

Comments
 (0)