Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions controller/getchangedtargets.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ type job struct {
cancel context.CancelFunc
}

// GetChangedTargets returns the changed targets between two revisions.
// GetChangedTargets returns the changed targets between two revisions. If the client disconnects, the context will be cancelled, and the function returns with context.ErrCancelled.
func (c *controller) GetChangedTargets(request *pb.GetChangedTargetsRequest, stream pb.TangoServiceGetChangedTargetsYARPCServer) error {
ctx := context.Background()
// Use the stream from the context as a parent context for the request. If the client disconnects, the context will be cancelled.
ctx := stream.Context()
if err := validateGetChangedTargetsRequest(request); err != nil {
c.logger.Error("GetChangedTargets: Invalid request", zap.Error(err))
return err
Expand Down Expand Up @@ -179,12 +180,35 @@ func (c *controller) compareTargetGraphs(ctx context.Context, firstGraph, second

// 1) Extract targets and metadata; index by canonical names
firstTargetsByID, firstMetadata := getTargetsAndMetadata(firstGraph)

if ctx.Err() != nil {
return nil, ctx.Err()
}

secondTargetsByID, secondMetadata := getTargetsAndMetadata(secondGraph)

if ctx.Err() != nil {
return nil, ctx.Err()
}

firstByName := buildNameIndex(firstTargetsByID, firstMetadata)

if ctx.Err() != nil {
return nil, ctx.Err()
}

secondByName := buildNameIndex(secondTargetsByID, secondMetadata)

if ctx.Err() != nil {
return nil, ctx.Err()
}

sourceFileRuleTypeID := detectSourceFileID(secondMetadata)

if ctx.Err() != nil {
return nil, ctx.Err()
}

// 2) Build newTargetsMap and processing order (source files first if present)
newTargetsMap := make(map[string]*pb.OptimizedTarget, len(secondByName))
for name, t := range secondByName {
Expand Down Expand Up @@ -271,6 +295,10 @@ func (c *controller) compareTargetGraphs(ctx context.Context, firstGraph, second
}
}

if ctx.Err() != nil {
return nil, ctx.Err()
}

// Iterate over the changed targets and check if any of them are DIRECT changes.
for name, ct := range changedByName {
if ct.GetChangeType() == pb.CHANGE_TYPE_DIRECT || ct.GetChangeType() == pb.CHANGE_TYPE_NEW {
Expand Down Expand Up @@ -305,11 +333,19 @@ func (c *controller) compareTargetGraphs(ctx context.Context, firstGraph, second
}
}

if ctx.Err() != nil {
return nil, ctx.Err()
}

// Compute BFS distances from CHANGE_TYPE_DIRECT targets through the dependency graph.
if outputConfig.GetComputeDistances() {
computeDistances(c.logger, changedByName, secondByName, secondMetadata)
}

if ctx.Err() != nil {
return nil, ctx.Err()
}

// TODO: https://github.com/uber/tango/issues/34
// only return changed targets changed within x distance from a direct target

Expand Down
Loading