Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update pipelinerun graph to show past pipeline structure #6960

Merged

Conversation

karthikjeeyar
Copy link
Contributor

Fixes: https://issues.redhat.com/browse/ODC-2302

Description:
As a user, I would like to be able to view my past Pipeline Run visualization graphs without them being impacted by my current Pipeline status.

Problem:
Pipeline visualization component was always fetching the tasks from the current pipeline.

Solution:
Visualization component now uses the tasks from the pipelinerun.status.pipelineSpec field, which holds the reference of the pipeline at the time of execution. As a fallback, we still read from the pipeline if this pipelinerun.status.pipelineSpec field is not available.

Screenshots:
pipelinerun-graph

Test cases:
image

cc: @siamaksade @andrewballantyne
/kind feature

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 20, 2020
@openshift-ci-robot openshift-ci-robot added the component/dev-console Related to dev-console label Oct 20, 2020
@jerolimov
Copy link
Member

/retest

Copy link
Member

@jerolimov jerolimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this locally, works as expected

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 21, 2020
Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I don't think we need to keep the dependancy on Pipeline. It is true that 1.0.1 of the Operator does still require it but based on the Compatibility Matrix 4.7 is going to be a far cry away from upstream Pipelines not having this feature (which was added in 0.12).

For sanity for the customer's cluster, I think we could go back 1 (1.2) or even more safety 2 (1.1) versions and still give that support so they are not getting a broken UI immediately after upgrading but not changing their channel. If memory serves correctly, when the Operator updates to give us an ocp-4.7 channel, they'll remove the ocp-4.5 channel. Which will remove any chance for unsupported code to exist.

The easiest approach to solving this ask I think is to just remove the requirement of Pipeline from getExecutedPipeline (see my comment below to get you started).

