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

fix: pause child monitors if parent is paused #5193

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

julian-piehl
Copy link
Contributor

@julian-piehl julian-piehl commented Oct 12, 2024

⚠️⚠️⚠️ Since we do not accept all types of pull requests and do not want to waste your time. Please be sure that you have read pull request rules:
https://github.com/louislam/uptime-kuma/blob/master/CONTRIBUTING.md#can-i-create-a-pull-request-for-uptime-kuma

Tick the checkbox if you understand [x]:

  • I have read and understand the pull request rules.

Description

Currently if a group is paused, the children will be shown as paused, but they are not. I fixed this behavior.
Also shows groups as pending if all childs are paused (idea from #4663).

Fixes #4696

Type of change

Please delete any options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • User interface (UI)

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and tested it
  • I have commented my code, particularly in hard-to-understand areas (including JSDoc for methods)
  • My changes generates no new warnings
  • My code needed automated testing. I have added them (this is optional task)

Screenshots (if any)

Please do not use any external image service. Instead, just paste in or drag and drop the image here, and it will be uploaded automatically.

@julian-piehl
Copy link
Contributor Author

There seems to be another bug.
If you pause a group, the children won't be shown as paused directly. Only after reloading.
I can't find a fix for that. Sometime ago it worked as it should.

@julian-piehl
Copy link
Contributor Author

There seems to be another bug. If you pause a group, the children won't be shown as paused directly. Only after reloading. I can't find a fix for that. Sometime ago it worked as it should.

Not sure if its a good solution, but its fixed.

@julian-piehl
Copy link
Contributor Author

There seems to be another bug. If you pause a group, the children won't be shown as paused directly. Only after reloading. I can't find a fix for that. Sometime ago it worked as it should.

I've reverted the fix to this bug, because I found some more problems regarding this and moved it to MR #5196.

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

This logic seems a bit slow as it includes a lot of steps that all happen in a series.
We should be able to merge this into one one database query or at least a significantly more sane amount than 3 (you are currently missing setting the active field for children) per child recursively.

What about a recursive CTE instead?

WITH RECURSIVE monitor_ids_to_pause(id) as (
  SELECT m.id
  FROM monitor m
  WHERE m.id = ? AND m.active = true
  UNION
  SELECT m.id
  FROM monitor_ids_to_pause r, monitor m
  WHERE m.parent = r.id AND m.active = true
)
SELECT * FROM monitor_ids_to_pause;

The call to Monitor.stop() should also be in a Promise.all(..) to make sure that this adding the async code there does not cause a performance problem.

@julian-piehl
Copy link
Contributor Author

This logic seems a bit slow as it includes a lot of steps that all happen in a series. We should be able to merge this into one one database query or at least a significantly more sane amount than 3 (you are currently missing setting the active field for children) per child recursively.

What about a recursive CTE instead?

I improved the efficiency of database queries in multiple locations concerning groups and recursion. Please take a moment to review these changes to ensure they meet your expectations and do not introduce any new bugs.

The call to Monitor.stop() should also be in a Promise.all(..) to make sure that this adding the async code there does not cause a performance problem.

I implemented these changes for both Monitor.start() and Monitor.stop(). However, I'm not sure if it should be used in Monitor.start(), considering the comment in startMonitors().
https://github.com/louislam/uptime-kuma/blob/master/server/server.js#L1808-L1809
What do you think about this aspect?

you are currently missing setting the active field for children

I don't believe that the active field should be set for child monitors, as the isParentActive method is specifically designed for this purpose. Using this method ensures that the activity status is correctly determined based on the parent monitor, maintaining the intended functionality.
https://github.com/louislam/uptime-kuma/blob/master/server/model/monitor.js#L1550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:monitor Everything related to monitors pr:please address review comments this PR needs a bit more work to be mergable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[groups] pausing groups does show children as paused without pausing them
2 participants