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

Profile API should show node details as well as shard details #96396

Merged
merged 8 commits into from
Jun 24, 2023

Conversation

quux00
Copy link
Contributor

@quux00 quux00 commented May 27, 2023

SearchProfileResults has additional fields for XContent output: node_id, cluster, index, shard_id. It parses the existing composite ID using the new parseProfileShardId method, which reverses the SeachShardTarget.toString method.

No new information is added here, merely the splitting out of the four pieces of information in the profile shards "composite" id that is created by the SeachShardTarget.toString method.

Profile/shards output now has the form:

  "profile": {
    "shards": [
      {
        "id": "[2m7SW9oIRrirdrwirM1mwQ][blogs][0]",
        "node_id": "2m7SW9oIRrirdrwirM1mwQ",
        "shard_id": "0",
        "index": "blogs",
        "cluster": "(local)",
        "searches": [ ... ]
        ...
      },
      {
        "id": "[UngEVXTBQL-7w5j_tftGAQ][remote1:blogs][2]",
        "node_id": "UngEVXTBQL-7w5j_tftGAQ",
        "shard_id": "2",
        "index": "blogs",
        "cluster": "remote1",
        "searches": [ ... ]
        ...

where the latter is on a remote cluster and you can see that as the prefix on the index name.

Partially addresses #25896

@quux00 quux00 added the WIP label May 27, 2023
@quux00 quux00 force-pushed the profile/show-node-details branch 2 times, most recently from 0e8036e to 1efbe87 Compare June 9, 2023 21:21
@quux00 quux00 changed the title Draft: Profile API should show node details as well as shard details Profile API should show node details as well as shard details Jun 9, 2023
@quux00 quux00 added :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team >non-issue >enhancement and removed WIP >non-issue labels Jun 9, 2023
@quux00 quux00 marked this pull request as ready for review June 9, 2023 21:33
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine
Copy link
Collaborator

Hi @quux00, I've created a changelog YAML for you.

@quux00 quux00 requested review from jdconrad and javanna June 9, 2023 21:33
@quux00 quux00 force-pushed the profile/show-node-details branch from 5dc8388 to fcdd4be Compare June 12, 2023 13:39
@@ -79,9 +90,24 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
for (String key : sortedKeys) {
builder.startObject();
builder.field(ID_FIELD, key);
shardResults.get(key).toXContent(builder, params);

ShardProfileId shardProfileId = parseProfileShardId(key);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is good for backwards compatibility, but what do you think of actually serializing those objects back instead of encoding them in the id and parsing them out again?

It seems brittle to me to store important info in a plain text string that is assumed to be formatted in a specific way.

Copy link
Member

Choose a reason for hiding this comment

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

@quux00 the brittleness could be acceptable if test coverage was adequate.

I know there can be thousands SearchProfileResults and maybe we don't want to add more fields to it for the sake of heap usage.

What do you think @javanna ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Ben,

I think this is good for backwards compatibility, but what do you think of actually serializing those objects back instead of encoding them in the id and parsing them out again? It seems brittle to me to store important info in a plain text string that is assumed to be formatted in a specific way.

In terms of brittleness, I marked this PR as partially addressing the original issue: #25896, where the request was basically to split the composite ID and maybe add some additional information. They recommended not changing the ID itself because that would be a backwards incompatible change.

So the brittleness is already baked in when that composite ID was created and now we need to support that composite ID in order to not make breaking changes.

In my analysis comment on that issue, I analyzed all the formats of that ID and how it's generated, indicating that it would be fairly straightforward to parse that out. Adding new info is problematic though because that composite ID is used as a Map key (https://github.com/elastic/elasticsearch/pull/96396/files#diff-582e9063bae3a8d070700f30a160c2647fd69bff489591ce5a16821bac63af6aR52) and that Map is passed around quite a bit through multiple layers before it gets to the place where it is rendered as XContent. IIRC (it's been two weeks since I looked at this), the likely place to serialize the data is in SearchShardTarget, but that doesn't make out to the place the XContent is rendered (only the composite ID map key).

I think we'd need to refactor a fair bit of code to avoid using that ID as the map key. So I decided to try to go the simple path first - just parsing out the existing info from that map key.

We could certainly try the bigger refactoring if we think it's worth it and want additional things not in the composite id, like cluster_uuid.

the brittleness could be acceptable if test coverage was adequate.

In terms of better test coverage, the approach I took was bottom up from the possible formats that are generated by SearchShardTarget.toString(), which is the composite ID map key.

I can enhance the test I added to use the SearchShardTarget.toString() method to generate the input.

I'm open to suggestions on how else to test it. Since the node_id and possibly other fields would be randomized in yamlRestTests. The test would need to parse out the composite on the fly and I'm not sure how I'd do that in a yamlRestTest. Do you have ideas on an additional good way to test this?

Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

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

Thanks for the clarifications @quux00

Could you add some tests on the output and add an assert to the parser to catch during tests?

Here is where you should put the integration tests:
rest-api-spec/test/search/370_profile.yml

These yaml tests are ran against various Elasticsearch versions. So you will have to restrict the version via

  - skip:
      version: " - 8.7.99"
      reason: introduced in 8.8.0

Or whatever version is appropriate.

@quux00 quux00 force-pushed the profile/show-node-details branch from fcdd4be to 7440b1d Compare June 16, 2023 19:58
@elasticsearchmachine
Copy link
Collaborator

Hi @quux00, I've created a changelog YAML for you.

Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

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

two minor things and I think this is good to go.

---
composite_id_parsed:
- skip:
version: " - 8.8.99"
Copy link
Member

Choose a reason for hiding this comment

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

With 8.9.0 being cut, you will need to update this as it will get released in 8.10 now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks for the reminder.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose you haven't pushed your local commit yet? Once you do, I will give it another review

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed it now. It must have failed when I tried it earlier and I missed it.

@quux00 quux00 force-pushed the profile/show-node-details branch from e52024f to 86f29d1 Compare June 23, 2023 15:25
Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

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

:shipit:

quux00 added 4 commits June 23, 2023 19:55
SearchProfileResults has additional fields for XContent output: node_id, cluster, index, shard_id.
It parses the existing composite ID using the new parseProfileShardId method, which reverses
the SeachShardTarget.toString method.

No new information is added here, merely the splitting out of the four pieces of information
in the profile shards "composite" id that is created by the SeachShardTarget.toString method.

Profile/shards output now has the form:
  "profile": {
    "shards": [
      {
        "id": "[2m7SW9oIRrirdrwirM1mwQ][blogs][0]",
        "node_id": "2m7SW9oIRrirdrwirM1mwQ",
        "shard_id": "0",
        "index": "blogs",
        "cluster": "(local)",
        "searches": [ ... ]
        ...
      },
      {
        "id": "[UngEVXTBQL-7w5j_tftGAQ][remote1:blogs][2]",
        "node_id": "UngEVXTBQL-7w5j_tftGAQ",
        "shard_id": "2",
        "index": "blogs",
        "cluster": "remote1",
        "searches": [ ... ]
        ...

where the latter is on a remote cluster and you can see that as the prefix on the index name.

Partially addresses elastic#25896
quux00 added 4 commits June 23, 2023 19:55
Added asserts to the SearchProfileResults.parseCompositeProfileShardId method to assert against invalid inputs

Added yamlRestTest for the new fields in the profile response.

Updated the existing unit test to use more randomization of inputs and to use the
SearchShardTarget.toString method to generate the compositeId (which is what happens in production)
…dTarget.toString to set the key for the SearchProfileShardResult map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants