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

Allow comment in request payload to be returned in the response payload. #61118

Closed
linker-c opened this issue Aug 13, 2020 · 10 comments · Fixed by #63036
Closed

Allow comment in request payload to be returned in the response payload. #61118

linker-c opened this issue Aug 13, 2020 · 10 comments · Fixed by #63036
Labels
:Core/Infra/Logging Log management and logging utilities >enhancement feedback_needed Team:Core/Infra Meta label for core/infra team

Comments

@linker-c
Copy link

The idea is very similar to "X-Opaque-ID" from http request header. But make it part of the payload so the value will be available in all aspect of debugging.
X-Opaque-ID only shows up for slow logs, which is not friendly enough IMO.
I often use kibana to see detailed task and any query taking too long will be spotted easily. Especially performance degradation over time.
The problem for me is that I have no idea who made that request and under what context. The coders don't even know most of the time.

If there's a boolean flag that allows us to return the comment from request payload, then I can easily use comment as an ID.
It will speed up troubleshooting significantly.

@linker-c linker-c added >enhancement needs:triage Requires assignment of a team area label labels Aug 13, 2020
@pgomulka pgomulka added the :Core/Infra/Logging Log management and logging utilities label Aug 18, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Logging)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Aug 18, 2020
@costin
Copy link
Member

costin commented Sep 7, 2020

To clarify, are you asking for X-Opaque-ID to be returned or for any comment inside the request to be returned?
In general, the issue with HTTP headers being promoted in the payload is that breaks the line between meta-data and concrete data. For example, all ES APIs support HTTP requests, many support multiple formats, typically JSON but also BSON, Smile, etc.. In a similar fashion, HTTP headers are well defined but the payload itself is not, assuming JSON, should the comment sit at the top or anywhere in the request. If the payload gets wrapped by another API (which uses it internally) what should happen then?
There's also the issue of dealing with potentially malicious comment - making it part of the payload, it is being fed to all its consumers.

Since you mentioned troubleshooting, would getting access to X-Opaque-ID on all requests help?

@cjcenizal
Copy link
Contributor

Seems related to the enhancement request to support comments in the body of requests in Console (elastic/kibana#11973), which has been requested a few times.

@linker-c
Copy link
Author

linker-c commented Sep 15, 2020

@costin .
I am thinking more like a boolean flag in the body. I believe it's easier for most folks. We don't typically touch http headers in the code. It'll be more work changing headers per context.

A flag like {"track_total_hits": true }, or {"profile" : true } is what I'm thinking.
@cjcenizal , yes it's related. But I am asking for the returned payload.

For example:

POST sites/_search {
  // From AI model 3
   "return_comment": true
}

And the payload looks something like this

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : { ... },
  **"comment": "From AI model 3",**
  "hits" : { ...  },
    "max_score" : 1.0,
    "hits" : [
      { "name": "xyz"},
      { "name": "abc"},
          ...
     ]
}

Maybe just return the first comment or concatenate all into 1 is fine too.
If this specific query is having an issue or long query/indexing time, I can easily see the caller is "From AI model 3", etc.

If you guys are going to do this, please also honor this flag in your own internal display.
So we can get the benefit through out the system.
Like the payload for this one:

GET _cat/tasks?v&detailed=true

Thanks.

@costin
Copy link
Member

costin commented Sep 15, 2020

Supporting arbitrary elements alongside the response is problematic, see some of the examples in my previous comment.
I understand the angle that you are coming from however I have issues with generalizing this concept across ES APIs.
For example I can see the use of getting access to X-Opaque-ID inside each request and potentially in the logs but changing the actual response is too impactful.

For your particular use-case, I recommend creating your own plugin which can enhance the request/response to your preference. This should help move things forward and also validate your ideas.

@linker-c
Copy link
Author

Maybe returning result of X-Opaque-ID to all access is easier.
Let's do that instead then if possible.

Thanks.

@jimczi jimczi removed the needs:triage Requires assignment of a team area label label Sep 17, 2020
@imotov
Copy link
Contributor

