-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add the cluster version to enrich policies #45021
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
Conversation
|
Pinging @elastic/es-core-features |
martijnvg
left a comment
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.
Looks good. Left a few comments.
| private final List<String> indices; | ||
| private final String enrichKey; | ||
| private final List<String> enrichValues; | ||
| private Version versionCreated; |
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.
make final?
| in.readString(), | ||
| in.readStringList() | ||
| ); | ||
| if (in.readBoolean()) { |
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.
and then:
if (in.readBoolean()) {
version = Version.readVersion(in);
} else {
version = null;
}?
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.
Is the idea here then to just make the policy object fully immutable, and when storing it make a copy with the version set before saving it to the cluster state? I think I can manage that.
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, that works.
Or we can set version to Version.CURRENT if version is null in the 2nd constructor?
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 what Version.V_EMPTY is for.
+1 to remove boolean in favor of V_EMPTY if null.
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'm not against setting it to Version.CURRENT if it would be null otherwise. Does it make sense that a user could create a policy with version_created already set to a version? Do we care to limit that?
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.
+1 to always set to Version.CURRENT if null.
Does it make sense that a user could create a policy with version_created already set to a version?
nope
Do we care to limit that?
Doesn't your validation already do that ?
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 validation will fail if we set the version to Version.CURRENT in the event that it's null - If the user ends up not providing the version in the request, when the object is deserialized from XContent, the version will be null, which will mean it would get set to CURRENT, thus removing any way to tell if a user actually set the version or not.
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.
What if do this:
Add an argument to fromXContent:
public static EnrichPolicy fromXContent(XContentParser parser, boolean fromAPI) throws IOException {
return PARSER.parse(parser, fromAPI);
}
Change parsers' context type from void to Boolean:
private static final ConstructingObjectParser<EnrichPolicy, Boolean> PARSER = new ConstructingObjectParser<>("policy",
Change parser:
parser.declareField(ConstructingObjectParser.optionalConstructorArg(),
(p, fromApi) -> {
if (fromApi) {
// fail
}
return Version.fromString(p.text());
},
VERSION_CREATED,
ObjectParser.ValueType.STRING
);
This way we fail if a version is provided via api and otherwise we're ok with a version being provided?
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.
btw I'm happy with the PR as is. I don't feel strong about this (^) any more.
| builder.array(INDICES.getPreferredName(), indices.toArray(new String[0])); | ||
| builder.field(ENRICH_KEY.getPreferredName(), enrichKey); | ||
| builder.array(ENRICH_VALUES.getPreferredName(), enrichValues.toArray(new String[0])); | ||
| if (versionCreated != null) { |
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.
Perhaps we should only serialize versionCreated if params.include_version is set to true? It should default to true, and in get and list policy api we would then set it to false. This way when the user adds a policy and then returns it via get policy api then he sees the exact content that was submitted.
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 made this change, but it looks like Strings.toString(this) does not use include_version and can lead to some strange assert messages when checking equals on two policy objects where one has a version set and the other does not:
java.lang.AssertionError:
Expected: <{"type":"exact_match","indices":["index"],"enrich_key":"key","enrich_values":["val1"]}>
but: was <{"type":"exact_match","indices":["index"],"enrich_key":"key","enrich_values":["val1"]}>
I don't think this is necessarily bad, but it can be confusing.
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.
Agreed this can be confusing, but I think it is ok. This things are easy to spot in debug mode.
Add it as a constructor argument. Only serialize it to XContent if include_version is set
|
@elasticmachine update branch |
|
@elasticmachine update branch |
|
@elasticmachine run elasticsearch-ci/1 |
martijnvg
left a comment
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.
LGTM
|
Im not sure i like |
|
@elasticmachine update branch |
Adds the Elasticsearch version as a field on the EnrichPolicy object
This is a reimplementation of #44595 which just adds the Elasticsearch version as a field on the EnrichPolicy object directly instead of creating a separate metadata object to hold it. This change has the advantage of not intrusively modifying the get policy response, and having a smaller ripple through the code base, while avoiding having a separate map for policy metadata keyed by policy name in the
EnrichMetadataclass.