Skip to content

Commit

Permalink
fix: include Instances generated by Inbuilt Plugins in pluginInstance…
Browse files Browse the repository at this point in the history
…s Log
  • Loading branch information
rahulguptajss committed Nov 29, 2024
1 parent e4ea1e2 commit 177d6ab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
13 changes: 4 additions & 9 deletions cmd/poller/plugin/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *

// initialize cache
for i, rule := range a.rules {

matrices[i] = data.Clone(matrix.With{Data: false, Metrics: true, Instances: false, ExportInstances: true})
if rule.object != "" {
matrices[i].Object = rule.object
Expand All @@ -129,7 +128,6 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *
}

// create instances and summarize metric values

var (
objName, objKey string
objInstance *matrix.Instance
Expand All @@ -141,14 +139,14 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *
err error
)

for _, instance := range data.GetInstances() {
metadata := &util.Metadata{}

for _, instance := range data.GetInstances() {
if !instance.IsExportable() {
continue
}

for i, rule := range a.rules {

if objName = instance.GetLabel(rule.label); objName == "" {
a.SLogger.Warn("label missing, skipped", slog.String("label", rule.label))
continue
Expand Down Expand Up @@ -182,6 +180,7 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *
if objInstance, err = matrices[i].NewInstance(objKey); err != nil {
return nil, nil, err
}
metadata.PluginInstances++
switch {
case rule.allLabels:
objInstance.SetLabels(instance.GetLabels())
Expand All @@ -196,7 +195,6 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *
}

for key, metric := range data.GetMetrics() {

if value, ok = metric.GetValueFloat64(instance); !ok {
continue
}
Expand Down Expand Up @@ -249,10 +247,8 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *
}

// normalize values into averages if we are able to identify it as a percentage or average metric

for i, m := range matrices {
for mk, metric := range m.GetMetrics() {

var (
v float64
count float64
Expand All @@ -275,7 +271,6 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *
}

for key, instance := range m.GetInstances() {

if v, ok = metric.GetValueFloat64(instance); !ok {
continue
}
Expand All @@ -302,7 +297,7 @@ func (a *Aggregator) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *
}
}

return matrices, nil, nil
return matrices, metadata, nil
}

// NewLabels returns the new labels the receiver creates
Expand Down
5 changes: 4 additions & 1 deletion cmd/poller/plugin/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ func (c *ChangeLog) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *u
var matricesArray []*matrix.Matrix
matricesArray = append(matricesArray, changeMat)

metadata := &util.Metadata{}
metadata.PluginInstances = uint64(len(changeMat.GetInstances()))

c.copyPreviousData(data)
if len(changeMat.GetInstances()) > 0 {
// The `index` variable is used to differentiate between changes to the same label in a Grafana dashboard.
Expand All @@ -281,7 +284,7 @@ func (c *ChangeLog) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *u
)
}

return matricesArray, nil, nil
return matricesArray, metadata, nil
}

// CompareMetrics compares the metrics of the current and previous instances
Expand Down
2 changes: 2 additions & 0 deletions cmd/poller/plugin/max/max.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (m *Max) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me
err error
)

metadata := &util.Metadata{}
for _, instance := range data.GetInstances() {

if !instance.IsExportable() {
Expand Down Expand Up @@ -189,6 +190,7 @@ func (m *Max) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, *util.Me
if objInstance, err = matrices[matrixKey].NewInstance(objKey); err != nil {
return nil, nil, err
}
metadata.PluginInstances++
}

if value, ok = metric.GetValueFloat64(instance); !ok {
Expand Down

0 comments on commit 177d6ab

Please sign in to comment.