-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Delegate toXContent logic from ClusterState to its member classes #48218 #48924
Conversation
… serialization for IndexMetaData. This test may sometimes fail due to JsonNode.equals may be order sensitive for deeply nested json structure
…a.toXContent, and note the difference both in code as comment and in serialization. This test may sometimes fail due to JsonNode.equals may be order sensitive for deeply nested json structure
Pinging @elastic/es-distributed (:Distributed/Distributed) |
… serialization for IndexTemplateMetaData This test may sometimes fail due to JsonNode.equals may be order sensitive for deeply nested json structure
…eMetaData.toXContent, and note the difference in serialization. This test may sometimes fail due to JsonNode.equals may be order sensitive for deeply nested json structure
…Content, and note the difference in serialization. This test may sometimes fail due to JsonNode.equals may be order sensitive for deeply nested json structure
… of testing serializaation directly
Hi @zacharymorn, first off I want to apologize for taking so long to review this. I've been waiting on some internal discussions that took a while to happen. I want to thank you especially for looking into the other places in ClusterState's toXContent that have this issue. We discussed this recently in the Distributed team sync, and we're going to:
We'll also review the code changes in this PR as usual soon. |
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've left some initial comments. I would prefer to start by parameterizing the code in MetaData.toXContent
to, depending on the context (API vs GATEWAY), emit different XContent. We can then step-by-step resolve the differences between the two. Also we need more detailed examples to see how the output between the two differs. A good first test would be to take a complex cluster state, use the old serialization method, and check that the new parameterized one in MetaData.toXContent
provides equivalent output.
@@ -82,8 +82,10 @@ public void testToXContent() throws IOException { | |||
" \"attributes\" : { }\n" + | |||
" }\n" + | |||
" },\n" + | |||
" \"metadata\" : {\n" + | |||
" \"meta-data\" : {\n" + |
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.
If anyone was relying on the stability of the cluster state APIs, this is definitely the biggest thing that would break them. I wonder if we should change MetaData.toXContent
to have metadata there, and be lenient in the MetaData.fromXContent
method, allowing both. This means that the internal storage format can handle the change, and the user-facing cluster state will be kept the same as well.
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.
An alternative would be to use meta-data
/ metadata
in MetaData.toXContent
depending on the context (API vs GATEWAY).
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.
Yes I think this makes sense. Will try to parametrize the code.
" \"aliases\" : [ ],\n" + | ||
" \"primary_terms\" : {\n" + | ||
" \"0\" : 0\n" + | ||
" \"index.max_script_fields\" : \"10\",\n" + |
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.
MetaData.toXContent could have flat_settings
defaulting to false
if the context is API. That means that the representation would stay the same here.
" \"index.number_of_replicas\" : \"0\",\n" + | ||
" \"index.number_of_shards\" : \"1\",\n" + | ||
" \"index.shard.check_on_startup\" : \"true\",\n" + | ||
" \"index.version.created\" : \"8000099\"\n" + |
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.
the version is hardcoded here, which means that this will break as soon as we do a version bump. Please use a variable as it used to be before.
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.
Will do.
coordinationMetaData().toXContent(builder, params); | ||
builder.endObject(); | ||
|
||
builder.startObject("templates"); |
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.
Would be good to have an example that shows how / whether templates are rendered differently 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.
I have it here as an intermediate commit bfc1103 . Please let me know if this look good.
builder.endObject(); | ||
|
||
builder.startObject("indices"); | ||
for (IndexMetaData indexMetaData : metaData()) { |
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 this change, we are now also exposing index metadata customs. I'm not sure if these might contain sensitive information. Need to double-check. We could perhaps omit these for API context.
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 I'm missing some knowledge about the potential sensitive information here in metadata custom. Let me see if I can find some documentation about it.
@@ -1205,6 +1211,23 @@ public static void toXContent(IndexMetaData indexMetaData, XContentBuilder build | |||
} | |||
builder.endArray(); | |||
|
|||
/* | |||
==== for the above, ClusterState.toXContent has the following ==== |
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.
sure, but how is this rendered differently? Can we see an example?
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.
Yes it's available here as an intermediate commit 4850acc . Please let me know if this looks good.
@ywelsch Yes I agree with the approach of seeing the changes in serialization as well. I did start my changes by generating an existing serialization of the cluster state (df24188), and each time I updated a portion of code I committed both the changes to code and to the serialization. In my last commit though, I removed the checked for serialization content and replaced it with a verification of delegating call (to member classes). I think the problem here is, as the existing serialization of a complex cluster state are new changes in my existing PR, it might be hard to use git to clearly shows the changes of serialization introduced by the PR globally, as they will always be viewed as new changes. Will it help if I create a separate PR to just check in the existing serialization, and track the updates to the serialization in this PR? |
yes, this PR is trying to do too many things at once. Let's start by having a PR first that parameterizes the code in |
@ywelsch As this current PR has too many commits to cleanly show the changes, I’ve made a new branch and PR #52743 to better track the changes in the new direction. I'll close this PR for now. As MetaData.toXContent is already parameterized as it checks for API context for certain serializations, I’ve organized the 4 commits in that PR as follows:
|
ClusterState.toXContent contains duplicate logic from its member classes such as IndexMetaData.toXContent and MetaData.toXContent etc. This PR is to remove the duplicate and delegate logic to those classes. For details, please refer to #48218