context propagation: pkg/apiserver (#3272)

* context propagation: apic.Push()

* context propagation: NewServer()

* lint
This commit is contained in:
mmetc 2024-10-09 13:06:03 +02:00 committed by GitHub
parent 40021b6bcf
commit b9bccfa56f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 59 additions and 61 deletions

View file

@ -159,11 +159,9 @@ func newGinLogger(config *csconfig.LocalApiServerCfg) (*log.Logger, string, erro
// NewServer creates a LAPI server.
// It sets up a gin router, a database client, and a controller.
func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) {
func NewServer(ctx context.Context, config *csconfig.LocalApiServerCfg) (*APIServer, error) {
var flushScheduler *gocron.Scheduler
ctx := context.TODO()
dbClient, err := database.NewClient(ctx, config.DbConfig)
if err != nil {
return nil, fmt.Errorf("unable to init database client: %w", err)
@ -300,8 +298,8 @@ func (s *APIServer) Router() (*gin.Engine, error) {
return s.router, nil
}
func (s *APIServer) apicPush() error {
if err := s.apic.Push(); err != nil {
func (s *APIServer) apicPush(ctx context.Context) error {
if err := s.apic.Push(ctx); err != nil {
log.Errorf("capi push: %s", err)
return err
}
@ -337,7 +335,7 @@ func (s *APIServer) papiSync() error {
}
func (s *APIServer) initAPIC(ctx context.Context) {
s.apic.pushTomb.Go(s.apicPush)
s.apic.pushTomb.Go(func() error { return s.apicPush(ctx) })
s.apic.pullTomb.Go(func() error { return s.apicPull(ctx) })
// csConfig.API.Server.ConsoleConfig.ShareCustomScenarios