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

[inspector] show request method, path, and querystring #167544

Closed
wants to merge 3 commits into from

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Sep 28, 2023

Reinstates changes from #166565. Original changes reverted by #167485. This PR only returns method, path, and querystring keys from request parameters.

When reviewing, 933a5ac are the changes that resolve the issue and the only different changes from the revert of the revert.

I updated the integration tests to check entire requestParams object instead of individual keys. This gives us a guarentee that 'headers' is not getting returned from the API since it will fail these tests.

@nreese nreese requested a review from rudolf September 28, 2023 16:58
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #71 / event_log Event Log public API "after all" hook in "Event Log public API"
  • [job] [logs] FTR Configs #71 / event_log Event Log public API Legacy Ids "before all" hook for "should support search event by ids and legacyIds"

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
inspector 56 57 +1

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
kibanaUtils 417 421 +4

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
inspector 26.2KB 26.4KB +203.0B

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
kibanaUtils 9 10 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 408.0KB 408.2KB +205.0B
inspector 21.8KB 22.2KB +414.0B
total +619.0B
Unknown metric groups

API count

id before after diff
data 3311 3313 +2
kibanaUtils 610 614 +4
total +6

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@nreese nreese marked this pull request as ready for review September 28, 2023 18:56
@nreese nreese requested review from a team as code owners September 28, 2023 18:56
@nreese nreese added release_note:enhancement Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v8.11.0 labels Sep 28, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@nreese nreese added the Feature:Inspector Inspector infrastructure and implementations label Sep 28, 2023
Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Changes in 933a5ac LGTM! Nice updates to the integration tests especially to ensure the response is sanitized.

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Is it expected that Inspector in Graph and Vega apps does not show request params yet?

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

By changing reportServerError we're changing the behaviour of a lot of server APIs owned by other teams. We should rather limit this behaviour change to the data plugin only.

/**
* HTTP request parameters from elasticsearch transport client t
*/
requestParams?: ConnectionRequestParams;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we construct a dedicated type that only includes the information we intend to send back?

@@ -43,6 +56,7 @@ export function reportServerError(res: KibanaResponseFactory, err: KbnServerErro
body: {
message: err.message,
attributes: err.errBody?.error,
...(err.requestParams ? { requestParams: err.requestParams } : {}),
Copy link
Contributor

Choose a reason for hiding this comment

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

KbnServerError and reportServerError are widely used outside of data plugin for catching any kind of error in route handlers. It's risky to return the 'requestParams' for all the places this gets used and this would also not be a pattern that we'd recommend gets widely adopted.

We should rather move this functionality and sanitizeRequestParams into the data plugin.

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 am not sure I understand, are you suggesting not using KbnServerError and reportServerError in data plugin?

Copy link
Contributor

@rudolf rudolf Oct 2, 2023

Choose a reason for hiding this comment

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

yes, we could create a new reportElasticsearchErrorAndRequestParams (naming tbd) in the data plugin and leave the reportServerError util as-is so we don't change the APIs of any other plugins/teams.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I will do that. That aligns well with another effort to return rawResponse from data plugin search endpoints, #167099. I will work #167099 first to migrate data search plugin away from KbnServerError and reportServerError so that rawResponse is included in error response. Then I can circle back to this PR and build off of those data plugin only utility methods

'method' | 'path' | 'querystring'
>;

export function sanitizeRequestParams(requestParams: ConnectionRequestParams) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export function sanitizeRequestParams(requestParams: ConnectionRequestParams) {
export function sanitizeRequestParams(requestParams: ConnectionRequestParams): SanitizedConnectionRequestParams {

@nreese nreese added v8.12.0 and removed v8.11.0 labels Oct 9, 2023
nreese added a commit that referenced this pull request Oct 23, 2023
Closes #167099

#### Problem
`/bsearch` and `/search` APIs only return `error` key from elasticsearch
error response. This is problematic because Inspector needs
`rawResponse` to populate "Clusters and shards"

While working on this issue, I discovered another problem with how error
responses are added to inspector requestResponder. The `Error` instance
is added as `json` key. This is a little awkward since the response tab
just stringifies the contents of `json`, thus stringifing the Error
object instead of just the error body returned from API. This PR address
this problem by setting `json` to either `attributes` or `{ message }`.

#### Solution
PR updates `/bsearch` and `/search` APIs to return `{ attributes: {
error: ErrorCause, rawResponse }}` for failed responses. Solution
avoided changing KbnServerError and reportServerError since these
methods are used extensivly throughout Kibana (see
#167544 (comment) for
more details). Instead, KbnSearchError and reportSearchError are created
to report search error messages.

#### Test
1) install web logs sample data set
2) open discover
3) add filter
    ```
    {
      "error_query": {
        "indices": [
          {
            "error_type": "exception",
            "message": "local shard failure message 123",
            "name": "kibana_sample_data_logs",
            "shard_ids": [
              0
            ]
          }
        ]
      }
    }
    ```
4) Open inspector. Verify "Clusters and shards" tab is visible and
populated. Verify "Response" tab shows "error" and "rawResponse" keys.
<img width="500" alt="Screenshot 2023-10-09 at 9 29 16 AM"
src="https://github.com/elastic/kibana/assets/373691/461b0eb0-0502-4d48-a487-68025ef24d35">
<img width="500" alt="Screenshot 2023-10-09 at 9 29 06 AM"
src="https://github.com/elastic/kibana/assets/373691/9aff41eb-f771-48e3-a66d-1447689c2c6a">

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Gloria Hornero <[email protected]>
@nreese
Copy link
Contributor Author

nreese commented Oct 26, 2023

Replacing with #169970.

@nreese nreese closed this Oct 26, 2023
nreese added a commit that referenced this pull request Nov 3, 2023
Closes #45931

PR updates data plugin `search` and `bsearch` endpoints to return
method, path, and querystring request params from elasticsearch-js
client requests. This provides inspector with the exact details used to
fetch data from elasticsearch, ensuring inspector displays request
exactly as used by elasticsearch-js client.

**ESQL** This PR makes it possible to open ESQL searches in console.
<img width="500" alt="Screen Shot 2023-09-16 at 4 19 58 PM"
src="https://github.com/elastic/kibana/assets/373691/56019fb5-ca88-46cf-a42f-86f5f51edfcc">

### background
If you are thinking to yourself, "haven't I reviewed this before?", you
are right. This functionality has been through several iterations.
1) Original PR #166565 was
reverted for exposing `headers`.
2) [Fix to only expose method, path, and querystring keys from request
parameters](#167544) was rejected
because it applied changes to
`kibana_utils/server/report_server_error.ts`, which is used extensively
throughout Kibana.
3) This iteration moves logic into the data plugin to be as narrow as
possible.

---------

Co-authored-by: kibanamachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Inspector Inspector infrastructure and implementations release_note:enhancement Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants