Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-1944: Unable to Delete a Comment in Alerts UI #1307

Closed
wants to merge 3 commits into from

Conversation

ruffle1986
Copy link
Contributor

Contributor Comments

Link to the original ASF Jira ticket: https://issues.apache.org/jira/browse/METRON-1944

The problem

The problem and its solution are quite trivial in this case. The code which is responsible for the deletion of the comment tried to address the deleted comment in an array after it was removed from it.

splice returns with an array of the removed elements so we can keep working with that to persist the operation for the given comment on the server.

Description from the ASF Jira ticket:

I am unable to delete a comment in the Alerts UI. While it appears that the comment is deleted, it is only deleted locally, but not server side. An exception is thrown in the browser console.

ERROR TypeError: Cannot read property 'alertComment' of undefined at SafeSubscriber._next (alert-details.component.ts:258) at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:207) at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:145) at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:80) at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:55) at Subject.push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next (Subject.js:47) at DialogService.push../src/app/service/dialog.service.ts.DialogService.approve (dialog.service.ts:49) at MetronDialogComponent.push../src/app/shared/metron-dialog/metron-dialog.component.ts.MetronDialogComponent.confirm (metron-dialog.component.ts:54) at Object.handleEvent (login-guard.ts:40) at handleEvent (core.js:10258)

Steps To Replicate

  1. Find an Alert
  2. Comment on the alert.
  3. Delete the comment.
  4. Close the side panel.
  5. Search for the alert again.
  6. Click on the alert and the comment remains.

Pull Request Checklist

Thank you for submitting a contribution to Apache Metron.
Please refer to our Development Guidelines for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines for complete smoke testing guides.

In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:

For all changes:

  • Is there a JIRA ticket associated with this PR? If not one needs to be created at Metron Jira.
  • Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
  • Has your PR been rebased against the latest commit within the target branch (typically master)?

For code changes:

  • Have you included steps to reproduce the behavior or problem that is being changed or addressed?

  • Have you included steps or a guide to how the change may be verified and tested manually?

  • Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:

    mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh 
    
  • Have you written or updated unit tests and or integration tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

  • Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via site-book/target/site/index.html:

    cd site-book
    mvn site
    

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that travis-ci is set up for your personal repository such that your branches are built there before submitting a pull request.

@sardell
Copy link
Contributor

sardell commented Dec 20, 2018

@ruffle1986 It looks like Travis is failing, but it's failing during the integration tests that don't have to do with the UI (where your work happened). Specifically:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test (integration-tests) on project metron-pcap-backend: Execution integration-tests of goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?

From the looks of it, the VM just randomly crashed? Could you try closing/reopening this PR to re-run Travis?

@ruffle1986 ruffle1986 closed this Dec 20, 2018
@ruffle1986 ruffle1986 reopened this Dec 20, 2018
@justinleet
Copy link
Contributor

Is there any way to add a unit test for this? I know a lot of the testing code and infra has been a bit in flux, so I'm not quite sure how much of an ask that is.

@ruffle1986
Copy link
Contributor Author

Good point. Shall I open a JIRA ticket on this and add the tests to another PR? Or just simply add them here? @tiborm @sardell

@sardell
Copy link
Contributor

sardell commented Jan 25, 2019

@ruffle1986 If the amount of mocking and setup you need to do is minimal, I think writing a unit test specific to the comment functionality of the alert details component should be done in this PR. However, I do see there are no unit tests currently setup for the alert details component. If the scope of setting up these tests is very time consuming, I think you should create a separate JIRA to cover this component with unit tests. That way, we aren't delaying the bug fix getting into master.

@sardell
Copy link
Contributor

sardell commented Jan 31, 2019

+1. Glad to see the unit test for the comment deletion functionality. Hopefully in the near future, we can extend the unit test coverage for this component, but for now I think this is good. Thanks for the contribution, @ruffle1986!

EDIT: @ruffle1986 After further testing, I think I caught a bug in this code (though it may have existed before and didn't show because of the comment deletion being broken). Here are the steps to reproduce:

  • Open the details panel for an alert
  • Add a comment, then delete it.
  • Close and reopen the details panel for the alert you just had open.
  • The comment reappears. If you delete the comment again and repeat the close/reopen steps, it's finally deleted.

@ruffle1986
Copy link
Contributor Author

ruffle1986 commented Feb 11, 2019

@sardell Thanks for the report! Nice catch!

Yes, it was there before probably. In order the enable comment deletion, I had to slightly modify the existing code. However the issue you're struggling with is critical, I respectfully think it's out of the scope of this PR.

When it comes to removing comments (and adding as well!!), the app deals with HTTP requests which are not organized properly. When you successfully removed or added new comments, the server responses with the fresh new list of comments attached to the given alert. But if you're fast, adding/removing a bunch of comments then immediately closing and opening the comments pane again could cause certain issues. The problem is that the API endpoints for the deletion/addition returns with a list of comments and when you open the pane, it also returns the list of comments and the two are not necessarily the same at a certain point of time. They're not synced yet.

Long story short, the current design and the implementation is not prepared for this kind of user quickness, the solution for this is not trivial and needs to have a further discussion for sure how to deal with it.

If you don't think otherwise, I would open a Jira ticket about the aforementioned syncing issue and ship the patch in a different PR.

@sardell
Copy link
Contributor

sardell commented Feb 11, 2019

@ruffle1986 I see. After reading your explanation, I agree that resolving this issue is going to take more thought, and will likely result in a pretty big change in implementation. I also agree that this is an issue bigger in scope than the original task of resolving a front-end specific bug which prevented a user from deleting a comment.

+1 pending @ruffle1986 creating and sharing a JIRA ticket to track the syncing issue described above.

@ruffle1986
Copy link
Contributor Author

I created the ASF Jira ticket which describes the aforementioned problem. I also made a video and added the scenario to reproduce the problem.

Here you are: https://issues.apache.org/jira/browse/METRON-2001

() => {
this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment)
},
null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the next callback here because it makes no sense to map over an array and does nothing with the mapped array.

map does not mutate the array on which you call it. It creates a brand new array with the mapped elements. The code above does nothing with the return value of map so it can be removed.

Copy link
Contributor

@sardell sardell Feb 13, 2019

Choose a reason for hiding this comment

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

Yeah, that makes sense to remove since we do not know the original intention of the line of code.

@justinleet It looks like this line of code was added here. I'm going to assume it's fine to remove, but I'm curious what the original intention of the code was. Since there isn't a PR attached I'm not even sure you were the author of the code:
e0fc475#diff-bce5ae5c6be579250a35b6ff4f6da594R271

@sardell
Copy link
Contributor

sardell commented Feb 14, 2019

+1. Thanks for the contribution, @ruffle1986!

@asfgit asfgit closed this in 792e796 Feb 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants