-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Describe the bug
Searching by a node attribute set at different precedence levels gives unexpected results. For example, if attribute "x" is false at the default level but true at the normal level, a search for x:true returns no results.
The Node data is saved correctly (at different levels) in the node table, and a knife node show my.host shows prometheus.enabled as true in Attributes, but false in default attributes. However, after indexing, only a single entry in the search_items table for "x" is stored as false:
goiardi=> select * from search_items where path ~ 'prometheus.enabled' and item_name = 'my.host';
id | item_name | value | path
----------+-----------------+-------+-------------------------
25599967 | my.host | false | prometheus.enabled
I think this is because walking/merging down through the Field()s returned from reflection of the Node object is performed in the order they are defined in the Node struct - "Automatic", "Normal", "Default", "Override".
I think the order should probably be "Default", "Normal", "Override", "Automatic"? Reordering the Node struct fields then gives me the expected results for searches (after reindexing). It's a small fix, but i wanted to check the existing ordering wasn't intentional?
(the stability/predictability of the struct field ordering was confirmed by Ian Lance-Taylor here: https://groups.google.com/g/golang-nuts/c/_he7g1TL0K8/m/8BBCFB0tCgAJ)
To Reproduce
Converge a node with attributes set differently at the different precedence levels, search.
Expected behavior
Searching for attribute values set differently at the "automatic" or "normal" level should take precedence over those set at the "default" level.