From 177d6ab5814a0f66f63cd576a88fe82df3a855fa Mon Sep 17 00:00:00 2001 From: rahulguptajss Date: Fri, 29 Nov 2024 13:01:00 +0530 Subject: [PATCH] fix: include Instances generated by Inbuilt Plugins in pluginInstances Log --- cmd/poller/plugin/aggregator/aggregator.go | 13 ++++--------- cmd/poller/plugin/changelog/changelog.go | 5 ++++- cmd/poller/plugin/max/max.go | 2 ++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/poller/plugin/aggregator/aggregator.go b/cmd/poller/plugin/aggregator/aggregator.go index 784fad294..fa5b15c3d 100644 --- a/cmd/poller/plugin/aggregator/aggregator.go +++ b/cmd/poller/plugin/aggregator/aggregator.go @@ -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 @@ -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 @@ -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 @@ -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()) @@ -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 } @@ -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 @@ -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 } @@ -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 diff --git a/cmd/poller/plugin/changelog/changelog.go b/cmd/poller/plugin/changelog/changelog.go index b59744a60..c56922186 100644 --- a/cmd/poller/plugin/changelog/changelog.go +++ b/cmd/poller/plugin/changelog/changelog.go @@ -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. @@ -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 diff --git a/cmd/poller/plugin/max/max.go b/cmd/poller/plugin/max/max.go index 62ac94ec2..7609a9198 100644 --- a/cmd/poller/plugin/max/max.go +++ b/cmd/poller/plugin/max/max.go @@ -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() { @@ -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 {