Add "key: value" pair to determine if pipeline is parent or child
In order to display a pipeline graph the backend serializes the pipeline data including triggered_pipelines array and triggered_by_pipeline object.
-
triggered_pipelinescontains all downstream pipelines from the given pipeline being displayed -
triggered_by_pipelinecontain the upstream pipeline from the given pipeline being displayed
Prior to introducing parent/child pipelines all upstream and downstream pipelines were cross-project. With parent/child pipelines we have:
- child pipeline is a type of downstream pipeline having the same project of the referenced pipeline
- parent pipeline is a type of upstream pipeline having the same project of the referenced pipeline
In order to display a Child or Parent label (in the frontend) beside each upstream or downstream pipeline, the frontend is currently comparing the project.id field of the pipeline being displayed with the project.id of the object in triggered_pipelines or triggered_by_pipeline. If the project.ids match, then we are in presence of either child or parent pipeline. If they don't match we have cross-project downstream or upstream pipelines.
Problem statement
Comparing project.ids in the frontend is not a good design choice because it leaks domain specific information to the UI layer. We should instead provide this information from the backend when we serialize the pipeline data for the graph.
The objects in triggered_pipelines or triggered_by_pipeline should contain 2 flags:
parent: true/false,
child: true/false
- If
parent: true, the frontend displaysParentlabel for the pipeline intriggered_by_pipeline - If
child: true, the frontend displaysChildlabel for the pipeline intriggered_pipelines - Otherwise no labels are displayed
-
parent: trueshould never appear intriggered_pipelines(downstream) -
child: trueshould never appear intriggered_by_pipeline(upstream)
Alternatively we could have a single attribute that can have multiple values (whatever makes sense also from performance perspective):
pipeline_relationship: (child|parent|upstream-cross-project|downstream-cross-project|nil)
Challenges
The main challenge in implementing this is to do it in a performant way. Adding check if the pipeline is child or parent and serialize that information introduces N+1 queries as each downstream pipeline has to check whether it's parent and whether it's child.
Ideally we should pass the main (currently displayed) pipeline object when serializing each triggered_pipelines and triggered_by_pipeline so that we can directly compare them to the main pipeline rather than checking for the existence of child/parent pipelines for each of them.