imotov commented Sep 21, 2020

@linker-c we are trying to understand the deficiencies of X-Opaque-ID for your purposes. We designed this mechanism specifically to identify the running tasks and add additional roundtrip metadata. In order to make it universally applicable for all request we placed into request and response headers. It also shows up in the task list.

@linker-c
Copy link
Author

Really?
It's not showing up on GET _cat/tasks?v&detailed=true.
We are running 7.3.1 version.
Maybe it's in later build?

@imotov
Copy link
Contributor

imotov commented Sep 22, 2020

It is available since 6.2.0. See #27764. It is just not available on _cat API.

$ curl -v "http://127.0.0.1:9200/_tasks?pretty" -H 'X-Opaque-ID: Blah blah blah'
*   Trying 127.0.0.1:9200...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 9200 (#0)
> GET /_tasks?pretty HTTP/1.1
> Host: 127.0.0.1:9200
> User-Agent: curl/7.68.0
> Accept: */*
> X-Opaque-ID: Blah blah blah
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< X-Opaque-Id: Blah blah blah
< content-type: application/json; charset=UTF-8
< content-length: 1440
< 
{
  "nodes" : {
    "zJC4YnjPTjSVtYASXp8b_Q" : {
      "name" : "grasshopper",
      "transport_address" : "127.0.0.1:9300",
      "host" : "127.0.0.1",
      "ip" : "127.0.0.1:9300",
      "roles" : [
        "data",
        "ingest",
        "master",
        "ml",
        "remote_cluster_client",
        "transform"
      ],
      "attributes" : {
        "ml.machine_memory" : "33516806144",
        "xpack.installed" : "true",
        "transform.node" : "true",
        "ml.max_open_jobs" : "20"
      },
      "tasks" : {
        "zJC4YnjPTjSVtYASXp8b_Q:22177" : {
          "node" : "zJC4YnjPTjSVtYASXp8b_Q",
          "id" : 22177,
          "type" : "transport",
          "action" : "cluster:monitor/tasks/lists",
          "start_time_in_millis" : 1600792437554,
          "running_time_in_nanos" : 246088,
          "cancellable" : false,
          "headers" : {
            "X-Opaque-Id" : "Blah blah blah"
          }
        },
        "zJC4YnjPTjSVtYASXp8b_Q:22178" : {
          "node" : "zJC4YnjPTjSVtYASXp8b_Q",
          "id" : 22178,
          "type" : "direct",
          "action" : "cluster:monitor/tasks/lists[n]",
          "start_time_in_millis" : 1600792437555,
          "running_time_in_nanos" : 118696,
          "cancellable" : false,
          "parent_task_id" : "zJC4YnjPTjSVtYASXp8b_Q:22177",
          "headers" : {
            "X-Opaque-Id" : "Blah blah blah"
          }
        }
      }
    }
  }
}
* Connection #0 to host 127.0.0.1 left intact

@imotov
Copy link
Contributor

imotov commented Sep 29, 2020

I opened PR for cat API.

imotov added a commit that referenced this issue Oct 1, 2020
Adds an optional column with support for x_opaque_id to _cat/tasks API.

Closes #61118
imotov added a commit to imotov/elasticsearch that referenced this issue Oct 1, 2020
Adds an optional column with support for x_opaque_id to _cat/tasks API.

Closes elastic#61118
imotov added a commit that referenced this issue Oct 1, 2020
Adds an optional column with support for x_opaque_id to _cat/tasks API.

Closes #61118
imotov added a commit to imotov/elasticsearch that referenced this issue Oct 1, 2020
Since elastic#63036 is now backported, we can enable this test for earlier versions.

Relates to elastic#61118
imotov added a commit that referenced this issue Oct 1, 2020
Since #63036 is now backported, we can enable this test for earlier versions.

Relates to #61118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Logging Log management and logging utilities >enhancement feedback_needed Team:Core/Infra Meta label for core/infra team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants