-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Conversation
0e8036e
to
1efbe87
Compare
Pinging @elastic/es-search (Team:Search) |
Hi @quux00, I've created a changelog YAML for you. |
5dc8388
to
fcdd4be
Compare
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
server/src/main/java/org/elasticsearch/search/profile/SearchProfileResults.java
Show resolved
Hide resolved
fcdd4be
to
7440b1d
Compare
Hi @quux00, I've created a changelog YAML for you. |
There was a problem hiding this 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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
server/src/main/java/org/elasticsearch/search/profile/SearchProfileResults.java
Outdated
Show resolved
Hide resolved
e52024f
to
86f29d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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
…hardId regex to private static final var
…atch on known value
86f29d1
to
eec0fc8
Compare
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:
where the latter is on a remote cluster and you can see that as the prefix on the index name.
Partially addresses #25896