in internal/workloadmanager/workloadcollector.go [181:224]
func (e *metricEmitter) getMetric(ctx context.Context) (WorkloadType, map[string]string, bool) {
if e.metrics == nil {
e.metrics = make(map[string]string) // Initialize the metrics map if it's nil
}
for e.scanner.Scan() {
line := e.scanner.Text()
if line == "" || strings.HasPrefix(line, "#") {
continue // Skip empty lines and comments directly
}
key, value, found := strings.Cut(line, ":")
if !found {
log.CtxLogger(ctx).Warn("Invalid format: " + line)
continue
}
key = strings.TrimSpace(key)
value = strings.TrimSpace(value)
if key == "workload_type" {
// Found the first workload type, continue scanning for its metrics.
if e.workloadType == "" {
e.workloadType = WorkloadType(value)
continue
}
// Found a new workload type, return the current one with its metrics
workloadType := e.workloadType
metrics := e.metrics
e.workloadType = WorkloadType(value) // Update the workload type for the next record
e.metrics = make(map[string]string) // Reset the metrics map for the new workload
return workloadType, metrics, false
}
e.metrics[key] = value
}
if err := e.scanner.Err(); err != nil {
log.CtxLogger(ctx).Warnw("Could not read from the override metrics file", "error", err)
}
// Reached end of file, return the last workload type and its metrics
workloadType := e.workloadType
metrics := e.metrics
return workloadType, metrics, true
}