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

Use deltas in GScan #543

Merged
merged 13 commits into from
Jul 5, 2021
Merged

Use deltas in GScan #543

merged 13 commits into from
Jul 5, 2021

Conversation

kinow
Copy link
Member

@kinow kinow commented Nov 29, 2020

These changes close a lot of issues, listed below. Do not worry about assigning to me, setting milestone, etc. After the final review, and when this issue is closed, then I will go through each issue linked below, will assign and set the milestone 👍

Requirements check-list

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Already covered by existing tests.
  • Appropriate change log entry included.
  • No documentation update required.

Notes from discussions on Element and comments here:

  • we can use stateTotals to retrieve the states in the workflow, with their count too
  • when showing states, we need to filter the ones that are applicable to job (i.e. filter with the JobStatus enum!)
  • we can handle when workflows are moved/renamed

@kinow kinow added this to the 0.3 milestone Nov 29, 2020
@kinow kinow self-assigned this Nov 29, 2020
@codecov-io

This comment has been minimized.

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@kinow kinow marked this pull request as ready for review December 6, 2020 19:43
@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@oliver-sanders
Copy link
Member

oliver-sanders commented Dec 10, 2020

And from what I remember, we are not able to merge deltas subscriptions.

Yeah, it gets messy. Conceptually it's easy:

subs:
    1: {a, b, {c}}
    2: {a: {d}}

incoming delta:
   {A, {C}}

internal deltas:
    1: {A, {C}}
    2: {A}

But in practice GraphQL isn't that abstract, need to spend some time on this one soonish to see if it's achievable easily. It's filters that really mess it up, e.g. filtering by task state but I guess that could be handled in a simple dumb manner just merging what we can:

subs:
    1:
        filters: {workflow: 'workflows: ["five"]' taskProxy: 'state: ["failed"]'}
        sub: {a, b, {c}}
    2:
        filters: {workflow: 'workflows: ["six"]'}
        sub: {a, {d}}

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@oliver-sanders
Copy link
Member

oliver-sanders commented Dec 14, 2020

GScan doesn't seem to respond to the addition or removal of stopped workflows. I think it might not be responding to the full range of flow change events. Perhaps we need to add more info to the deltas?

Steps to reproduce:

  1. Create a workflow called five (but don't run it).
  2. Load the UI, you should see it in the sidebar.
  3. Rename five -> six.

The five flow should disappear and six should be added.

Something strange is happening in the dashboard too which might be related. The number of stopped workflows keeps flickering between two

10
different values.

2

I think one matches the number visible in GScan (correct when the page loaded) and the other matches the current number of flows.

@kinow
Copy link
Member Author

kinow commented Dec 14, 2020

Oh, never thought about renaming workflows. The UIS probably doesn't send a message telling the UIS to remove that workflow, or if does, I think the UI doesn't handle that 😥

The old code, that is not deltas-based, would handle that as it always re-rendered the whole list, so I think we can't push that to a follow-up. Will have to think about this one and confirm whether there's a solution in the UI. Otherwise will create and link an issue in UIS.

Thanks for the testing @oliver-sanders !

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

@kinow

This comment has been minimized.

Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

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

Made it to the end 😓.

Looks great, the queries and subs are nicely centralised and the mixins should make view development easier 👍.

Still need to dive into the subscription merging (unexpected bonus 🎉). To help me review this could you comment about what the subscription merging is supposed to merge and what it isn't (i.e. what subscriptions we should expect to have for different views).

Still need to do some hands on testing with:

  • Lookup / tree structures.
  • Subscription merging.
  • Delta processing.

I have only found a couple of small snags so far which are to do with the life cycle of subscriptions.

Here's the diff I used for testing (you may need to correct me if my method is wrong):

diff --git a/src/services/workflow.service.js b/src/services/workflow.service.js
index 455f60e8..ccdf521c 100644
--- a/src/services/workflow.service.js
+++ b/src/services/workflow.service.js
@@ -203,6 +203,8 @@ class WorkflowService {
     } catch (e) {
       subscription.handleViewState(ViewState.ERROR, e)
     }
+
+    console.warn('# START', this.subscriptions)
   }
 
   /**
@@ -271,6 +273,7 @@ class WorkflowService {
       store.dispatch(actionName).then(() => {})
     })
     delete this.subscriptions[subscription.query.name]
+    console.warn('# STOP', this.subscriptions)
   }
 
   // --- Merging GraphQL queries...

Note: This logs the subscriptions AFTER a subscription has been started or stopped.

And here are my results:

Experiment 1: Move from the Dashboard to workflow page.

The "root" subscription is cancelled and re-started causing GScan to flicker.

Screenshot 2021-06-28 at 15 52 38

Experiment 2: Open new tree views

(Note: to replicate this I had to start on the Dashboard page)

The "root" subscription is canceled and re-started.

Screenshot 2021-06-28 at 15 57 59

src/components/cylc/gscan/GScan.vue Show resolved Hide resolved
src/components/cylc/gscan/GScan.vue Outdated Show resolved Hide resolved
src/components/cylc/gscan/WorkflowIcon.vue Show resolved Hide resolved
src/components/cylc/tree/deltas.js Show resolved Hide resolved
src/components/cylc/tree/index.js Outdated Show resolved Hide resolved
src/store/workflows.module.js Outdated Show resolved Hide resolved
src/views/Dashboard.vue Show resolved Hide resolved
src/views/Guide.vue Show resolved Hide resolved
src/views/Workflow.vue Show resolved Hide resolved
src/views/Workflow.vue Show resolved Hide resolved
@kinow
Copy link
Member Author

kinow commented Jun 29, 2021

Having some spare time this week after the work on this PR, and don't want to add more PR's that will cause this PR to have to be rebased or its merge delayed. So decided to cover a part of the new code that I thought wasn't too important to add tests initially (but doesn't hurt to have more tests right :) Last commit only includes a handful new unit tests, no changes to the code.

@kinow
Copy link
Member Author

kinow commented Jun 30, 2021

Here's the diff I used for testing (you may need to correct me if my method is wrong):

@oliver-sanders I think your diff is correct. And the results of your test look correct to me. Initially, I re-used the GScan query for Dashboard & WorkflowTables. Which resulted in less subscriptions being stopped and started again, but then I thought it would be best to keep things as they are for now, and focus on getting the GScan component and the subscriptions in place first, leaving a few teaks like this one for later.

Probably to be addressed when we work on the new issues for query merging after this PR.

@oliver-sanders
Copy link
Member

oliver-sanders commented Jun 30, 2021

I think the first example requires some extra logic to handle nicely (suggestion below), the second example (opening a new tree view) looks like a bug on this branch causing the root sub to be cancelled when trying to add a workflow sub?

Perhaps the solution to the first issue is to make the "unregister subscription" logic schedule a callback rather than cancelling the sub straight away. The callback can then check whether any new view has subscribed to the sub in the mean time.

This way the GScan subscription wouldn't get cancelled. This leads onto the idea of keeping workflow subs active for a configured period so that users can switch back and forth between workflows with minimum waiting. Related to #392.

@kinow
Copy link
Member Author

kinow commented Jun 30, 2021

looks like a bug on this branch causing the root sub to be cancelled when trying to add a workflow sub?

I thought the root subscription had been cancelled because the Dashboard query had been removed, resulting in a call to recompute and then triggering the stop/start in the subscription.

I will take a look tomorrow, but you are correct, it's supposed to stop root only iff the root's query changed, not because of any changes to the workflow query.

@oliver-sanders oliver-sanders mentioned this pull request Jun 30, 2021
6 tasks
@kinow
Copy link
Member Author

kinow commented Jun 30, 2021

@oliver-sanders found the bug that was causing the GScan root subscription to be stopped and started again! The subscription was marked as reload = true because of the merge of GScan + Dashboard queries.

The issue was that I was never setting reload = false 😅

Fixed, and found another bug where I was not saving the result of union's of collections. Fix is really small, but I will probably need a bit more of time to write tests for these 2 issues I just found, to prevent them from happening again 👍

Thanks!!!

@kinow
Copy link
Member Author

kinow commented Jul 1, 2021

Done! If tests pass in CI, it should not stop/start the root subscription when going from Dashboard to the Tree view or Workflow with Tree view 👍

@oliver-sanders
Copy link
Member

oliver-sanders commented Jul 1, 2021

Brilliant that fixes both of my scenarios 💯 .

Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

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

Great 🍾, really nice code, should give us a pattern to grow into.

@kinow
Copy link
Member Author

kinow commented Jul 1, 2021

Thanks @oliver-sanders !

@hjoliver
Copy link
Member

hjoliver commented Jul 5, 2021

I'm having a good play with this, probably can't improve on @oliver-sanders ' thorough review. Looks great so far, massive effort to close so many issues, thanks @kinow 💐

Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

Very nice 👍

@hjoliver hjoliver merged commit 57c69de into cylc:master Jul 5, 2021
@kinow kinow deleted the gscan-deltas branch July 5, 2021 03:22
kinow added a commit to kinow/cylc-ui that referenced this pull request Jul 5, 2021
kinow added a commit to kinow/cylc-ui that referenced this pull request Jul 5, 2021
@kinow kinow mentioned this pull request Jul 5, 2021
6 tasks
hjoliver pushed a commit that referenced this pull request Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment