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

Watcher inconsistencies with hidden indices #65148

Closed
joegallo opened this issue Nov 17, 2020 · 5 comments · Fixed by #65332
Closed

Watcher inconsistencies with hidden indices #65148

joegallo opened this issue Nov 17, 2020 · 5 comments · Fixed by #65332
Assignees
Labels

Comments

@joegallo
Copy link
Contributor

joegallo commented Nov 17, 2020

Given this setup:

PUT ordinary-index-2020.11.17/_doc/1
{
  "foo":"bar"
}

PUT hidden-index-2020.11.17/_doc/1
{
  "foo":"bar"
}

PUT hidden-index-2020.11.17/_settings
{
   "index.hidden": true
}

PUT _watcher/watch/some-watch
{
  "trigger" : {
    "schedule" : {
      "yearly" : { "in" : "january" }
    }
  },
  "input" : {
    "search" : {
      "request" : {
        "indices" : [ "ordinary-index*" ],
        "body" : {
          "query" : {
            "match_all" : {}
          }
        }
      }
    }
  },
  "actions" : {
    "log_error" : {
      "logging" : {
        "text" : "ctx.payload.hits.total was {{ctx.payload.hits.total}}"
      }
    }
  }
}

POST _watcher/watch/some-watch/_execute
{
  "record_execution" : true
}

You will end up with these indices on a fresh 7.x cluster:

GET _cat/indices?s=index&v&expand_wildcards=all
health status index                          uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .ds-ilm-history-5-000001       EhTUkJclTzugXWOV9H9Iiw   1   0          4            0     16.8kb         16.8kb
green  open   .watcher-history-13-2020.11.17 fjsVgpL3Rl-Regpd65Y_1A   1   0          2            0     13.1kb         13.1kb
green  open   .watches                       rzufqdImQKadvUQxJUm7cg   1   0          1            0      7.9kb          7.9kb
yellow open   hidden-index-2020.11.17        qNiLM9g1QsyPja9-sMnVkQ   1   1          1            0      3.7kb          3.7kb
yellow open   ordinary-index-2020.11.17      qHRVJZSFT_WRsMDE5JYkZQ   1   1          1            0      3.7kb          3.7kb

Note, in particular, that .watcher-history-13-2020.11.17 is hidden:

GET .watcher-history-13-2020.11.17/_settings
{
  ".watcher-history-13-2020.11.17" : {
  [...]
        "hidden" : "true",
  [...]
  }
}

Then the following watcher execution template results in sometimes surprising results:

POST _watcher/watch/_execute
{
  "watch" : {
    "trigger" : {
      "schedule" : {
        "yearly" : { "in" : "january" }
      }
    },
    "input" : {
      "search" : {
        "request" : {
          # see snippets below
          "body" : {
            "query" : {
              "match_all" : {}
            }
          }
        }
      }
    },
    "actions" : {
      "log_error" : {
        "logging" : {
          "text" : "ctx.payload.hits.total was {{ctx.payload.hits.total}}"
        }
      }
    }
  }
}

Search request snippets and results:

"indices" : [ "ordinary-index-*" ],
-->
 "logged_text" : "ctx.payload.hits.total was 1" # unsurprising, it's not hidden
"indices" : [ "hidden-index-*" ],
-->
 "logged_text" : "ctx.payload.hits.total was 0" # unsurprising, it's hidden
"indices" : [ "hidden-index-*" ],
"indices_options" : {
  "expand_wildcards" : "all"
},
-->
 "logged_text" : "ctx.payload.hits.total was 0" # surprising, 'all' didn't work (potential bug A)
"indices" : [ ".watcher-history-*" ],
-->
"logged_text" : "ctx.payload.hits.total was 1" # surprising, since it *is* hidden (potential bug B)

Potential bug A

It looks like WatcherSearchTemplateRequest needs to learn about hidden rather than just open and closed.

Potential bug B

It's not clear to me why this is happening. 😬

@joegallo joegallo added >bug :Data Management/Watcher needs:triage Requires assignment of a team area label labels Nov 17, 2020
@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Nov 17, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (Team:Core/Features)

@joegallo
Copy link
Contributor Author

In the same space as potential bug B, and indeed perhaps as an extension of the same bug, is the following behavior:

GET ordinary-index-*/_count
--> 1 # no surprise here

GET hidden-index-*/_count
--> 0 # no surprise here, it is hidden after all

GET hidden-index-*/_count?expand_wildcards=all
--> 1 # no surprise here

GET .watcher-history-*/_count
--> 1 # wait, I thought .watcher-history-13-2020.11.17 was hidden?

@jaymode
Copy link
Member

jaymode commented Nov 17, 2020

Potential bug A

You're correct, this is a bug where watcher needs to know about hidden :(.

Potential bug B

This is expected and the naming of the pattern indicates this is an attempt to access a hidden index. The hidden paradigm is kind of like *nix shells and dot files where they are hidden unless you specify a pattern that begins with a . like .e* or .ss*. Does that make sense?

@jaymode jaymode self-assigned this Nov 17, 2020
@joegallo
Copy link
Contributor Author

Does that make sense?

Yes, I think so. Essentially GET .watcher-history-*/_count is implicitly ?expand_wildcards=all (or, well, maybe hidden) because of the leading dot at the beginning of the wildcard, right?

@jaymode
Copy link
Member

jaymode commented Nov 18, 2020

Essentially GET .watcher-history-*/_count is implicitly ?expand_wildcards=all (or, well, maybe hidden) because of the leading dot at the beginning of the wildcard, right?

It is essentially adding hidden as an expand wildcard option (not exactly how it is implemented but how it functions)

@romseygeek romseygeek removed the needs:triage Requires assignment of a team area label label Nov 20, 2020
jaymode added a commit to jaymode/elasticsearch that referenced this issue Nov 20, 2020
Watcher has a search template that stores indices options to be used as
part of a search during watch execution, but this was not updated to be
aware of hidden indices and the `hidden` expand_wildcards option. This
change makes use of the `IndicesOptions#toXContent` method in Watcher,
which already handles the new value. Additionally, the XContent parsing
is moved to the IndicesOptions class so that we will be less likely to
miss updating this in the future.

Closes elastic#65148
jaymode added a commit that referenced this issue Nov 23, 2020
Watcher has a search template that stores indices options to be used as
part of a search during watch execution, but this was not updated to be
aware of hidden indices and the `hidden` expand_wildcards option. This
change makes use of the `IndicesOptions#toXContent` method in Watcher,
which already handles the new value. Additionally, the XContent parsing
is moved to the IndicesOptions class so that we will be less likely to
miss updating this in the future.

Closes #65148
jaymode added a commit to jaymode/elasticsearch that referenced this issue Nov 23, 2020
Watcher has a search template that stores indices options to be used as
part of a search during watch execution, but this was not updated to be
aware of hidden indices and the `hidden` expand_wildcards option. This
change makes use of the `IndicesOptions#toXContent` method in Watcher,
which already handles the new value. Additionally, the XContent parsing
is moved to the IndicesOptions class so that we will be less likely to
miss updating this in the future.

Closes elastic#65148
Backport of elastic#65332
jaymode added a commit that referenced this issue Nov 23, 2020
Watcher has a search template that stores indices options to be used as
part of a search during watch execution, but this was not updated to be
aware of hidden indices and the `hidden` expand_wildcards option. This
change makes use of the `IndicesOptions#toXContent` method in Watcher,
which already handles the new value. Additionally, the XContent parsing
is moved to the IndicesOptions class so that we will be less likely to
miss updating this in the future.

Closes #65148
Backport of #65332
jaymode added a commit that referenced this issue Nov 23, 2020
Watcher has a search template that stores indices options to be used as
part of a search during watch execution, but this was not updated to be
aware of hidden indices and the `hidden` expand_wildcards option. This
change makes use of the `IndicesOptions#toXContent` method in Watcher,
which already handles the new value. Additionally, the XContent parsing
is moved to the IndicesOptions class so that we will be less likely to
miss updating this in the future.

Closes #65148
Backport of #65332
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants