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

Send HTTP Warning Header(s) for any Deprecation Usage from a REST request #17804

Merged

Conversation

pickypg
Copy link
Member

@pickypg pickypg commented Apr 16, 2016

This adds support for ThreadContexts to maintain unique Response headers (repeated header values are ignored) in addition to Request headers. In particular, this enables REST requests (e.g., PUT /test) that hop across the nodes to properly return headers as part of the overall request. With the response headers Thread aware thanks to the ThreadContext, we can associate individual requests with deprecation logging and therefore warn developers when they unwittingly use deprecated features:

PUT /test
{
  "mappings": {
    "type": {
      "properties": {
        "field": {
          "type": "string"
        },
        "field2": {
          "type": "string"
        }
      }
    }
  }
}

The headers that would get returned by this would be:

HTTP/1.1 200 OK
Warning: The [string] field is deprecated, please use [text] or [keyword] instead on [field]
Warning: The [string] field is deprecated, please use [text] or [keyword] instead on [field2]
Content-Type: application/json; charset=UTF-8
Content-Length: 21

Alongside that feature, this adds a DeprecationRestHandler that logs a deprecation warning whenever it is used, but it otherwise behaves identically to normal RestHandlers. This allows REST APIs to be deprecated in a consistent manner instead of dropped without any non-documentation-level deprecation warnings in advance.

Closes #17687

@pickypg pickypg added >enhancement :Core/Infra/Logging Log management and logging utilities :Core/Infra/REST API REST infrastructure and utilities v2.4.0 v5.0.0-alpha2 v2.3.2 review labels Apr 16, 2016
@pickypg pickypg force-pushed the feature/deprecated-rest-handler-17687 branch from 8235156 to f6e5a18 Compare April 16, 2016 01:05
*
* @return {@code true} if the {@code value} is not obviously wrong.
*/
public static boolean validHeaderValue(String value) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this method belongs on Strings, especially since it's only used in only place. I'd be fine with it as a static package-private method on DeprecationRestChannel so it's visible for testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I honestly think that it should be used in other places.

Copy link
Member

Choose a reason for hiding this comment

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

That's probably correct, but right now it's not and I don't think Strings is the right place anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to DeprecationRestChannel and also added String requireValidHeader(String value) that behaves similar to Objects.requireNonNull to use for all creations. I did leave it as public as it's used by DeprecationRestHandler (even though they're in the same package).

@pickypg pickypg force-pushed the feature/deprecated-rest-handler-17687 branch from f6e5a18 to c1d086a Compare April 16, 2016 01:09
@@ -1404,7 +1404,7 @@ private final EngineConfig newEngineConfig(EngineConfig.OpenMode openMode, Trans
return new EngineConfig(openMode, shardId,
threadPool, indexSettings, warmer, store, deletionPolicy, indexSettings.getMergePolicy(),
mapperService.indexAnalyzer(), similarityService.similarity(mapperService), codecService, shardEventListener, translogRecoveryPerformer, indexCache.query(), cachingPolicy, translogConfig,
indexSettings.getSettings().getAsTime(IndexingMemoryController.SHARD_INACTIVE_TIME_SETTING, IndexingMemoryController.SHARD_DEFAULT_INACTIVE_TIME));
IndexingMemoryController.SHARD_INACTIVE_TIME_SETTING.get(indexSettings.getSettings()));
Copy link
Member

Choose a reason for hiding this comment

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

This too is confusing.

/**
* Attempts to do a scatter/gather request that expects unique responses per sub-request.
*/
@AwaitsFix(bugUrl = "")
Copy link
Member

Choose a reason for hiding this comment

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

can we add text here/open up a issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #19222 (and placed it appropriately)

@pickypg pickypg force-pushed the feature/deprecated-rest-handler-17687 branch 2 times, most recently from 4f44659 to af4fc01 Compare July 5, 2016 20:35
@pickypg
Copy link
Member Author

pickypg commented Jul 5, 2016

@jaymode Please take a second pass now that I have rebased it back onto master. I think it's ready to merge with all tests passing.

}

/**
* Note: {@code threadContexts} <em>must</em> be a modifiable {@link Set} so that stale contexts can be removed.
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 it would be simpler to have the node remove its threadcontext from here on close

@jaymode
Copy link
Member

jaymode commented Jul 6, 2016

left one comment, other than that LGTM

@pickypg pickypg force-pushed the feature/deprecated-rest-handler-17687 branch from af4fc01 to 8079da3 Compare July 6, 2016 22:55
This adds a new proxy for RestHandlers and RestControllers so that requests made
to deprecated REST APIs can be automatically logged in the ES logs via the
DeprecationLogger as well as via a "Warning" header (RFC-7234) for all responses.
@pickypg pickypg force-pushed the feature/deprecated-rest-handler-17687 branch from dd44506 to b927cfe Compare July 6, 2016 23:52
@pickypg pickypg removed the review label Jul 6, 2016
@pickypg pickypg merged commit b927cfe into elastic:master Jul 6, 2016
@pickypg pickypg changed the title Add DeprecationRestHandler to automatically log deprecated REST calls Send HTTP Warning Header(s) for any Deprecation Usage from a REST request Jul 7, 2016
@pickypg pickypg deleted the feature/deprecated-rest-handler-17687 branch July 7, 2016 17:34
@frioux
Copy link

frioux commented Jan 17, 2018

In case anyone in the internet superfuture runs into this like we did, this can pretty easily cause a long enough set of headers that nginx cannot even parse the response, and thus can cause pretty serious outages. Would be great if it could be disabled entirely, but you can set proxy_buffer_size to something higher to resolve it at least temporarily.

@jasontedor
Copy link
Member

@frioux Can you share the contents of these large responses? I would be interested in seeing if there are headers that we need to de-duplicate (we do this already to some extent, this is part of what pushes my interest here).

@frioux
Copy link

frioux commented Jan 18, 2018

HTTP/1.1 200 OK
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
Warning: 299 Elasticsearch-5.4.0-780f8c4 "The [string] field is deprecated, please use [text] or [keyword] instead on [REDACTED]" "Wed, 17 Jan 2018 19:03:29 GMT"
content-type: application/json; charset=UTF-8
content-encoding: gzip
transfer-encoding: chunked

1

Of course instead of REDACTED it was a distinct field for each thing. 12k is a lot of data to jam into headers ;)

@jasontedor
Copy link
Member

Okay; it is because it's a distinct field. Thanks for that, I will see what, if anything, can be done (I am doubtful because of the way these are collected).

@frioux
Copy link

frioux commented Jan 18, 2018

It would be good to limit this, because this is pretty gnarly to debug (I could only do it with a network trace) and anyone who puts nginx in front of ES would run into it.

@jasontedor
Copy link
Member

I agree with you. I opened #28301 and this work is assigned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Logging Log management and logging utilities :Core/Infra/REST API REST infrastructure and utilities >enhancement release highlight v5.0.0-alpha5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants