in internal/sqlservermetrics/guestoscollector/linuxcollector.go [436:527]
func (c *LinuxCollector) CollectGuestRules(ctx context.Context, timeout time.Duration) sqlserverutils.MetricDetails {
details := sqlserverutils.MetricDetails{
Name: "OS",
}
fields := map[string]string{}
if !c.remote {
ctxWithTimeout, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
ch := make(chan bool, 1)
go func() {
DiskToDiskType(fields, c.disks)
ch <- true
}()
select {
case <-ctxWithTimeout.Done():
log.Logger.Errorf("DiskToDiskType() for local linux disktype timeout")
case <-ch:
}
} else {
if c.remoteRunner == nil {
fields[UseLocalSSD] = "unknown"
details.Fields = append(details.Fields, fields)
log.Logger.Debugw("Remoterunner is nil. Remote collection attempted when ssh keys aren't set up correctly. Check customer support documentation.")
return details
}
defer func() {
log.Logger.Debug("Closing the remote runner client")
if err := c.remoteRunner.Close(); err != nil {
log.Logger.Errorw("Failed to close the client in remote runner", "error", err)
}
}()
}
for _, rule := range CollectionOSFields() {
exe := c.guestRuleCommandMap[rule]
func() {
ctxWithTimeout, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
ch := make(chan bool, 1)
go func() {
if c.remote {
res, err := exe.runRemoteCommand(ctx, exe.command, c.remoteRunner)
if err != nil {
if strings.Contains(err.Error(), "Check help docs") {
log.Logger.Warnw("Failed to run remote command. Install command on linux vm to collect more data", "command", exe.command, "error", err)
} else {
log.Logger.Errorw("Failed to run remote command", "command", exe.command, "error", err)
}
fields[rule] = "unknown"
ch <- false
return
} else if res == "null" {
fields[rule] = "unknown"
ch <- false
return
}
fields[rule] = res
} else if exe.isRule { // local calls are only made if isrule is true
res, err := exe.runCommand(ctx, exe.command)
if err != nil {
if strings.Contains(err.Error(), "Check help docs") {
log.Logger.Warnw("Failed to run remote command. Install command on linux vm to collect more data", "command", exe.command, "error", err)
} else {
log.Logger.Errorw("Failed to run command", "command", exe.command, "error", err)
}
fields[rule] = "unknown"
ch <- false
return
} else if res == "null" {
fields[rule] = "unknown"
ch <- false
return
}
fields[rule] = res
}
ch <- true
}()
select {
case <-ctxWithTimeout.Done():
log.Logger.Errorf("Running linux guest rule %s timeout", rule)
case <-ch:
}
}()
}
details.Fields = append(details.Fields, fields)
return details
}