Shiji Zhou
04/15/2023, 2:29 AMLabelQueriesForHost
method in server/datastore/mysql/labels.go
, there is a SQL query to get label queries for given host :
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:
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:
`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.🤝Kathy Satterlee
04/15/2023, 7:25 PMShiji Zhou
04/16/2023, 6:26 PM