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

[groups] Put child's name in the notification, also added count of additional children #4371

Closed
wants to merge 6 commits into from

Conversation

homeautomaton
Copy link

⚠️⚠️⚠️ 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

Fixes #3278

Type of change

Please delete any options that are not relevant.

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

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.

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.

Thank you for your PR!
I have left some inline comments

@@ -383,6 +383,8 @@ class Monitor extends BeanModel {
bean.msg = "Monitor under maintenance";
bean.status = MAINTENANCE;
} else if (this.type === "group") {
let failChild = "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:
please don't hamming code variable names here.
I think downChildrenName and downChildrenCount are better names

Copy link
Author

Choose a reason for hiding this comment

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

I'll go with downChildName and failureCount

Copy link
Collaborator

Choose a reason for hiding this comment

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

names are different despite close in meaning => don't think this is good for long-term maintence

Copy link
Author

Choose a reason for hiding this comment

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

Your petulant complaints have made contributing to this project far more trouble than it is worth. Good day, sir.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we are not on the same page what the job as a maintainer is. I see it as making sure that the project can and will move in the right direction.
This does mean that the primary job is to make sure that the code stays maintainable and readable.

The job is not to blindly accept any contribution.

What might be a source of miscommunication is my usage of nit: comments. These comments can be addressed, but does not have to.

@@ -383,6 +383,8 @@ class Monitor extends BeanModel {
bean.msg = "Monitor under maintenance";
bean.status = MAINTENANCE;
} else if (this.type === "group") {
let failChild = "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to collect the DOWN-children in a list instead of doing this double accounting (last name + count).
This would allow adding this to the logging output, and I think the code might look better.

Copy link
Author

Choose a reason for hiding this comment

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

Even including the count was beyond the scope of the original request. It's simple, doesn't use any extra memory, and makes the message more informative. I'll stick with what I have.

Copy link
Collaborator

@CommanderStorm CommanderStorm Jan 16, 2024

Choose a reason for hiding this comment

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

I am not convinced that the extra memory of a few child-names will matter for overall performance/memory consumption.
Yes, my approach does consume a bit more memory, but assuming reasonably long names and a reasonable ammount of monitors per group this likely won't be a problem.
I do think adding a separate mechanism for accounting for the failed number is sort of a footgun => I would prefer a list for tracking this ^^

@@ -1526,6 +1543,23 @@ class Monitor extends BeanModel {
]);
}

/**
* Gets Parent name
* @returns {Promise<string>} Name of this monitor's parent
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @returns {Promise<string>} Name of this monitor's parent
* @returns {Promise<string>} Name of this monitor's parent or '' if no parent exists

@CommanderStorm CommanderStorm changed the title Resolves #3278 - put child name in notification, also added count of add'l children [groups] Put child's name in the notification, also added count of additional children Jan 15, 2024
@CommanderStorm CommanderStorm added the area:notifications Everything related to notifications label Jan 15, 2024
homeautomaton and others added 3 commits January 15, 2024 12:17
Co-authored-by: Frank Elsinga <[email protected]>
Co-authored-by: Frank Elsinga <[email protected]>
suggestion accepted

Co-authored-by: Frank Elsinga <[email protected]>
Comment on lines +987 to +988
let parentName = await this.getParentName();
groupText = ` under group '${parentName}'`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Re https://github.com/louislam/uptime-kuma/pull/4371/files#r1452660704

(I can't add the second line to the suggestion)

I did forget to add the second line to the code suggestion.
I don't think the comparison with getPathName is fair as said function does do a lot more.

Suggested change
let parentName = await this.getParentName();
groupText = ` under group '${parentName}'`;
let parent = await Monitor.getParent(this.id);
groupText = ` under group '${parent.name}'`;

Comment on lines +1546 to +1558
/**
* Gets Parent name
* @returns {Promise<string>} Name of this monitor's parent
*/
async getParentName() {
if (this.parent === null) {
return "";
}

let parent = await Monitor.getParent(this.id);
return parent.name;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Continiuation of the suggested changes in https://github.com/louislam/uptime-kuma/pull/4371/files#r1452821597

Suggested change
/**
* Gets Parent name
* @returns {Promise<string>} Name of this monitor's parent
*/
async getParentName() {
if (this.parent === null) {
return "";
}
let parent = await Monitor.getParent(this.id);
return parent.name;
}

Comment on lines +386 to +387
let downChildName = "";
let failureCount = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Continuation of #4371 (comment)

I can only suggest refactorings for lines you changed => this is why this suggestion is split into multiple parts

My consearn is mostly around future maintenence effort and if this introduces bugs like the faulty (not taking into account PENDING) accounting using failureCount

Suggested change
let downChildName = "";
let failureCount = 0;
let downChildNames = [];

// lastBeat.status could be null
if (!lastBeat) {
bean.status = PENDING;
} else if (bean.status === UP && (lastBeat.status === PENDING || lastBeat.status === DOWN)) {
bean.status = lastBeat.status;
downChildName = child.name;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
downChildName = child.name;
downChildNames.push(child.name);

} else if (bean.status === PENDING && lastBeat.status === DOWN) {
bean.status = lastBeat.status;
downChildName = child.name;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
downChildName = child.name;
downChildNames.push(child.name);

Comment on lines +410 to +412
}
if (lastBeat.status === DOWN) {
failureCount++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
}
if (lastBeat.status === DOWN) {
failureCount++;

Comment on lines +417 to +421
if (failureCount <= 1) {
bean.msg = `Child '${downChildName}' inaccessible`;
} else {
bean.msg = `Child '${downChildName}' and ${failureCount - 1} others inaccessible`;
}
Copy link
Collaborator

@CommanderStorm CommanderStorm Jan 16, 2024

Choose a reason for hiding this comment

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

Suggested change
if (failureCount <= 1) {
bean.msg = `Child '${downChildName}' inaccessible`;
} else {
bean.msg = `Child '${downChildName}' and ${failureCount - 1} others inaccessible`;
}
if (downChildNames.lenght === 1) {
bean.msg = `Child '${downChildName[0]}' inaccessible`;
} else {
bean.msg = `Child '${downChildNames[0]}' and ${downChildNames.lengh - 1} others inaccessible`;
}

Copy link
Author

Choose a reason for hiding this comment

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

This is nothing short of ridiculous. Collect a list of names, just to get the first name from the list.

And you've misspelled length. Your code wouldn't even work. I'll just keep my own private fork of this project, and shape it to my own needs. I have many enhancements in mind, and working on this trivial already-existing issue was just my way of testing the waters to see if it is worth contributing to the project. People like you make open source worse than working for a corporation with bad management.

Good riddance.

Copy link
Author

Choose a reason for hiding this comment

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

@louislam Do you have an opinion?

Copy link
Collaborator

@CommanderStorm CommanderStorm Jan 16, 2024

Choose a reason for hiding this comment

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

Collect a list of names, just to get the first name from the list.

first name and the lenght of the list.

you've misspelled length

Good catch. fixed it

I'll just keep my own private fork of this project, and shape it to my own needs

That is fine by us.
Forking a project doesn’t have to be a bad thing. Being able to copy and modify projects is one of the best things about open source1

People like you make open source worse than working for a corporation with bad management.

Sorry that you feel this way. If there is something concrete that I can change in the way I review work, that would be appreciated (I am not even a junior dev in terms of job experience right now)

Footnotes

  1. https://opensource.guide/best-practices/#let-others-build-the-solutions-they-need

@tylerjwatson
Copy link

hi all, looks like some trouble with code review here.

would you all like me to pick up this PR? I would really like this feature and will donate some time to it.

@CommanderStorm
Copy link
Collaborator

would you all like me to pick up this PR?

@tylerjwatson
Yes, that would be appreciated.
please rebase any change on #4395 instead (basically a code-move) => lower merge effort.

I am going to close this PR as I don't see @homeautomaton contributing to this PR further as they stated:

I'll just keep my own private fork of this project, and shape it to my own needs [...]
Good riddance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:notifications Everything related to notifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

notifications not showing which child is down
3 participants