mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2026-02-13 06:31:46 +01:00
Golangci lint fixes (#195)
* Add golangci-lin as make target * Fix: could omit type ... from declaration; it will be inferred from the right-hand side (staticcheck) * Fix func intArrayContains is unused (unused) * Fix: could use strings.ReplaceAll instead (staticcheck) * Fix: could expand call to math.Pow (staticcheck) * Fix: could use tagged switch on `...` (staticcheck) * Fix: Error return value of `...` is not checked (errcheck) * Fix: ineffectual assignment to err (ineffassign) * Fix: There is no need to wait for command completion * Add cpustat, diskstat and schedstat config * Use slices to exclude metrics * Replaced stringArrayContains by slices.Contains * Replace m[k]=v loop with maps.Copy * Use module slices from the standard library. Remove use of golang.org/x/exp/slices * Use SplitSeq and max to modernize code
This commit is contained in:
@@ -107,10 +107,8 @@ func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, rout
|
||||
cclog.ComponentError("MetricRouter", err.Error())
|
||||
return err
|
||||
}
|
||||
r.maxForward = 1
|
||||
if r.config.MaxForward > r.maxForward {
|
||||
r.maxForward = r.config.MaxForward
|
||||
}
|
||||
r.maxForward = max(1, r.config.MaxForward)
|
||||
|
||||
if r.config.NumCacheIntervals > 0 {
|
||||
r.cache, err = NewCache(r.cache_input, r.ticker, &r.cachewg, r.config.NumCacheIntervals)
|
||||
if err != nil {
|
||||
@@ -118,50 +116,74 @@ func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, rout
|
||||
return err
|
||||
}
|
||||
for _, agg := range r.config.IntervalAgg {
|
||||
r.cache.AddAggregation(agg.Name, agg.Function, agg.Condition, agg.Tags, agg.Meta)
|
||||
err = r.cache.AddAggregation(agg.Name, agg.Function, agg.Condition, agg.Tags, agg.Meta)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MetricCache AddAggregation() failed: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
p, err := mp.NewMessageProcessor()
|
||||
if err != nil {
|
||||
return fmt.Errorf("initialization of message processor failed: %v", err.Error())
|
||||
return fmt.Errorf("MessageProcessor NewMessageProcessor() failed: %w", err)
|
||||
}
|
||||
r.mp = p
|
||||
|
||||
if len(r.config.MessageProcessor) > 0 {
|
||||
err = r.mp.FromConfigJSON(r.config.MessageProcessor)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed parsing JSON for message processor: %v", err.Error())
|
||||
return fmt.Errorf("MessageProcessor FromConfigJSON() failed: %w", err)
|
||||
}
|
||||
}
|
||||
for _, mname := range r.config.DropMetrics {
|
||||
r.mp.AddDropMessagesByName(mname)
|
||||
err = r.mp.AddDropMessagesByName(mname)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MessageProcessor AddDropMessagesByName() failed: %w", err)
|
||||
}
|
||||
}
|
||||
for _, cond := range r.config.DropMetricsIf {
|
||||
r.mp.AddDropMessagesByCondition(cond)
|
||||
err = r.mp.AddDropMessagesByCondition(cond)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MessageProcessor AddDropMessagesByCondition() failed: %w", err)
|
||||
}
|
||||
}
|
||||
for _, data := range r.config.AddTags {
|
||||
cond := data.Condition
|
||||
if cond == "*" {
|
||||
cond = "true"
|
||||
}
|
||||
r.mp.AddAddTagsByCondition(cond, data.Key, data.Value)
|
||||
err = r.mp.AddAddTagsByCondition(cond, data.Key, data.Value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MessageProcessor AddAddTagsByCondition() failed: %w", err)
|
||||
}
|
||||
}
|
||||
for _, data := range r.config.DelTags {
|
||||
cond := data.Condition
|
||||
if cond == "*" {
|
||||
cond = "true"
|
||||
}
|
||||
r.mp.AddDeleteTagsByCondition(cond, data.Key, data.Value)
|
||||
err = r.mp.AddDeleteTagsByCondition(cond, data.Key, data.Value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MessageProcessor AddDeleteTagsByCondition() failed: %w", err)
|
||||
}
|
||||
}
|
||||
for oldname, newname := range r.config.RenameMetrics {
|
||||
r.mp.AddRenameMetricByName(oldname, newname)
|
||||
err = r.mp.AddRenameMetricByName(oldname, newname)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MessageProcessor AddRenameMetricByName() failed: %w", err)
|
||||
}
|
||||
}
|
||||
for metricName, prefix := range r.config.ChangeUnitPrefix {
|
||||
r.mp.AddChangeUnitPrefix(fmt.Sprintf("name == '%s'", metricName), prefix)
|
||||
err = r.mp.AddChangeUnitPrefix(fmt.Sprintf("name == '%s'", metricName), prefix)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MessageProcessor AddChangeUnitPrefix() failed: %w", err)
|
||||
}
|
||||
}
|
||||
r.mp.SetNormalizeUnits(r.config.NormalizeUnits)
|
||||
|
||||
r.mp.AddAddTagsByCondition("true", r.config.HostnameTagName, r.hostname)
|
||||
err = r.mp.AddAddTagsByCondition("true", r.config.HostnameTagName, r.hostname)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MessageProcessor AddAddTagsByCondition() failed: %w", err)
|
||||
}
|
||||
|
||||
// r.config.dropMetrics = make(map[string]bool)
|
||||
// for _, mname := range r.config.DropMetrics {
|
||||
|
||||
Reference in New Issue
Block a user