Skip to content

Commit

Permalink
fix monitor
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <[email protected]>
  • Loading branch information
NikitaSkrynnik committed Oct 7, 2024
1 parent c3c0f15 commit eeef057
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
18 changes: 8 additions & 10 deletions pkg/networkservice/common/monitor/eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func newEventLoop(ctx context.Context, ec EventConsumer, cc grpc.ClientConnInter

// Create new eventLoopCtx and store its eventLoopCancel
eventLoopCtx, eventLoopCancel := context.WithCancel(ctx)

cev := &eventLoop{
eventLoopCtx: eventLoopCtx,
conn: conn,
Expand Down Expand Up @@ -91,17 +92,14 @@ func (cev *eventLoop) eventLoop() {
connOut := cev.conn.Clone()
if err != nil && connOut != nil {
// If we get an error, we've lost our connection... Send Down update
connOut := cev.conn.Clone()
if connOut != nil {
connOut.State = networkservice.State_DOWN
eventOut := &networkservice.ConnectionEvent{
Type: networkservice.ConnectionEventType_UPDATE,
Connections: map[string]*networkservice.Connection{
cev.conn.GetId(): connOut,
},
}
_ = cev.eventConsumer.Send(eventOut)
connOut.State = networkservice.State_DOWN
eventOut := &networkservice.ConnectionEvent{
Type: networkservice.ConnectionEventType_UPDATE,
Connections: map[string]*networkservice.Connection{
cev.conn.GetId(): connOut,
},
}
_ = cev.eventConsumer.Send(eventOut)
return
}
_ = cev.eventConsumer.Send(eventIn)
Expand Down
30 changes: 15 additions & 15 deletions pkg/networkservice/common/monitor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/clientconn"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/postpone"

"github.com/networkservicemesh/api/pkg/api/networkservice"

Expand Down Expand Up @@ -55,7 +58,7 @@ func NewServer(chainCtx context.Context, monitorServerPtr *networkservice.Monito
}

func (m *monitorServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
// closeCtxFunc := postpone.ContextWithValues(ctx)
closeCtxFunc := postpone.ContextWithValues(ctx)
// Cancel any existing eventLoop
cancelEventLoop, loaded := loadAndDelete(ctx, metadata.IsClient(m))
if loaded {
Expand Down Expand Up @@ -83,20 +86,17 @@ func (m *monitorServer) Request(ctx context.Context, request *networkservice.Net

// If we have a clientconn ... we must be part of a passthrough server, and have a client to pass
// events through from, so start an eventLoop
// cc, ccLoaded := clientconn.Load(ctx)
// log.FromContext(ctx).Infof("ccLoaded")
// if ccLoaded {
// log.FromContext(ctx).Infof("newEventLoop")
// cancelEventLoop, eventLoopErr := newEventLoop(m.chainCtx, m.MonitorConnectionServer.(EventConsumer), cc, conn)
// if eventLoopErr != nil {
// closeCtx, closeCancel := closeCtxFunc()
// defer closeCancel()
// _, _ = next.Client(closeCtx).Close(closeCtx, conn)
// return nil, errors.Wrap(eventLoopErr, "unable to monitor")
// }
// log.FromContext(ctx).Infof("STORE")
// store(ctx, metadata.IsClient(m), cancelEventLoop)
// }
cc, ccLoaded := clientconn.Load(ctx)
if ccLoaded {
cancelEventLoop, eventLoopErr := newEventLoop(m.chainCtx, m.MonitorConnectionServer.(EventConsumer), cc, conn)
if eventLoopErr != nil {
closeCtx, closeCancel := closeCtxFunc()
defer closeCancel()
_, _ = next.Client(closeCtx).Close(closeCtx, conn)
return nil, errors.Wrap(eventLoopErr, "unable to monitor")
}
store(ctx, metadata.IsClient(m), cancelEventLoop)
}

return conn, nil
}
Expand Down
11 changes: 3 additions & 8 deletions pkg/networkservice/common/updatepath/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,9 @@ func (i *updatePathClient) Request(ctx context.Context, request *networkservice.
return nil, err
}

segments := conn.GetPath().GetPathSegments()
if segments != nil && len(segments) > int(index) {
conn.Id = segments[index].Id
}

path := conn.GetPath()
if path != nil {
path.Index = index
if conn.GetPath() != nil && len(conn.GetPath().GetPathSegments()) > int(index) {
conn.Id = conn.GetPath().GetPathSegments()[index].Id
conn.GetPath().Index = index
}

return conn, nil
Expand Down

0 comments on commit eeef057

Please sign in to comment.