Skip to content

[WIP] Add headers parsing to ElasticsearchException#22675

Closed
tlrx wants to merge 3 commits intoelastic:masterfrom
tlrx:expirement-exception-header-parsing
Closed

[WIP] Add headers parsing to ElasticsearchException#22675
tlrx wants to merge 3 commits intoelastic:masterfrom
tlrx:expirement-exception-header-parsing

Conversation

@tlrx
Copy link
Copy Markdown
Member

@tlrx tlrx commented Jan 18, 2017

This is work in progress

When rendered to XContent, ElasticsearchException's headers and other metadata are added to the XContent as new fields/objects.

For example, a new CircuitBreakingException("Excessive stuff", 30L, 20L) is rendered as the following JSON:

    {
        "type": "circuit_breaking_exception",
        "reason": "Excessive stuff",
        "bytes_wanted": 30,
        "bytes_limit": 20
    }

The same exception with an internal header "es.uuid"="foo" and a custom header "bar"="baz" would be rendered as:

    {
        "type": "circuit_breaking_exception",
        "reason": "Excessive stuff",
        "uuid": "foo"
        "bytes_wanted": 30,
        "bytes_limit": 20,
        "header": {
            "bar": "baz"
        }
    }

When this JSON is parsed back, there is no way to know if bytes_wanted is an internal header or a metadata because only custom headers (ie, which does not start with "es.") are added as sub fields of a parent header field. The internal headers are just added in the stream. In the best world, headers and metadata would have their own namespaces to avoid name conflicts but for now we can just assume that everything is a header.

This commit changes the ElasticsearchException so that:

  • innerFromXContent() method is added and is in charge of parsing what is produced by innerToXContent()
  • every field/object is considered as a header
  • header objects/arrays names are flattened
  • header values are converted to String (because headers only accept strings)

tlrx added 3 commits January 18, 2017 11:31
When rendered to XContent, ElasticsearchException's headers and other metadata are added to the XContent as new fields/objects.

For example, a `new CircuitBreakingException("Excessive stuff", 30L, 20L)` is rendered as the following JSON:
{
    "type": "circuit_breaking_exception",
    "reason": "Excessive stuff",
    "bytes_wanted": 30,
    "bytes_limit": 20
}

The same exception with an internal header "es.uuid"="foo" and a custom header "bar"="baz" would be rendered as:
{
    "type": "circuit_breaking_exception",
    "reason": "Excessive stuff",
    "uuid": "foo"
    "bytes_wanted": 30,
    "bytes_limit": 20,
    "header": {
        "bar": "baz"
    }
}

When this JSON is parsed back, there is no way to know if "bytes_wanted" is an internal header or a metadata because only custom headers (ie, which does not start with "es.") are added as sub fields of a parent "header" field. The internal headers are just added in the stream. In the best world, headers and metadata would have their own namespaces to avoid name conflicts but for now we can just assume that everything is a header.

This commit changes the ElasticsearchException so that:
- innerFromXContent() method is added and is in charge of parsing what is produced by innerToXContent()
- every field/object is considered as a header
- header objects/arrays  names are flattened
- header values are converted to String (because headers only accept strings)
}
} else {
List<String> values = headers.getOrDefault(current, new ArrayList<>());
values.add(String.valueOf(value));
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.

after all, what would the parsed output of SearchPhaseExecutionException look like? I'm asking because that subclass prints out an array and potentially additional objects, I wonder how users would retrieve that additional info from the parsed ElasticsearchException.

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.

Additional objects are parsed as map, then the map keys are "flattened" and the map values converted to String, every field being added as a header. Then one can retrieve these info from headers with th right key name, there's a sample in the test testFromXContentWithExtraMetadataArrays()

@tlrx
Copy link
Copy Markdown
Member Author

tlrx commented Jan 25, 2017

This pull request has been supersede by #22703 and #22783.

@tlrx tlrx closed this Jan 25, 2017
@tlrx tlrx deleted the expirement-exception-header-parsing branch January 27, 2017 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants