-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Start to uncouple deprecation handling from log4j #27955
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
Changes from all commits
38fc94d
01527c2
585af19
c6824e8
f792c60
a730054
bb5dc2a
910d276
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,9 @@ | |
| import org.elasticsearch.action.support.IndicesOptions; | ||
| import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
| import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
| import org.elasticsearch.common.LoggingDeprecationHandler; | ||
| import org.elasticsearch.common.ParseField; | ||
| import org.elasticsearch.common.ParseField.DeprecationHandler; | ||
| import org.elasticsearch.common.bytes.BytesArray; | ||
| import org.elasticsearch.common.bytes.BytesReference; | ||
| import org.elasticsearch.common.collect.MapBuilder; | ||
|
|
@@ -318,7 +320,10 @@ public CreateIndexRequest aliases(String source) { | |
| */ | ||
| public CreateIndexRequest aliases(BytesReference source) { | ||
| // EMPTY is safe here because we never call namedObject | ||
| try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, source)) { | ||
| // TODO LoggingDeprecationHandler probably should be visible to a request | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That wouldn't this kind of kill the whole idea of separating log4j from high level rest clients?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left it like this because I didn't want to change too many things in this PR. I'd love to change how this works but that is technically a breaking change for the transport client and the high level rest client and I didn't want to bury it with all the internal changes in this PR. Basically I think we should change this but I didn't want to do it now.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be fine with dealing with this in a separate PR. |
||
| // because the requests might be in a separate jar from core | ||
| try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, | ||
| LoggingDeprecationHandler.INSTANCE, source)) { | ||
| //move to the first alias | ||
| parser.nextToken(); | ||
| while ((parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
|
|
@@ -380,16 +385,19 @@ public CreateIndexRequest source(BytesReference source, XContentType xContentTyp | |
| */ | ||
| @SuppressWarnings("unchecked") | ||
| public CreateIndexRequest source(Map<String, ?> source) { | ||
| // TODO LoggingDeprecationHandler probably should be visible to a request | ||
| // because the requests might be in a separate jar from core | ||
| DeprecationHandler deprecationHandler = ParseField.UNSUPPORTED_OPERATION_DEPRECATION_HANDLER; | ||
| for (Map.Entry<String, ?> entry : source.entrySet()) { | ||
| String name = entry.getKey(); | ||
| if (SETTINGS.match(name)) { | ||
| if (SETTINGS.match(name, deprecationHandler)) { | ||
| settings((Map<String, Object>) entry.getValue()); | ||
| } else if (MAPPINGS.match(name)) { | ||
| } else if (MAPPINGS.match(name, deprecationHandler)) { | ||
| Map<String, Object> mappings = (Map<String, Object>) entry.getValue(); | ||
| for (Map.Entry<String, Object> entry1 : mappings.entrySet()) { | ||
| mapping(entry1.getKey(), (Map<String, Object>) entry1.getValue()); | ||
| } | ||
| } else if (ALIASES.match(name)) { | ||
| } else if (ALIASES.match(name, deprecationHandler)) { | ||
| aliases((Map<String, Object>) entry.getValue()); | ||
| } else { | ||
| // maybe custom? | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| import org.elasticsearch.action.support.WriteRequest; | ||
| import org.elasticsearch.action.support.replication.ReplicationRequest; | ||
| import org.elasticsearch.action.update.UpdateRequest; | ||
| import org.elasticsearch.common.LoggingDeprecationHandler; | ||
| import org.elasticsearch.common.Nullable; | ||
| import org.elasticsearch.common.ParseField; | ||
| import org.elasticsearch.common.Strings; | ||
|
|
@@ -304,7 +305,10 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null | |
|
|
||
| // now parse the action | ||
| // EMPTY is safe here because we never call namedObject | ||
| try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, data.slice(from, nextMarker - from))) { | ||
| // TODO LoggingDeprecationHandler is probably not appropriate here because this is a request | ||
| // because LoggingDeprecationHandler is a server side thing but this is a request | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's actually used in both server and client content. So, maybe we need to have another version of this method that accepts logger as a parameter and pass LoggingDeprecationHandler on the server side and IGNORING_DEPRECATION_HANDLER on the client. |
||
| try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, | ||
| LoggingDeprecationHandler.INSTANCE, data.slice(from, nextMarker - from))) { | ||
| // move pointers | ||
| from = nextMarker + 1; | ||
|
|
||
|
|
@@ -348,45 +352,45 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null | |
| if (token == XContentParser.Token.FIELD_NAME) { | ||
| currentFieldName = parser.currentName(); | ||
| } else if (token.isValue()) { | ||
| if (INDEX.match(currentFieldName)){ | ||
| if (INDEX.match(currentFieldName, parser.deprecationHandler())){ | ||
| if (!allowExplicitIndex) { | ||
| throw new IllegalArgumentException("explicit index in bulk is not allowed"); | ||
| } | ||
| index = parser.text(); | ||
| } else if (TYPE.match(currentFieldName)) { | ||
| } else if (TYPE.match(currentFieldName, parser.deprecationHandler())) { | ||
| type = parser.text(); | ||
| } else if (ID.match(currentFieldName)) { | ||
| } else if (ID.match(currentFieldName, parser.deprecationHandler())) { | ||
| id = parser.text(); | ||
| } else if (ROUTING.match(currentFieldName)) { | ||
| } else if (ROUTING.match(currentFieldName, parser.deprecationHandler())) { | ||
| routing = parser.text(); | ||
| } else if (PARENT.match(currentFieldName)) { | ||
| } else if (PARENT.match(currentFieldName, parser.deprecationHandler())) { | ||
| parent = parser.text(); | ||
| } else if (OP_TYPE.match(currentFieldName)) { | ||
| } else if (OP_TYPE.match(currentFieldName, parser.deprecationHandler())) { | ||
| opType = parser.text(); | ||
| } else if (VERSION.match(currentFieldName)) { | ||
| } else if (VERSION.match(currentFieldName, parser.deprecationHandler())) { | ||
| version = parser.longValue(); | ||
| } else if (VERSION_TYPE.match(currentFieldName)) { | ||
| } else if (VERSION_TYPE.match(currentFieldName, parser.deprecationHandler())) { | ||
| versionType = VersionType.fromString(parser.text()); | ||
| } else if (RETRY_ON_CONFLICT.match(currentFieldName)) { | ||
| } else if (RETRY_ON_CONFLICT.match(currentFieldName, parser.deprecationHandler())) { | ||
| retryOnConflict = parser.intValue(); | ||
| } else if (PIPELINE.match(currentFieldName)) { | ||
| } else if (PIPELINE.match(currentFieldName, parser.deprecationHandler())) { | ||
| pipeline = parser.text(); | ||
| } else if (FIELDS.match(currentFieldName)) { | ||
| } else if (FIELDS.match(currentFieldName, parser.deprecationHandler())) { | ||
| throw new IllegalArgumentException("Action/metadata line [" + line + "] contains a simple value for parameter [fields] while a list is expected"); | ||
| } else if (SOURCE.match(currentFieldName)) { | ||
| } else if (SOURCE.match(currentFieldName, parser.deprecationHandler())) { | ||
| fetchSourceContext = FetchSourceContext.fromXContent(parser); | ||
| } else { | ||
| throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]"); | ||
| } | ||
| } else if (token == XContentParser.Token.START_ARRAY) { | ||
| if (FIELDS.match(currentFieldName)) { | ||
| if (FIELDS.match(currentFieldName, parser.deprecationHandler())) { | ||
| DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead"); | ||
| List<Object> values = parser.list(); | ||
| fields = values.toArray(new String[values.size()]); | ||
| } else { | ||
| throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]"); | ||
| } | ||
| } else if (token == XContentParser.Token.START_OBJECT && SOURCE.match(currentFieldName)) { | ||
| } else if (token == XContentParser.Token.START_OBJECT && SOURCE.match(currentFieldName, parser.deprecationHandler())) { | ||
| fetchSourceContext = FetchSourceContext.fromXContent(parser); | ||
| } else if (token != XContentParser.Token.VALUE_NULL) { | ||
| throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]"); | ||
|
|
@@ -428,8 +432,10 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null | |
| .routing(routing) | ||
| .parent(parent); | ||
| // EMPTY is safe here because we never call namedObject | ||
| // TODO LoggingDeprecationHandler is probably not appropriate here because this is a request | ||
| // because LoggingDeprecationHandler is a server side thing but this is a request | ||
| try (XContentParser sliceParser = xContent.createParser(NamedXContentRegistry.EMPTY, | ||
| sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType))) { | ||
| LoggingDeprecationHandler.INSTANCE, sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType))) { | ||
| updateRequest.fromXContent(sliceParser); | ||
| } | ||
| if (fetchSourceContext != 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.
This comment gave me pause. I think it's somewhat misleading. Users can upgrade the version of the server, so they can do something about it. However, they might choose not to do that and this is perfectly fine. Maybe we can change this comment into something like "We use IGNORING_DEPRECATION_HANDLER because we are expected to work with deprecated fields while parsing responses from older version of elasticsearch and there is no need to notify users about every single occurrence of such field."
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.
Makes sense to me.
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 like that this makes us think about deprecated fields here.