-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Improve error message for non append-only writes that target data stream #60809
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
Improve error message for non append-only writes that target data stream #60809
Conversation
Pinging @elastic/es-core-features (:Core/Features/Data streams) |
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.
Thanks @martijnvg for fixing this, one small nit, otherwise LGTM
infe.setResources("index_expression", indexExpressions); | ||
if (excludedDataStreams) { | ||
// Allows callers to handle IndexNotFoundException differently based on whether data streams were excluded. | ||
infe.addMetadata("es.excluded_ds", "true"); |
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.
Maybe refactor es.excluded_ds
to named constant?
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. Left an optional comment about the error message wording and a question just for my own benefit.
request.concreteIndex(indexNameExpressionResolver.concreteWriteIndex(clusterState, request).getName()); | ||
} catch (IndexNotFoundException e) { | ||
if (request.includeDataStreams() == false && e.getMetadataKeys().contains("es.excluded_ds")) { | ||
throw new IllegalArgumentException("only write ops with op_type=create are allowed in data streams"); |
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.
throw new IllegalArgumentException("only write ops with op_type=create are allowed in data streams"); | |
throw new IllegalArgumentException("only write ops with an op_type of create are allowed in data streams"); |
concreteIndex = indexNameExpressionResolver.concreteWriteIndex(state, request.indicesOptions(), | ||
request.indices()[0], false, includeDataStreams); | ||
} catch (IndexNotFoundException e) { | ||
if (includeDataStreams == false && e.getMetadataKeys().contains("es.excluded_ds")) { |
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.
Just a question -- I don't understand why includeDataStreams == false
is here. I would have thought it would be the opposite if it were addressing the case of indexing into data streams though it does seem to work according to the tests you added.
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 don't think it is needed (because es.excluded_ds
is only set if includeDataStreams
is false
), but I like to keep it here to highlight that this check is only needed for op types other than create. If includeDataStreams
is false
then request.opType()
is not CREATE
.
…r_non_append_only_writes_targeting_ds
…eam (elastic#60874) Backport of elastic#60809 to 7.x branch. Closes elastic#60581
When a write op with
op_type
not equal tocreate
targets a data streams then the following error is returned:no such index [null]
. This isn't a meaningful error message. Also the the used exception (IndexNotFoundException
) will result in a 404 response code.This PR adds exception handling logic, so that a
IllegalArgumentException
is returned with a better error message.This exception will return a 400 response code instead.
Closes #60581