Skip to content

Correct display of warning header#10470

Merged
jbudz merged 4 commits intoelastic:masterfrom
jasontedor:warning-header
Feb 27, 2017
Merged

Correct display of warning header#10470
jbudz merged 4 commits intoelastic:masterfrom
jasontedor:warning-header

Conversation

@jasontedor
Copy link
Copy Markdown
Member

@jasontedor jasontedor commented Feb 20, 2017

Elasticsearch produces warning headers for the use of deprecated features. These warning headers can contain commas which breaks the splitting of multiple values on commas. Upstream Elasticsearch has changed the warning headers to be specification compliant so that these headers can be safely split (the warning text and warning date must be quoted, so splits should only occur on commas that are not contained in quotes). Additionally, the upstream change includes additional details that are not needed for display in Console (a warning code, the Elasticsearch version that produced the warning, and the warning date). This commit corrects the splitting logic in Console to only split on commas not contained in quotes, and to extract the warning text from each warning header.

Relates elastic/elasticsearch#23275

Elasticsearch produces warning headers for the use of deprecated
features. These warning headers can contain commas which breaks the
splitting of multiple values on commas. Upstream Elasticsearch has
changed the warning headers to be specification compliant so that these
headers can be safely split (the warning text and warning date must be
quoted, so splits should only occur on commas that are not contained in
quotes). Additionally, the upstream change includes additional details
that are not needed for display in Console (a warning code, the
Elasticsearch version that produced the warning, and the warning
date). This commit corrects the splitting logic in Console to only split
on commas not contained in quotes, and to extract the warning text from
each warning header.
@jasontedor
Copy link
Copy Markdown
Member Author

jasontedor commented Feb 20, 2017

@epixa I discussed this with @clintongormley. As it currently stands, this feature is buggy in case Elasticsearch sends back a warning header that contains a comma (for example, [groovy] scripts are deprecated, use [painless] scripts instead, relates elastic/elasticsearch#22986) as the header splitting mechanism splits on commas followed by a space which catches legitimate warning messages. Moreover, Elasticsearch is violating the specification for the format of warning headers. Therefore, we have targeted elastic/elasticsearch#23275 for v5.3.0 to correct the non-compliant headers, and then this enables the fix here so that the headers can be split correctly. Thus, this fix should go into v5.3.0 as well.

@epixa epixa added review and removed review labels Feb 21, 2017
@jbudz jbudz self-assigned this Feb 22, 2017
warnings = _.map(warnings.split(", "), function (warning) {
return "#! Deprecation: " + warning;
// pattern for valid warning header
var re = /\d{3} [^ ]+ \"([^"]*)\"( \"[^"]*\")/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this support escaped quotes in the message?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a good question but I do not think it's necessary. The warning headers produced by Elasticsearch will not contained escaped quotes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A regex to handle escaped quotes and escaped backslashes would look like this:

var re = /\d{3} \S+ \"((?:\\[\\"]|[^"])*)\"( \"(?:\\[\\"]|[^"])*\")/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Learning from the regex master: do we need the extra \\ in [\\"] ?

Copy link
Copy Markdown
Contributor

@clintongormley clintongormley Feb 23, 2017

Choose a reason for hiding this comment

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

Ah you've just pointed out a flaw in my regex. Not such a master now! In fact it should be:

"((?:[^"\\]|\\.)*)"

Which means:

  • match "
  • capture:
    • zero or more times: match any character except \ or " or match \ followed by any character
  • match "

So it'd match this correctly:

"Here is an embedded \\ and a \" quote and \n"

That handles any backslashed character, not just quotes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bah - ignore me. This would work (which is what I think you were suggesting):

"((?:\\"|[^"])*)"

Which says:

  • match *
  • capture:
    • zero or more times: match \" or any character except "
  • match "

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After additional discussion with @clintongormley and @bleskes, it has been agreed that we should allow escaped quotes in warning messages, so I will work on a change on both sides to support them. Thanks for raising the question @jbudz. 😄

var re = /\d{3} [^ ]+ \"([^"]*)\"( \"[^"]*\")/
// split on any comma that is followed by an even number of quotes
warnings = _.map(warnings.split(/, (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/), function (warning) {
var match = re.exec(warning)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if there's no match, accessing match[1] will cause a full screen fatal error. thoughts on a match !== null check?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a good point. The warning headers produced by Elasticsearch should always match this pattern but I think your suggestion to err on the side of safety is a good one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I pushed 7f98c48.

If the warning header from Elasticsearch comes back in the wrong format,
this could lead to the regex not matching which would lead to a
blow-up. While Elasticsearch should not do this, let us be defensive
here.
jbudz
jbudz previously approved these changes Feb 22, 2017
@tylersmalley tylersmalley self-assigned this Feb 22, 2017
@epixa
Copy link
Copy Markdown
Contributor

epixa commented Feb 22, 2017

I kicked off a new build on this because the old one aborted on jenkins: https://kibana-ci.elastic.co/job/elastic+kibana+pull-request+multijob-selenium/2722/console

Copy link
Copy Markdown
Member

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

LGTM - tested against #10470

Copy link
Copy Markdown
Contributor

@bleskes bleskes left a comment

Choose a reason for hiding this comment

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

Thanks @jasontedor for picking this side of the equation as well. Can we add a unit test for the regexes (I can help with where to put them and how to run). Also I think we should deal with escaping properly so we never have to worry about this again.

warnings = _.map(utils.splitOnUnquotedCommaSpace(warnings), function (warning) {
var match = re.exec(warning)
// extract the actual warning if there was a match
return "#! Deprecation: " + (match !== null ? match[1] : warning)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should unescape a match... Also, I wonder if it's got have all of this as a util method (i.e., extractDeprecationMessages ) and test it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I pushed 8a9f432.

});
}

utils.splitOnUnquotedCommaSpace = function (s) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fancy pants

Copy link
Copy Markdown
Contributor

@bleskes bleskes left a comment

Choose a reason for hiding this comment

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

Sweet. Thanks Jason!

@epixa
Copy link
Copy Markdown
Contributor

epixa commented Feb 27, 2017

Is this backwards compatible with the old warning headers? In other words, is it safe to merge even if the Elasticsearch PR isn't in?

@jbudz jbudz dismissed their stale review February 27, 2017 16:28

re-reviewing

@epixa
Copy link
Copy Markdown
Contributor

epixa commented Feb 27, 2017

The corresponding Elasticsearch PR went in, so my question is no longer valid. @jbudz can you merge/backport this to 5.3?

@epixa epixa added the review label Feb 27, 2017
@jbudz jbudz merged commit 38ca174 into elastic:master Feb 27, 2017
elastic-jasper added a commit that referenced this pull request Feb 27, 2017
Backports PR #10470

**Commit 1:**
Correct display of warning header

Elasticsearch produces warning headers for the use of deprecated
features. These warning headers can contain commas which breaks the
splitting of multiple values on commas. Upstream Elasticsearch has
changed the warning headers to be specification compliant so that these
headers can be safely split (the warning text and warning date must be
quoted, so splits should only occur on commas that are not contained in
quotes). Additionally, the upstream change includes additional details
that are not needed for display in Console (a warning code, the
Elasticsearch version that produced the warning, and the warning
date). This commit corrects the splitting logic in Console to only split
on commas not contained in quotes, and to extract the warning text from
each warning header.

* Original sha: 02896ea
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-20T20:44:14Z

**Commit 2:**
Safer regex handling

If the warning header from Elasticsearch comes back in the wrong format,
this could lead to the regex not matching which would lead to a
blow-up. While Elasticsearch should not do this, let us be defensive
here.

* Original sha: 7f98c48
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-22T20:23:35Z

**Commit 3:**
Stricter handling of warning headers

* Original sha: f14055c
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-24T19:08:28Z

**Commit 4:**
Add tests for deprecation messages

* Original sha: 8a9f432
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-27T15:42:56Z
elastic-jasper added a commit that referenced this pull request Feb 27, 2017
Backports PR #10470

**Commit 1:**
Correct display of warning header

Elasticsearch produces warning headers for the use of deprecated
features. These warning headers can contain commas which breaks the
splitting of multiple values on commas. Upstream Elasticsearch has
changed the warning headers to be specification compliant so that these
headers can be safely split (the warning text and warning date must be
quoted, so splits should only occur on commas that are not contained in
quotes). Additionally, the upstream change includes additional details
that are not needed for display in Console (a warning code, the
Elasticsearch version that produced the warning, and the warning
date). This commit corrects the splitting logic in Console to only split
on commas not contained in quotes, and to extract the warning text from
each warning header.

* Original sha: 02896ea
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-20T20:44:14Z

**Commit 2:**
Safer regex handling

If the warning header from Elasticsearch comes back in the wrong format,
this could lead to the regex not matching which would lead to a
blow-up. While Elasticsearch should not do this, let us be defensive
here.

* Original sha: 7f98c48
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-22T20:23:35Z

**Commit 3:**
Stricter handling of warning headers

* Original sha: f14055c
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-24T19:08:28Z

**Commit 4:**
Add tests for deprecation messages

* Original sha: 8a9f432
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-27T15:42:56Z
jbudz pushed a commit that referenced this pull request Feb 27, 2017
Backports PR #10470

**Commit 1:**
Correct display of warning header

Elasticsearch produces warning headers for the use of deprecated
features. These warning headers can contain commas which breaks the
splitting of multiple values on commas. Upstream Elasticsearch has
changed the warning headers to be specification compliant so that these
headers can be safely split (the warning text and warning date must be
quoted, so splits should only occur on commas that are not contained in
quotes). Additionally, the upstream change includes additional details
that are not needed for display in Console (a warning code, the
Elasticsearch version that produced the warning, and the warning
date). This commit corrects the splitting logic in Console to only split
on commas not contained in quotes, and to extract the warning text from
each warning header.

* Original sha: 02896ea
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-20T20:44:14Z

**Commit 2:**
Safer regex handling

If the warning header from Elasticsearch comes back in the wrong format,
this could lead to the regex not matching which would lead to a
blow-up. While Elasticsearch should not do this, let us be defensive
here.

* Original sha: 7f98c48
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-22T20:23:35Z

**Commit 3:**
Stricter handling of warning headers

* Original sha: f14055c
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-24T19:08:28Z

**Commit 4:**
Add tests for deprecation messages

* Original sha: 8a9f432
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-27T15:42:56Z
jbudz pushed a commit that referenced this pull request Feb 27, 2017
Backports PR #10470

**Commit 1:**
Correct display of warning header

Elasticsearch produces warning headers for the use of deprecated
features. These warning headers can contain commas which breaks the
splitting of multiple values on commas. Upstream Elasticsearch has
changed the warning headers to be specification compliant so that these
headers can be safely split (the warning text and warning date must be
quoted, so splits should only occur on commas that are not contained in
quotes). Additionally, the upstream change includes additional details
that are not needed for display in Console (a warning code, the
Elasticsearch version that produced the warning, and the warning
date). This commit corrects the splitting logic in Console to only split
on commas not contained in quotes, and to extract the warning text from
each warning header.

* Original sha: 02896ea
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-20T20:44:14Z

**Commit 2:**
Safer regex handling

If the warning header from Elasticsearch comes back in the wrong format,
this could lead to the regex not matching which would lead to a
blow-up. While Elasticsearch should not do this, let us be defensive
here.

* Original sha: 7f98c48
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-22T20:23:35Z

**Commit 3:**
Stricter handling of warning headers

* Original sha: f14055c
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-24T19:08:28Z

**Commit 4:**
Add tests for deprecation messages

* Original sha: 8a9f432
* Authored by Jason Tedor <jason@tedor.me> on 2017-02-27T15:42:56Z
@jbudz
Copy link
Copy Markdown
Contributor

jbudz commented Feb 27, 2017

5.3: 2a52a9d
5.x/5.4: 4b954d4

@jasontedor
Copy link
Copy Markdown
Member Author

Thanks all for the reviews.

@jasontedor jasontedor deleted the warning-header branch March 1, 2017 02:16
dakrone added a commit to dakrone/es-mode that referenced this pull request Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants