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

Fix _alias/<alias> returning non-matching data streams #104145

Merged
merged 15 commits into from
Jan 29, 2024

Conversation

mattc58
Copy link
Contributor

@mattc58 mattc58 commented Jan 9, 2024

This fixes a bug where GET _alias/<alias> would return non-matching data streams. This happens when security is enabled and when the index pattern is changed to ["*',"-*"] and the data streams don't properly process that.

Fixes #96589.

@mattc58 mattc58 added >bug :Data Management/Data streams Data streams and their lifecycles Team:Data Management Meta label for data/management team v8.13.0 labels Jan 9, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @mattc58, I've created a changelog YAML for you.

@mattc58
Copy link
Contributor Author

mattc58 commented Jan 9, 2024

The new REST test can be run with: ./gradlew ':modules:data-streams:yamlRestTest' --tests "org.elasticsearch.datastreams.DataStreamsClientYamlTestSuiteIT.test {p0=data_stream/140_data_stream_aliases/Test get alias with non-matching data streams}" --info

It will fail with the current code with:

      - is_false: ds-first.aliases.my-alias

    [2024-01-10T03:34:49,505][INFO ][o.e.d.DataStreamsClientYamlTestSuiteIT] [test] Stash dump on test failure [{
      "stash" : {
        "body" : {
          "ds-first" : {
            "aliases" : {
              "my-alias" : { }
            }
          }
        }
      }
    }]

[snip]

        Caused by:
        java.lang.AssertionError: field [ds-first.aliases.my-alias] has a true value but it shouldn't
        Expected: ("" or a string equal to "false" ignoring case or "0")
             but: was "{}"
            at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
            at org.junit.Assert.assertThat(Assert.java:956)
            at org.elasticsearch.test.rest.yaml.section.IsFalseAssertion.doAssert(IsFalseAssertion.java:48)
            at org.elasticsearch.test.rest.yaml.section.Assertion.execute(Assertion.java:65)
            at org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.executeSection(ESClientYamlSuiteTestCase.java:558)
            ... 38 more

@mattc58 mattc58 added auto-backport Automatically create backport pull requests when merged and removed auto-backport Automatically create backport pull requests when merged labels Jan 9, 2024
@mattc58 mattc58 marked this pull request as ready for review January 9, 2024 19:19
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@elasticsearchmachine
Copy link
Collaborator

Hi @mattc58, I've updated the changelog YAML for you.

@mattc58 mattc58 marked this pull request as draft January 10, 2024 00:29
@mattc58 mattc58 marked this pull request as ready for review January 17, 2024 14:28
@mattc58 mattc58 requested a review from masseyke January 17, 2024 14:28
}

{
GetAliasesRequest request = new GetAliasesRequest();
Copy link
Member

Choose a reason for hiding this comment

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

Should we have a test in here that covers the exclusions case (like testFindAliasWithExclusion but for findDataStreamAliases? I don't know that we even claim to support it, but we get it virtually for free with what you've done.

@mattc58 mattc58 requested a review from masseyke January 23, 2024 16:53
.toList();
if (aliases.isEmpty() == false) {
result.put(requestedDataStream, aliases);
if (dsAliases.containsKey(requestedDataStream)) {
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 that this check is redundant now, right? In Metadata, the setter only puts things in the map that's returned if they are the things you passed in as the second argument to findDataStreamAliases.

Copy link
Member

Choose a reason for hiding this comment

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

That is, can you just return the result of findDataStreamAliases from this method?

*/
public Map<String, List<DataStreamAlias>> findDataStreamAliases(final String[] aliases, final String[] dataStreams) {
ImmutableOpenMap.Builder<String, List<DataStreamAlias>> mapBuilder = ImmutableOpenMap.builder();
Map<String, List<DataStreamAlias>> dataStreamAliases = dataStreamAliasesByDataStream();
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if at some point we'll need to start computing this outside of this method if users have a lot of data stream aliases. But doing it once per request doesn't seem all that bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if doing the analysis and guidelines suggested in #104456 would help guide us here. Maybe we could store aliases differently in cluster state.

Copy link
Member

@masseyke masseyke left a comment

Choose a reason for hiding this comment

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

LGTM. Seems like a big improvement over what we had.

---
"Test get alias with non-matching data streams":
- skip:
version: " - 8.12.1"
Copy link
Member

Choose a reason for hiding this comment

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

This is currently pointed at main (8.13.0) and the PR isn't labeled with 8.12.1. We'll need to make sure to remember backport it, or change this version if this doesn't get backported in time for 8.12.1

@mattc58 mattc58 added v8.12.1 auto-backport-and-merge Automatically create backport pull requests and merge when ready labels Jan 29, 2024
@mattc58
Copy link
Contributor Author

mattc58 commented Jan 29, 2024

@elasticsearchmachine run elasticsearch-ci/part-2

@mattc58 mattc58 merged commit de68d91 into elastic:main Jan 29, 2024
15 checks passed
@mattc58 mattc58 deleted the fix-96589-alias-datastreams branch January 29, 2024 21:22
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.12

mattc58 added a commit to mattc58/elasticsearch that referenced this pull request Jan 29, 2024
This fixes a bug where GET _alias/<alias> would return non-matching data streams
elasticsearchmachine pushed a commit that referenced this pull request Jan 30, 2024
… (#104880)

* Fix _alias/<alias> returning non-matching data streams (#104145)

This fixes a bug where GET _alias/<alias> would return non-matching data streams

* Remove problematic assertions

* Change to `containsInAnyOrder` in assertions for lists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-and-merge Automatically create backport pull requests and merge when ready >bug :Data Management/Data streams Data streams and their lifecycles Team:Data Management Meta label for data/management team v8.12.1 v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GET _alias/<alias> returns aliases for non-matching data streams
3 participants