Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

control: set the highest priority for control service. #2645

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Changelog for NeoFS Node
- IR uses internal LOCODE DB from Go package (#2610)
- Contract group for the committee is no longer registered/used in the Sidechain auto-deployment (#2642)
- The priority of metrics service is increased (#2428)
- The priority of running control service is maximized (#2585)

### Removed
- deprecated `no-precheck` flag of `neofs-cli container set-eacl` (#2496)
Expand Down
7 changes: 4 additions & 3 deletions cmd/neofs-node/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@
})

control.RegisterControlServiceServer(c.cfgControlService.server, ctlSvc)

c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
c.wg.Add(1)
go func() {

Check warning on line 67 in cmd/neofs-node/control.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/control.go#L66-L67

Added lines #L66 - L67 were not covered by tests
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
runAndLog(c, "control", false, func(c *cfg) {
fatalOnErr(c.cfgControlService.server.Serve(lis))
c.wg.Done()

Check warning on line 70 in cmd/neofs-node/control.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/control.go#L70

Added line #L70 was not covered by tests
})
}))
}()
}

func (c *cfg) NetmapStatus() control.NetmapStatus {
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
}

func initApp(c *cfg) {
initAndLog(c, "control", initControlService)

Check warning on line 124 in cmd/neofs-node/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/main.go#L124

Added line #L124 was not covered by tests
initLocalStorage(c)

c.ctx, c.ctxCancel = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
Expand All @@ -139,7 +140,6 @@
initAndLog(c, "notification", initNotifications)
initAndLog(c, "object", initObjectService)
initAndLog(c, "tree", initTreeService)
initAndLog(c, "control", initControlService)

initAndLog(c, "morph notifications", listenMorphNotifications)

Expand Down
98 changes: 47 additions & 51 deletions pkg/innerring/innerring.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,53 @@
}
}

controlSvcEndpoint := cfg.GetString("control.grpc.endpoint")
if controlSvcEndpoint != "" {
authKeysStr := cfg.GetStringSlice("control.authorized_keys")
authKeys := make([][]byte, 0, len(authKeysStr))

Check warning on line 525 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L522-L525

Added lines #L522 - L525 were not covered by tests

for i := range authKeysStr {
key, err := hex.DecodeString(authKeysStr[i])
if err != nil {
return nil, fmt.Errorf("could not parse Control authorized key %s: %w",
authKeysStr[i],
err,
)

Check warning on line 533 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L527-L533

Added lines #L527 - L533 were not covered by tests
}

authKeys = append(authKeys, key)

Check warning on line 536 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L536

Added line #L536 was not covered by tests
}

lis, err := net.Listen("tcp", controlSvcEndpoint)
if err != nil {
return nil, err

Check warning on line 541 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L539-L541

Added lines #L539 - L541 were not covered by tests
}
var p controlsrv.Prm

Check warning on line 543 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L543

Added line #L543 was not covered by tests

p.SetPrivateKey(*server.key)
p.SetHealthChecker(server)

Check warning on line 546 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L545-L546

Added lines #L545 - L546 were not covered by tests

controlSvc := controlsrv.New(p,
controlsrv.WithAllowedKeys(authKeys),
)

Check warning on line 550 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L548-L550

Added lines #L548 - L550 were not covered by tests

grpcControlSrv := grpc.NewServer()
control.RegisterControlServiceServer(grpcControlSrv, controlSvc)

Check warning on line 553 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L552-L553

Added lines #L552 - L553 were not covered by tests

go func() {
errChan <- grpcControlSrv.Serve(lis)
}()

Check warning on line 557 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L555-L557

Added lines #L555 - L557 were not covered by tests

server.registerNoErrCloser(grpcControlSrv.GracefulStop)
} else {
log.Info("no Control server endpoint specified, service is disabled")

Check warning on line 561 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L559-L561

Added lines #L559 - L561 were not covered by tests
}

if cfg.GetString("prometheus.address") != "" {
m := metrics.NewInnerRingMetrics(misc.Version)
server.metrics = &m

Check warning on line 566 in pkg/innerring/innerring.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/innerring.go#L564-L566

Added lines #L564 - L566 were not covered by tests
}

// create morph listener
server.morphListener, err = createListener(server.morphClient, morphChain)
if err != nil {
Expand Down Expand Up @@ -985,57 +1032,6 @@

server.addBlockTimer(emissionTimer)

controlSvcEndpoint := cfg.GetString("control.grpc.endpoint")
if controlSvcEndpoint != "" {
authKeysStr := cfg.GetStringSlice("control.authorized_keys")
authKeys := make([][]byte, 0, len(authKeysStr))

for i := range authKeysStr {
key, err := hex.DecodeString(authKeysStr[i])
if err != nil {
return nil, fmt.Errorf("could not parse Control authorized key %s: %w",
authKeysStr[i],
err,
)
}

authKeys = append(authKeys, key)
}

var p controlsrv.Prm

p.SetPrivateKey(*server.key)
p.SetHealthChecker(server)

controlSvc := controlsrv.New(p,
controlsrv.WithAllowedKeys(authKeys),
)

grpcControlSrv := grpc.NewServer()
control.RegisterControlServiceServer(grpcControlSrv, controlSvc)

server.runners = append(server.runners, func(ch chan<- error) error {
lis, err := net.Listen("tcp", controlSvcEndpoint)
if err != nil {
return err
}

go func() {
ch <- grpcControlSrv.Serve(lis)
}()
return nil
})

server.registerNoErrCloser(grpcControlSrv.GracefulStop)
} else {
log.Info("no Control server endpoint specified, service is disabled")
}

if cfg.GetString("prometheus.address") != "" {
m := metrics.NewInnerRingMetrics(misc.Version)
server.metrics = &m
}

return server, nil
}

Expand Down
Loading