fix(channelext): bound the extension broker server with service limits

This commit is contained in:
sam committed 2026-10-25 22:46:47 +11:00
1 parent edffc529dd
commit b7c22c5002
2 files changed
+9 -5

No files matched your search

@@ -10,6 +10,7 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/samcharles93/archie-core/internal/app/servicekit"
"github.com/samcharles93/archie-core/internal/channels"
"github.com/samcharles93/archie-core/internal/domain/storepkg"
"github.com/samcharles93/archie-core/internal/infrastructure/channelext"
@@ -94,5 +95,5 @@ func buildExtensionChannel(ctx context.Context, host *extension.Host, source ext
resolved[name] = secretValue
}
spec := extension.Spec{Name: "channel/" + pkg.Name, Path: binary, SHA256: sum, Env: slices.Clone(pkg.AcceptedAuthority.Env), Egress: slices.Clone(pkg.AcceptedAuthority.EgressHosts)}
return channelext.New(host, pkg.Name, spec, plain, resolved), nil
return channelext.New(host, pkg.Name, spec, plain, resolved, servicekit.ServerLimits()), nil
}
@@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
"slices"
goplugin "github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
@@ -55,12 +56,14 @@ type Channel struct {
spec extension.Spec
settings map[string]string
secrets map[string]string
limits []grpc.ServerOption
}
// New returns a Channel that launches spec on Start. secrets are the resolved
// values of the settings' _ref entries.
func New(host *extension.Host, name string, spec extension.Spec, settings, secrets map[string]string) *Channel {
return &Channel{name: name, host: host, spec: spec, settings: settings, secrets: secrets}
// values of the settings' _ref entries. limits bound the broker server the
// extension dials back into, as on every service server.
func New(host *extension.Host, name string, spec extension.Spec, settings, secrets map[string]string, limits []grpc.ServerOption) *Channel {
return &Channel{name: name, host: host, spec: spec, settings: settings, secrets: secrets, limits: limits}
}
func (c *Channel) Name() string { return c.name }
@@ -81,7 +84,7 @@ func (c *Channel) Start(ctx context.Context, chat messaging.ChatContract, lifecy
id := ext.broker.NextId()
go ext.broker.AcceptAndServe(id, func(opts []grpc.ServerOption) *grpc.Server {
server := grpc.NewServer(opts...)
server := grpc.NewServer(append(slices.Clone(c.limits), opts...)...)
gatewayrpc.RegisterServer(server, restricted{chat}, nil, gatewayrpc.Catalog{})
return server
})