Move CreateIngress to IOInfoService. Adopt UpdateIngressStare from IOInfoService instead of IngressService (#2485)

When paired with an updated ingress service, this will cause CreateIngress to be called twice for URL pull ingress, with the 2nd call failing.
This commit is contained in:
Benjamin Pracht
2024-02-15 14:00:25 -08:00
committed by GitHub
parent d216f94ac1
commit 8d7257dd19
8 changed files with 301 additions and 96 deletions
+8 -77
View File
@@ -16,7 +16,6 @@ package service
import (
"context"
"errors"
"google.golang.org/protobuf/types/known/emptypb"
@@ -78,6 +77,14 @@ func (s *IOInfoService) Start() error {
return nil
}
func (s *IOInfoService) Stop() {
close(s.shutdown)
if s.ioServer != nil {
s.ioServer.Shutdown()
}
}
func (s *IOInfoService) CreateEgress(ctx context.Context, info *livekit.EgressInfo) (*emptypb.Empty, error) {
// check if egress already exists to avoid duplicate EgressStarted event
if _, err := s.es.LoadEgress(ctx, info.EgressId); err == nil {
@@ -156,79 +163,3 @@ func (s *IOInfoService) UpdateMetrics(ctx context.Context, req *rpc.UpdateMetric
)
return &emptypb.Empty{}, nil
}
func (s *IOInfoService) GetIngressInfo(ctx context.Context, req *rpc.GetIngressInfoRequest) (*rpc.GetIngressInfoResponse, error) {
info, err := s.loadIngressFromInfoRequest(req)
if err != nil {
return nil, err
}
return &rpc.GetIngressInfoResponse{Info: info}, nil
}
func (s *IOInfoService) loadIngressFromInfoRequest(req *rpc.GetIngressInfoRequest) (info *livekit.IngressInfo, err error) {
if req.IngressId != "" {
info, err = s.is.LoadIngress(context.Background(), req.IngressId)
} else if req.StreamKey != "" {
info, err = s.is.LoadIngressFromStreamKey(context.Background(), req.StreamKey)
} else {
err = errors.New("request needs to specify either IngressId or StreamKey")
}
return info, err
}
func (s *IOInfoService) UpdateIngressState(ctx context.Context, req *rpc.UpdateIngressStateRequest) (*emptypb.Empty, error) {
info, err := s.is.LoadIngress(ctx, req.IngressId)
if err != nil {
return nil, err
}
if err = s.is.UpdateIngressState(ctx, req.IngressId, req.State); err != nil {
logger.Errorw("could not update ingress", err)
return nil, err
}
if info.State.Status != req.State.Status {
info.State = req.State
switch req.State.Status {
case livekit.IngressState_ENDPOINT_ERROR,
livekit.IngressState_ENDPOINT_INACTIVE,
livekit.IngressState_ENDPOINT_COMPLETE:
s.telemetry.IngressEnded(ctx, info)
if req.State.Error != "" {
logger.Infow("ingress failed", "error", req.State.Error, "ingressID", req.IngressId)
} else {
logger.Infow("ingress ended", "ingressID", req.IngressId)
}
case livekit.IngressState_ENDPOINT_PUBLISHING:
s.telemetry.IngressStarted(ctx, info)
logger.Infow("ingress started", "ingressID", req.IngressId)
case livekit.IngressState_ENDPOINT_BUFFERING:
s.telemetry.IngressUpdated(ctx, info)
logger.Infow("ingress buffering", "ingressID", req.IngressId)
}
} else {
// Status didn't change, send Updated event
info.State = req.State
s.telemetry.IngressUpdated(ctx, info)
logger.Infow("ingress updated", "ingressID", req.IngressId, "status", info.State.Status)
}
return &emptypb.Empty{}, nil
}
func (s *IOInfoService) Stop() {
close(s.shutdown)
if s.ioServer != nil {
s.ioServer.Shutdown()
}
}