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

Get Aliases with wildcard exclusion expression #34230

Merged
merged 13 commits into from
Jan 29, 2019

Conversation

albertzaharovits
Copy link
Contributor

@albertzaharovits albertzaharovits commented Oct 2, 2018

#33518 added support for wildcard expressions for aliases resolution.
However, the REST handler will re-parse the expression on its own to
identify aliases missing from the response and issue a 404 and message.
This logic does not deal with wildcard exclusions (-...*). Consequently,
extraneous 404s were returned for aliases that were truthfully excluded,
as opposed to be missing.

Example:

curl -X PUT "localhost:9200/index" -H "Content-Type: application/json" -d'
{
  "aliases": {
    "alias1": {},
    "alias2": {}
  }
}
'
curl -X GET "localhost:9200/_alias/alias*,-alias2?pretty"
{
  "error" : "alias [-alias2] missing",
  "status" : 404,
  "index" : {
    "aliases" : {
      "alias1" : { }
    }
  }
}

The result is correct but the 404 is not.

This PR adds the code in the REST layer that will parse exclusion wildcard
expressions, together with REST tests.
The existing code issued 404s for wildcards as well as explicit indices.
In an expression with exclude wildcards (-...*) followed by following wildcards,
there is no way to tell if the include wildcard produced no results or
they were subsequently excluded (in the general case).
Therefore, the proposed change is breaking the behavior of 404s for
wildcards. Specifically, no 404s will be returned for wildcards, even
if they are not followed by exclude wildcards or the exclude wildcards
could not possibly exclude what has previously been included
.

Depends on: #34144
Relates: #33805

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

albertzaharovits added a commit to albertzaharovits/elasticsearch that referenced this pull request Oct 2, 2018
@javanna
Copy link
Member

javanna commented Oct 3, 2018

Thanks a lot for your effort @albertzaharovits and the super clear description!

I haven't reviewed this thoroughly yet, but given that we are breaking the behaviour of get aliases API in some circumstances in order to fix a bug, I wonder if it's worth starting the discussion on #30536 with the team, just to make sure that we move in the right direction long-term. Also, I believe aliases exclusions were not released yet, so we can always consider to back them off of 6.5 while we figure out what to do with get aliases (though this sounds a bit extreme).

Would it be possible to have a couple of examples about the scenarios affected by the breakage, and the difference before and after the change? We may also come to the conclusion that it's not that bad.

@albertzaharovits
Copy link
Contributor Author

Thanks for the speedy feedback @javanna !

I will add a description of the problem about missing
wildcards in the issue you have pointed me to.

Another thing I just realized is that the REST tests I have
added are failing. Right now, they are failing because
the Security code isn't digging wildcard exclusions, dealt
with in #34144 . But, moving the tests there would not solve
it because these tests cover functionality implemented in
this PR. So, I'll be marking this PR as dependent on #34144.

@jakelandis
Copy link
Contributor

jakelandis commented Jan 14, 2019

@albertzaharovits - What do you need to move this PR forward ? Also, is this breaking change ?

@albertzaharovits
Copy link
Contributor Author

Hi @jakelandis

What do you need to move this PR forward ?

A review :)

Also, is this breaking change ?

Yes, wildcards that are not present in the response will not be reported as missing anymore.

Therefore, the proposed change is breaking the behavior of 404s for
wildcards. Specifically, no 404s will be returned for wildcards, even
if they are not followed by exclude wildcards or the exclude wildcards
could not possibly exclude what has previously been included.

@original-brownbear
Copy link
Member

Jenkins retest this please

@javanna
Copy link
Member

javanna commented Jan 16, 2019

heya @albertzaharovits thanks for updating the description, could you also add some examples about the scenarios affected by the breakage please, with responses before and after your change? Although it's a bug-fix, I guess we need to document the breakage somewhere?

@albertzaharovits
Copy link
Contributor Author

albertzaharovits commented Jan 21, 2019

Hi @javanna ,

What this changes is the response of the get alias request. From what I can tell, It is not described (documented) anywhere (though it is parsed by yml REST tests), this is why I have not described the breaking behavior in the documentation.
Indeed, I think it is better to describe the change with examples:

# setup
curl -X PUT "localhost:9200/index" -H "Content-Type: application/json" -d'
{
  "aliases": {
    "foo": {},
    "foobar": {}
  }
}'

# BEFORE

curl -X GET "localhost:9200/_alias/baz*?pretty"
{
  "error" : "alias [baz*] missing",
  "status" : 404
}

curl -X GET "localhost:9200/_alias/baz*,foobar*?pretty"
{
  "error" : "alias [baz*] missing",
  "status" : 404,
  "index" : {
    "aliases" : {
      "foobar" : { }
    }
  }
}

curl -X GET "localhost:9200/_alias/baz*,foo*?pretty"
{
  "error" : "alias [baz*] missing",
  "status" : 404,
  "index" : {
    "aliases" : {
      "foo" : { },
      "foobar" : { }
    }
  }
}

# But the `error` message is completely off when using exclusions (wildcards or not)

curl -X GET "localhost:9200/_alias/foob*,-foo*?pretty"
{
  "error" : "alias [-foo*] missing",
  "status" : 404,
  "index" : {
    "aliases" : {
      "foobar" : { }
    }
  }
}

curl -X GET "localhost:9200/_alias/foo*,-foob*?pretty"
{
  "error" : "alias [-foob*] missing",
  "status" : 404,
  "index" : {
    "aliases" : {
      "foo" : { },
      "foobar" : { }
    }
  }
}

# AFTER 

curl -X GET "localhost:9200/_alias/baz*?pretty"
{ }

curl -X GET "localhost:9200/_alias/baz*,foobar*?pretty"
{
  "index" : {
    "aliases" : {
      "foobar" : { }
    }
  }
}

curl -X GET "localhost:9200/_alias/baz*,foo*?pretty"
{
  "index" : {
    "aliases" : {
      "foo" : { },
      "foobar" : { }
    }
  }
}

curl -X GET "localhost:9200/_alias/foob*,-foo*?pretty"
{ }

curl -X GET "localhost:9200/_alias/foo*,-foob*?pretty"
{
  "index" : {
    "aliases" : {
      "foo" : { }
    }
  }
}

As you can see, the breaking change is that -alias* OR alias* are not reported as missing (error message and 404).

@albertzaharovits
Copy link
Contributor Author

16:04:22 Tests with failures:
16:04:22 - org.elasticsearch.client.indices.PutMappingRequestTests.testFromXContent

run gradle build tests 1

@albertzaharovits
Copy link
Contributor Author

https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request-2/5210/console

17:12:08 Tests with failures:
17:12:08 - org.elasticsearch.upgrades.CCRIT.testAutoFollowing

run gradle build tests 2

@albertzaharovits
Copy link
Contributor Author

https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request-2/5245/console
FAILURE 0.02s J4 | PutRoleRequestTests.testSerialization <<< FAILURES!

run gradle build tests 2

@albertzaharovits
Copy link
Contributor Author

./gradlew :server:unitTest -Dtests.seed=10ECBEF210621EE7 -Dtests.class=org.elasticsearch.index.engine.InternalEngineTests -Dtests.method="testEngineMaxTimestampIsInitialized" -Dtests.security.manager=true -Dtests.locale=fr-FR -Dtests.timezone=Asia/Yangon -Dcompiler.java=11 -Druntime.java=8

Probably tracked by #37684 (comment)

run gradle build tests 1

@albertzaharovits
Copy link
Contributor Author

run gradle build tests 1

@albertzaharovits
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/1

@albertzaharovits
Copy link
Contributor Author

https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request-2/5654/consoleFull

08:33:54
08:33:54 > Task :x-pack:plugin:ccr:internalClusterTest FAILED
08:33:54 Tests with failures:
08:33:54 - org.elasticsearch.xpack.ccr.FollowerFailOverIT.testReadRequestsReturnsLatestMappingVersion
08:33:54 - org.elasticsearch.xpack.ccr.FollowerFailOverIT.testFailOverOnFollower

@elasticmachine run elasticsearch-ci/2

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

I am good with the change, I don't think we can avoid the breakage and it's not a big deal. I do wish that we went forward discussing #30536 meanwhile, given that this PR was first opened months ago. Can that be discussed at some point soon? Thanks for fixing this!!

if (Regex.simpleMatch(pattern, aliasName)) {
matches.add(pattern);
continue outer;
// compute explicitly requested aliases that have are not returned in the result
Copy link
Member

Choose a reason for hiding this comment

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

it would be great to have a unit test for this code. Otherwise we only rely on yaml tests to test it. Could be done as a followup.

@albertzaharovits
Copy link
Contributor Author

@javanna I have added the unit tests https://github.com/elastic/elasticsearch/pull/34230/files#diff-a4a22111aebdc6f8578f82fdf9bd5617

They test the alias wildcard logic in the scope of this PR.
I'll be grinding through CI and then merge.

@albertzaharovits albertzaharovits merged commit d05a4b9 into elastic:master Jan 29, 2019
@albertzaharovits albertzaharovits deleted the rest-get-alias branch January 29, 2019 16:56
albertzaharovits added a commit that referenced this pull request Jan 29, 2019
This commit adds the code in the HTTP layer that will parse exclusion wildcard
expressions.
The existing code issues 404s for wildcards as well as explicit indices.
But, in general, in an expression with exclude wildcards (-...*) following other
include wildcards, there is no way to tell if the include wildcard produced no
results or they were subsequently excluded.
Therefore, the proposed change is breaking the behavior of 404s for
wildcards. Specifically, no 404s will be returned for wildcards, even
if they are not followed by exclude wildcards or the exclude wildcards
could not possibly exclude what has previously been included.
Only explicitly requested aliases will be called out as missing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates v6.7.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants