in internal/sqlcollector/sqlcollector_v1.go [47:80]
func (c *V1) CollectMasterRules(ctx context.Context, timeout time.Duration) []internal.Details {
var details []internal.Details
for _, rule := range internal.MasterRules {
func() {
ctxWithTimeout, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
queryResult, err := c.executeSQL(ctxWithTimeout, rule.Query)
if err != nil {
log.Logger.Errorw("Failed to run sql query", "query", rule.Query, "error", err)
c.usageMetricsLogger.Error(agentstatus.SQLQueryExecutionError)
return
}
// queryResult is a 2d array and for most rules there is only one row in the query result.
// For InstanceMetrics, the query result is in one row and we need to append the os type to the row in queryResult.
if rule.Name == "INSTANCE_METRICS" {
if queryResult == nil || len(queryResult) == 0 {
log.Logger.Errorw("Empty query result", "query", rule.Query)
c.usageMetricsLogger.Error(agentstatus.SQLQueryExecutionError)
return
}
os := "windows"
if !c.windows {
os = "linux"
}
queryResult[0] = append(queryResult[0], os)
}
details = append(details, internal.Details{
Name: rule.Name,
Fields: rule.Fields(queryResult),
})
}()
}
return details
}