Skip to content

Commit

Permalink
feat: keyperfmetrics collector infrastructure (#3079)
Browse files Browse the repository at this point in the history
* feat: keyperfmetrics collector infrastructure

* feat: keyperfmetrics collector infrastructure
  • Loading branch information
cgrinds authored Aug 1, 2024
1 parent f9f82fe commit 0780744
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions cmd/collectors/keyperfmetrics/keyperfmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ func (kp *KeyPerfMetrics) loadParamInt(name string, defaultValue int) int {

if x = kp.Params.GetChildContentS(name); x != "" {
if n, e = strconv.Atoi(x); e == nil {
kp.Logger.Debug().Msgf("using %s = [%d]", name, n)
kp.Logger.Debug().Str("name", name).Int("n", n).Send()
return n
}
kp.Logger.Warn().Msgf("invalid parameter %s = [%s] (expected integer)", name, x)
kp.Logger.Warn().Str("parameter", name).Str("x", x).Msg("invalid parameter")
}

kp.Logger.Debug().Str("name", name).Str("defaultValue", strconv.Itoa(defaultValue)).Msg("using values")
Expand Down Expand Up @@ -286,8 +286,10 @@ func (kp *KeyPerfMetrics) pollData(
orderedDenominatorMetrics := make([]*matrix.Metric, 0, len(curMat.GetMetrics()))
orderedDenominatorKeys := make([]string, 0, len(orderedDenominatorMetrics))

counterMap := kp.perfProp.counterInfo

for key, metric := range curMat.GetMetrics() {
counter := kp.counterLookup(key)
counter := counterMap[key]
if counter != nil {
if counter.denominator == "" {
// does not require base counter
Expand Down Expand Up @@ -323,7 +325,7 @@ func (kp *KeyPerfMetrics) pollData(

for i, metric := range orderedMetrics {
key := orderedKeys[i]
counter := kp.counterLookup(key)
counter := counterMap[key]
if counter == nil {
kp.Logger.Error().Err(err).Str("counter", metric.GetName()).Msg("Missing counter:")
continue
Expand Down Expand Up @@ -416,25 +418,24 @@ func (kp *KeyPerfMetrics) pollData(
// calculate rates (which we deferred to calculate averages/percents first)
for i, metric := range orderedMetrics {
key := orderedKeys[i]
counter := kp.counterLookup(key)
if counter != nil {
property := counter.counterType
if property == "rate" {
if skips, err = curMat.Divide(orderedKeys[i], timestampMetricName); err != nil {
kp.Logger.Error().Err(err).
Int("i", i).
Str("metric", metric.GetName()).
Str("key", orderedKeys[i]).
Int("instIndex", instIndex).
Msg("Calculate rate")
continue
}
totalSkips += skips
}
} else {
counter := counterMap[key]
if counter == nil {
kp.Logger.Warn().Str("counter", metric.GetName()).Msg("Counter is missing or unable to parse ")
continue
}
property := counter.counterType
if property == "rate" {
if skips, err = curMat.Divide(orderedKeys[i], timestampMetricName); err != nil {
kp.Logger.Error().Err(err).
Int("i", i).
Str("metric", metric.GetName()).
Str("key", orderedKeys[i]).
Int("instIndex", instIndex).
Msg("Calculate rate")
continue
}
totalSkips += skips
}
}

calcD := time.Since(calcStart)
Expand All @@ -450,11 +451,6 @@ func (kp *KeyPerfMetrics) pollData(
return newDataMap, nil
}

func (kp *KeyPerfMetrics) counterLookup(metricKey string) *counter {
c := kp.perfProp.counterInfo[metricKey]
return c
}

// Interface guards
var (
_ collector.Collector = (*KeyPerfMetrics)(nil)
Expand Down

0 comments on commit 0780744

Please sign in to comment.