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

[BUG] On demand reports fail to generate a CSV file for download. #371

Closed
necoras opened this issue Jul 3, 2024 · 5 comments · Fixed by #458
Closed

[BUG] On demand reports fail to generate a CSV file for download. #371

necoras opened this issue Jul 3, 2024 · 5 comments · Fixed by #458
Labels
bug Something isn't working cannot-repro

Comments

@necoras
Copy link

necoras commented Jul 3, 2024

What is the bug?
After updating to v 2.13, we're having some of our reports fail to generate. It's not every report, but it is consistent. That is, if a query fails to allow a csv to be generated it will always fail, and if one succeeds it will always succeed. The only error message in the console is a 500 with the message of:

"The 'order' parameter should be one of 'asc' or 'desc'".

This seems to indicate that there is an Order enum that isn't being properly declared, but I don't know where in the codebase that is. There is a "Sort" query string parameter being passed into the generate-report call that may be related.

How can one reproduce the bug?
Steps to reproduce the behavior:

  1. Generate a query of some data
  2. Click on the Reporting button.
  3. Click Generate CSV
  4. See if error occurs. If so, toaster with text "Error downloading report." will appear.
  5. Check dev console, see 500 error with message "The 'order' parameter should be one of 'asc' or 'desc'"

What is the expected behavior?
CSV file is generated and downloaded.

What is your host/environment?

  • OS: Amazon Opensearch
  • Version 2.13
  • Plugins

Do you have any screenshots?
image

Do you have any additional context?
I think I've traced it down to a bad querystring being built/supplied in context_menu.js:

const queryUrl = replaceQueryURL(location.href);

But that code hasn't changed in years (aside from the addition of the xlsx support a bit above it.)

@necoras necoras added bug Something isn't working untriaged labels Jul 3, 2024
@dblock
Copy link
Member

dblock commented Jul 22, 2024

Thanks for opening this. Please do comment if you find the root cause.

[Catch All Triage w/ 1, 2, 3]

@dblock dblock removed the untriaged label Jul 22, 2024
@Swiddis
Copy link
Collaborator

Swiddis commented Sep 20, 2024

Some further debugging: I traced it down to this line in dataReportHelpers:

return esb.sort(element[0], element[1]);

The error happens when element[1] is not one of the listed values. But I haven't been able to reproduce this error path yet with actual reports (including migrating from 2.9 to 2.13).

@Swiddis
Copy link
Collaborator

Swiddis commented Sep 20, 2024

Update: it looks like after the upgrade, for some types of sorts with saved searches, the sort field is de-nested. If you have sort: [["field1", "asc"]] before the upgrade, it may have become sort: ["field1", "asc"]. Per the above logic, this means it incorrectly handles the value and tries to sort the field f by order i. I'm not sure what causes that to get incorrectly transformed during the upgrade, but manually updating the saved search in the index should be sufficient to fix the issue.

@Swiddis
Copy link
Collaborator

Swiddis commented Sep 24, 2024

A "just fix this" solution, the following will reset the sort information for all saved searches, which will stop the errors. From there, they can be re-saved from the UI with new sort information. In local testing I wasn't able to get the search to fix itself once corrupted using only the UI, but either fixing the sort field per-report or resetting everything worked fine.

POST .kibana/_update_by_query
{
  "query": {
    "match": {
      "type": "search"
    }
  },
  "script": {
    "source": "ctx._source.search.sort = []",
    "lang": "painless"
  }
}

There probably exists a more elaborate painless script that can fix all the reports non-destructively (if not nested -> nest, if empty -> keep empty, if already nested -> don't nest). If I had more time on-hand I'd try to write it. Note re-saving with a new sort will cause both: sort: ["@timestamp", "asc", ["@timestamp", "asc"]].

@Swiddis
Copy link
Collaborator

Swiddis commented Oct 29, 2024

Wrote #458 as a partial fix, but the root cause is still unknown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cannot-repro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants