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

Dynamic metadata filter not working as described #16758

Closed
valodzka opened this issue Apr 2, 2023 · 6 comments · Fixed by #16991
Closed

Dynamic metadata filter not working as described #16758

valodzka opened this issue Apr 2, 2023 · 6 comments · Fixed by #16991
Assignees
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/api HTTP API and SDK issues type/bug

Comments

@valodzka
Copy link
Contributor

valodzka commented Apr 2, 2023

Nomad version

1.5.2 / linux

Issue

I've tried example described here https://developer.hashicorp.com/nomad/api-docs/task-api and found that filter not working with dynamic metadata.

Reproduction steps

nomad node meta apply example=a
nomad node status -filter 'Meta.example == "a"'
Error querying node status: Unexpected response code: 400 (failed to read result page: error finding value in datum: /Meta/example at part 1: couldn't find key "example")
@schmichael
Copy link
Member

The error is poor here, but I suspect what you're running into is that there's a delay between setting node metadata and when it is available via nomad node status.

The API docs mentions this, but I forgot to add CLI docs! Fixing that in #16828

@schmichael schmichael added this to Needs Triage in Nomad - Community Issues Triage via automation Apr 8, 2023
@schmichael schmichael moved this from Needs Triage to In Progress in Nomad - Community Issues Triage Apr 8, 2023
@valodzka
Copy link
Contributor Author

valodzka commented Apr 8, 2023

Hi @schmichael

I don't think update delay is the reason. 5 days ago after meta update:

nomad node status -filter 'Meta.example == "a"'
Error querying node status: Unexpected response code: 400 (failed to read result page: error finding value in datum: /Meta/example at part 1: couldn't find key "example")

For context: i'm running this in simple cluster with 3 nodes (all nodes working as server and as client). It works as expected with nomad agent -dev, but not in cluster.

@schmichael
Copy link
Member

You're right @valodzka! I was able to reproduce the error with these agent configs and running your commands.

I can see the example = a metadata when using nomad node status -verbose on the node in question, so it is getting set properly... something seems to be going wrong with the filter processing. Hitting the HTTP API directly produces the same results:

> GET http://127.0.0.1:4646/v1/nodes?filter=Meta.example+%3D%3D+%22a%22
* Sending request and receiving response...
< HTTP/1.1 400 Bad Request
< Vary: Accept-Encoding
< Date: Tue, 11 Apr 2023 00:01:07 GMT
failed to read result page: error finding value in datum: /Meta/example at part 1: couldn't find key "example"```

@schmichael schmichael self-assigned this Apr 11, 2023
@schmichael schmichael added theme/api HTTP API and SDK issues stage/accepted Confirmed, and intend to work on. No timeline committment though. labels Apr 11, 2023
Nomad - Community Issues Triage automation moved this from In Progress to Done Apr 12, 2023
@schmichael schmichael reopened this Apr 12, 2023
Nomad - Community Issues Triage automation moved this from Done to Needs Triage Apr 12, 2023
@schmichael
Copy link
Member

This is a limitation of the underlying github.com/hashicorp/go-bexpr library we (and Consul) use for filters. While we try to find a fix that doesn't involve backwards incompatibilities there is a workaround:

"example" in Meta and Meta["example"] == "foo"

Performing an in test first will cause Nodes without the Meta["example"] key to be skipped instead of trying to perform the equality and failing to find the field.

@schmichael
Copy link
Member

Fixed and will be going out in our next releases! Thanks for the report @valodzka !

@lattwood
Copy link
Contributor

Looks like this was only fixed for the case of top level entries in Meta.

Example:

Meta
connect.log_level         = info
connect.proxy_concurrency = 1
> nomad node status -json -filter 'Meta.connect.proxy_concurrency == 1'
Error querying node status: Unexpected response code: 400 (failed to read result page: error finding value in datum: /Meta/connect/proxy_concurrency at part 1: couldn't find key "connect")
> nomad node status -json -filter '"connect.proxy_concurrency" in Meta and Meta["connect"]["proxy_concurrency"] == 1'
Error querying node status: Unexpected response code: 400 (failed to read result page: error finding value in datum: /Meta/connect/proxy_concurrency at part 1: couldn't find key "connect")

As you can see, the workaround didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/api HTTP API and SDK issues type/bug
Projects
Development

Successfully merging a pull request may close this issue.

3 participants