-
Notifications
You must be signed in to change notification settings - Fork 582
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
API: Display a correct status when removing a downtime #8104
API: Display a correct status when removing a downtime #8104
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
git reset --soft HEAD~$(git rev-list --count $(git merge-base HEAD master)..HEAD^)
-
git commit --amend --no-edit
-
git push -f origin bugfix/remove-downtime-returns-wrong-status-7408
f4a3f85
to
9ce579d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write a before/after test protocol for both cases you handle.
Testprotocol: First create scheduledDowntime object like this..
Now restart Icinga2 daemon and try to remove downtime: Log message:
Api response:
After:
Api :
Or if you want to delete host and services that belong to the scheduledDowntime: Before:
After:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered passing the error from Downtime::RemoveDowntime(...)
instead of duplicating the check, for example by raising an exception? That function is used in a few places though and probably all of them would have to be updated though. But this could also show different places where the caller should know about this failure.
I think it could also be possible that downtime->IsExpired()
changes between the check here and in Downtime::RemoveDowntime(...)
, so in theory you could get different results in the log and the API response, but nobody would really care I guess (log says it can't be removed right before it expires, API response says it was removed as it just expired).
8643cbc
to
4167624
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are also two more uses of Downtime::RemoveDowntime
in the code base, have you checked these?
Checkable::RemoveAllDowntimes
icinga2/lib/icinga/checkable-downtime.cpp
Lines 12 to 17 in 4167624
void Checkable::RemoveAllDowntimes() { for (const Downtime::Ptr& downtime : GetDowntimes()) { Downtime::RemoveDowntime(downtime->GetName(), true, true); } } Downtime::DowntimesExpireTimerHandler
icinga2/lib/icinga/downtime.cpp
Lines 441 to 445 in 4167624
for (const Downtime::Ptr& downtime : downtimes) { /* Only remove downtimes which are activated after daemon start. */ if (downtime->IsActive() && (downtime->IsExpired() || !downtime->HasValidConfigOwner())) RemoveDowntime(downtime->GetName(), false, true); }
Yeah, I've seen them before. But since we throw the exception as long as the downtime has not expired and is currently used by another object, it should not be a problem with the two callers, because the parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit history obviously still needs cleanup and once you say you're done, I'll spin this up in my test setup for my final review.
In general, can you give some explanation on why you added the individual members of invalid_downtime_removal_error
? I'd be perfectly fine with it only having the constructor it actually uses (i.e. with parameter String
). There's probably no reason for allowing to construct an exception of this type without a message. Also, is there any particular reason for listing the copy constructor and operator=
, or just to make it explicit?
No, there is no special reason for this, but since this exception type is thrown with |
7e62648
to
e630dd1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments. Sorry for requesting changes yet again, I missed this during previous reviews.
Why to discuss w/ team Web? Have a look at these (onSuccess). They don't even care about errors. |
ff11e34
to
3cae544
Compare
Sure, you can also answer questions regarding the current behavior by trying it out or reading the source. |
3cae544
to
3ea1289
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Rebase against master
- Reproduce this statement of @julianbrost:
Somehow it now returns an error code of 400 in the JSON wrapped in a HTTP response with code 500
< HTTP/1.1 500 Internal Server Error
< Server: Icinga/v2.12.0-rc1-54-g198177cc5
< Content-Type: application/json
< Content-Length: 248
<
{
"results": [
{
"code": 400.0,
"status": "Cannot remove downtime 'ha-master!ping4!8912c953-19b5-4cd6-93d0-65fc98c5bf80'. It is owned by scheduled downtime object 'ha-master!ping4!run-downtime'"
}
]
* Connection #0 to host localhost left intact
} |
Good! Now have a look at the code and tell where this behavior comes from. |
As @julianbrost already mentioned above, everything that is not 200 is listed in the HTTP response as internal server error with 500 error code and comes from here.
|
Any ideas how we could do this better? |
Isn't it obvious 🙄 ! You just have to add an |
No. Make a separate PR for that code:
|
198177c
to
572af6a
Compare
572af6a
to
dd02e3b
Compare
In fact this didn't change what Web 2 reports when trying to delete a downtime. But I guess in the end this error page is better than silently ignoring an error. I'll open an issue there. |
resolves #7408