Comment on lines 405 to 452
export const getExecutedPipeline = (pipeline: Pipeline, pipelineRun: PipelineRun): Pipeline => {
return {
...pipeline,
...(pipelineRun?.status?.pipelineSpec && { spec: pipelineRun?.status?.pipelineSpec }),
};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to do two things here:

  1. Remove the dependancy on Pipeline and trim it out along all the call paths (I just did this and it's quite a bit of changes and adjustments, no references to Pipeline should exist in the call paths)
  2. Rename it to something like (don't have to take this if you have something better) getPipelineFromPipelineRun

Tests will need to be updated naturally when this happens, since getTaskStatus heavily uses Pipeline. We may even need to update the test data to add pipelineSpec (which should be a mirror - maybe break that out to a var? - of the pipeline.spec used in the same data structure)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the pipeline dependency in the call paths, updated test data and tests as well.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Nov 3, 2020
Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more touch ups please.

return <PipelineVisualization pipeline={pipeline} pipelineRun={pipelineRun} />;
return (
<PipelineVisualization
pipeline={getPipelineFromPipelineRun(pipelineRun) || pipeline}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a PipelineRun visualization, it never needs the Pipeline, let's kill the fetch call for it.

@@ -22,7 +22,7 @@ const PipelineBuildDecoratorTooltip: React.FC<PipelineBuildDecoratorTooltipProps
return null;
}

const taskStatus = getTaskStatus(pipeline.latestRun, pipeline);
const taskStatus = getTaskStatus(pipeline.latestRun);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, wonder if we want to just remove the Pipeline from this data and just handle the PipelineRun as the Decorator is only really reading the PipelineRun information.

The caller of this component is build-decorator-utils and that creates a currentPipelineStatus that contains currentPipeline which is the pipeline in the above line. I believe my metholodolgy when I wrote it was to manage the standard Pipeline + .latestRun as a single param, instead of handling two variables Pipeline and PipelineRun.

This is all to say, I think we can change currentPipelineStatus to just have the PipelineRun, as nothing else really needs the Pipeline.

The work Divyanshi is doing for the "not started" icon and text is based around having a Pipeline but not having a PipelineRun. So I think we are safe on that front.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the pipeline dependency here.

@@ -35,7 +35,216 @@ type CombinedPipelineTestData = {
};

type PipelineTestData = { [key in PipelineExampleNames]?: CombinedPipelineTestData };

const pipelineSpec = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const pipelineSpec = {
type PipelineSpecData = { [key in PipelineExampleNames]?: PipelineSpec };
const pipelineSpec: PipelineSpecData = {

Comment on lines 39 to 54
status: { creationTimestamp: '31', conditions: [{ type: 'Succeeded', status: 'True' }] },
status: {
pipelineSpec: { tasks: [] },
creationTimestamp: '31',
conditions: [{ type: 'Succeeded', status: 'True' }],
},
},
{
apiVersion: 'abhiapi/v1',
kind: 'Pipeline',
metadata: { name: 'dragonstone', namespace: 'corazon' },
spec: { pipelineRef: { name: 'danaerys-targaeryen' } },
status: { creationTimestamp: '31', conditions: [{ type: 'Succeeded', status: 'Unknown' }] },
status: {
pipelineSpec: { tasks: [] },
creationTimestamp: '31',
conditions: [{ type: 'Succeeded', status: 'Unknown' }],
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is duplicate data from frontend/packages/dev-console/src/components/pipelines/modals/common/__tests__/utils.spec.ts 😞

Think we could move this data into pipeline-data.ts and then import it back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this mock data and used the data from pipeline-data.ts and also refactored utils.spec.ts to avoid duplication of mock data.

return null;
}
return {
apiVersion: PipelineModel.apiVersion,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apiVersion: PipelineModel.apiVersion,
apiVersion: apiVersionForModel(PipelineModel),

Awkward, I know... but apiVersion in the Model is actually the version, whereas the K8s CR is the "group + version".

const totalTasks =
pipeline && pipeline.spec && pipeline.spec.tasks ? pipeline.spec.tasks.length : 0;
export const getPipelineFromPipelineRun = (pipelineRun: PipelineRun): Pipeline => {
if (!pipelineRun?.status?.pipelineSpec) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably possible to pass in a inlineSpec for Pipeline, can we also check to see if the label for Pipeline is here on the PipelineRun?

Suggested change
if (!pipelineRun?.status?.pipelineSpec) {
const pipelineName = pipelineRun.metadata.labels[TektonResourceLabel.pipeline];
if (!pipelineName || !pipelineRun?.status?.pipelineSpec) {

apiVersion: PipelineModel.apiVersion,
kind: PipelineModel.kind,
metadata: {
name: pipelineRun.metadata[TektonResourceLabel.pipeline],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Shouldn't this be pipelineRun.metadata.labels?

Suggested change
name: pipelineRun.metadata[TektonResourceLabel.pipeline],
name: pipelineRun.metadata.labels[TektonResourceLabel.pipeline],

Also, perhaps make use of the variable based on my last comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be. updated.

},
};
const executedPipeline = getPipelineFromPipelineRun(plrWithOneTask);
expect(currentPipeline.spec.tasks).toHaveLength(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weird expect... you're not testing data you used to deliver the test of getPipelineFromPipelineRun you trimmed it out on 324 to being only the first one. What is this expect doing other than testing you have data that has 2 points (which is a bit odd of a test)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I Agree, after the pipeline dependancy removal this test wasn't serving the purpose. So i updated it now.

const executedPipeline = getPipelineFromPipelineRun(plrWithOneTask);
expect(currentPipeline.spec.tasks).toHaveLength(2);
expect(executedPipeline.spec.tasks).toHaveLength(1);
expect(executedPipeline).not.toEqual(currentPipeline);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused about this too... this follows my previous comment's confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test

},
pipelineTestData[PipelineExampleNames.SIMPLE_PIPELINE].pipelineRuns[DataState.SUCCESS],
pipelineTestData[PipelineExampleNames.WORKSPACE_PIPELINE].pipelineRuns[DataState.SUCCESS],
pipelineTestData[PipelineExampleNames.CLUSTER_PIPELINE].pipelineRuns[DataState.SUCCESS],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard approve of this change. Very nicely done, consolidating test data is awesome!

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 4, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 4, 2020
Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test changes, thanks for cleaning that up. Couple odd changes in the test data and one minor test needed.

Comment on lines 83 to 288
status: '',
type: 'Running',
status: 'Unknown',
type: 'Succeeded',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, this is DataState.IN_PROGRESS, you have changed it to completed... I think you're mixing data points here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted back.

completionTime: '2020-07-13T17:21:05Z',
conditions: [
{
lastTransitionTime: '2020-07-13T17:21:05Z',
message:
'Pipeline andrew/task-ref-error can\'t be Run; it contains Tasks that don\'t exist: Couldn\'t retrieve Task "not-a-task": task.tekton.dev "not-a-task" not found',
message: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you got rid of this data text? We could trim out my name for sure haha, it was log dumps when I created. We could make the message something like Test error text, but I think it shouldn't be empty... as our tests could send that data in and it be mistaken as no error text rather than just an empty error text for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While consolidating the test data, there was a test case, where it returns a static message Unknown failure condition if the message field is emtpy. For that reason i added this. I have reverted back the above one and handled the mock data in the test case itself.

@@ -328,3 +296,34 @@ describe('Pipeline exists test to determine whether a pipeline is linked to a pi
expect(pipelineFound).toBeFalsy();
});
});

describe('Pipelinerun graph to show the executed pipeline structure', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing a test for the actual result. You definitely have tested the paths to our current usage, but the method is, in isolation, just creating a Pipeline. We don't have a test to make sure it did do that. Goals of Unit Tests for functions should be to cover edge cases, any conditional paths, intended uses today and the function is performing the action it prescribes to - which in this case is making a PL CR out of the PLR CR.

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 4, 2020
@andrewballantyne
Copy link
Contributor

/retest

Looks to be a connection issue

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

6 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Nov 5, 2020
@karthikjeeyar
Copy link
Contributor Author

I rebased due to merge conflicts.

@andrewballantyne
Copy link
Contributor

/retest
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 5, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, jerolimov, karthikjeeyar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@jerolimov
Copy link
Member

/retest

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

5 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 0ff60c4 into openshift:master Nov 6, 2020
@spadgett spadgett added this to the v4.7 milestone Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/dev-console Related to dev-console kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants