<@U02KY9FDA59> Thanks. In the `LabelQueriesForHost...
# fleet
s
@Kathy Satterlee Thanks. In the
LabelQueriesForHost
method in
server/datastore/mysql/labels.go
, there is a SQL query to get label queries for given host :
Copy code
query := `SELECT id, query FROM labels WHERE platform = ? OR platform = '' AND label_membership_type = ?`
	rows, err = ds.reader.QueryContext(ctx, query, platform, fleet.LabelMembershipTypeDynamic)
Considering that MySQL
AND
operator takes precedence over the
OR
operator, the query is the same as:
Copy code
SELECT id, query FROM labels WHERE platform = ? OR (platform = '' AND label_membership_type = ?);
With this statement, a label query will be returned if the host's platform matches label's platform, even if the label's label_membership_type is
"manual"
instead of
"dynamic"
. However, a "manual" label is populated manually without the execution of a label query, so it is meaningless to return label queries for a manual label. Then I would suppose the query should look like:
Copy code
`SELECT id, query FROM labels WHERE (platform = ? OR platform = '') AND label_membership_type = ?`
Which instead means that it only gets
dynamic
label queries if the label's platform matches the host's or the label's platform is "all platforms" I really appreciate it if someone could correct my misunderstandings, or confirm that there are some problems here.🤝
k
Since manual labels don’t have a platform field, the query works as structured. It will grab queries for labels that are either for the correct platform, or that don’t have a platform specified and are dynamic labels
s
I see,thank you very much 👍