Skip to content

Commit

Permalink
apiserver: report online gateways every 5 sec
Browse files Browse the repository at this point in the history
  • Loading branch information
sechmann committed Jun 10, 2024
1 parent 5721027 commit e5b39ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 12 additions & 0 deletions cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,18 @@ func run(log *logrus.Entry, cfg config.Config) error {
cancel()
}()

go func() {
ticker := time.NewTicker(5 * time.Second)
for ctx.Err() == nil {
select {
case <-ctx.Done():
return
case <-ticker.C:
grpcHandler.ReportOnlineGateways()
}
}
}()

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
Expand Down
6 changes: 1 addition & 5 deletions internal/apiserver/api/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ func (s *grpcServer) GetGatewayConfiguration(request *pb.GetGatewayConfiguration
s.log.Infof("Gateway %s connected (%d active gateways)", request.Gateway, len(s.gatewayConfigTrigger))
s.gatewayConfigTriggerLock.Unlock()

s.reportOnlineGateways()

for {
select {
case <-c:
Expand All @@ -53,8 +51,6 @@ func (s *grpcServer) GetGatewayConfiguration(request *pb.GetGatewayConfiguration
s.log.Infof("Gateway %s disconnected (%d active gateways)", request.Gateway, len(s.gatewayConfigTrigger))
s.gatewayConfigTriggerLock.Unlock()

s.reportOnlineGateways()

return nil
}
}
Expand Down Expand Up @@ -95,7 +91,7 @@ func (s *grpcServer) MakeGatewayConfiguration(ctx context.Context, gatewayName s
return gatewayConfig, nil
}

func (s *grpcServer) reportOnlineGateways() {
func (s *grpcServer) ReportOnlineGateways() {
s.gatewayConfigTriggerLock.RLock()
connectedGatewayNames := make([]string, 0, len(s.gatewayConfigTrigger))
for k := range s.gatewayConfigTrigger {
Expand Down

0 comments on commit e5b39ed

Please sign in to comment.