From 51813bad695e1920b164b85b2d7b8c8d658fd065 Mon Sep 17 00:00:00 2001 From: rahulguptajss Date: Fri, 2 Aug 2024 19:30:08 +0530 Subject: [PATCH] feat: change to use KeyPerf name --- .../keyperfmetrics.go => keyperf/keyperf.go} | 28 +++++++++---------- .../keyperf_test.go} | 16 +++++------ .../testdata/conf/keyperf}/9.15.0/volume.yaml | 0 .../testdata/config.yml | 2 +- .../testdata/missingStats/volume-poll-1.json | 0 .../testdata/missingStats/volume-poll-2.json | 0 .../partialAggregation/volume-poll-1.json | 0 .../partialAggregation/volume-poll-2.json | 0 .../partialAggregation/volume-poll-3.json | 0 .../volume-poll-partial-2.json | 0 .../volume-poll-partial.json | 0 .../testdata/volume-poll-1.json | 0 .../testdata/volume-poll-2.json | 0 cmd/collectors/rest/rest.go | 4 +-- cmd/poller/poller.go | 2 +- .../9.15.0/volume.yaml | 0 conf/{keyperfmetrics => keyperf}/default.yaml | 2 +- pkg/util/util.go | 18 ++++++------ 18 files changed, 36 insertions(+), 36 deletions(-) rename cmd/collectors/{keyperfmetrics/keyperfmetrics.go => keyperf/keyperf.go} (94%) rename cmd/collectors/{keyperfmetrics/keyperfmetrics_test.go => keyperf/keyperf_test.go} (91%) rename cmd/collectors/{keyperfmetrics/testdata/conf/keyperfmetrics => keyperf/testdata/conf/keyperf}/9.15.0/volume.yaml (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/config.yml (88%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/missingStats/volume-poll-1.json (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/missingStats/volume-poll-2.json (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/partialAggregation/volume-poll-1.json (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/partialAggregation/volume-poll-2.json (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/partialAggregation/volume-poll-3.json (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/partialAggregation/volume-poll-partial-2.json (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/partialAggregation/volume-poll-partial.json (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/volume-poll-1.json (100%) rename cmd/collectors/{keyperfmetrics => keyperf}/testdata/volume-poll-2.json (100%) rename conf/{keyperfmetrics => keyperf}/9.15.0/volume.yaml (100%) rename conf/{keyperfmetrics => keyperf}/default.yaml (75%) diff --git a/cmd/collectors/keyperfmetrics/keyperfmetrics.go b/cmd/collectors/keyperf/keyperf.go similarity index 94% rename from cmd/collectors/keyperfmetrics/keyperfmetrics.go rename to cmd/collectors/keyperf/keyperf.go index 56725a38b..f9a5d48d6 100644 --- a/cmd/collectors/keyperfmetrics/keyperfmetrics.go +++ b/cmd/collectors/keyperf/keyperf.go @@ -1,4 +1,4 @@ -package keyperfmetrics +package keyperf import ( "fmt" @@ -18,7 +18,7 @@ const ( timestampMetricName = "statistics.timestamp" ) -type KeyPerfMetrics struct { +type KeyPerf struct { *rest.Rest // provides: AbstractCollector, Client, Object, Query, TemplateFn, TemplateType perfProp *perfProp } @@ -37,17 +37,17 @@ type perfProp struct { } func init() { - plugin.RegisterModule(&KeyPerfMetrics{}) + plugin.RegisterModule(&KeyPerf{}) } -func (kp *KeyPerfMetrics) HarvestModule() plugin.ModuleInfo { +func (kp *KeyPerf) HarvestModule() plugin.ModuleInfo { return plugin.ModuleInfo{ - ID: "harvest.collector.keyperfmetrics", - New: func() plugin.Module { return new(KeyPerfMetrics) }, + ID: "harvest.collector.keyperf", + New: func() plugin.Module { return new(KeyPerf) }, } } -func (kp *KeyPerfMetrics) Init(a *collector.AbstractCollector) error { +func (kp *KeyPerf) Init(a *collector.AbstractCollector) error { var err error @@ -94,7 +94,7 @@ func (kp *KeyPerfMetrics) Init(a *collector.AbstractCollector) error { return nil } -func (kp *KeyPerfMetrics) InitMatrix() error { +func (kp *KeyPerf) InitMatrix() error { mat := kp.Matrix[kp.Object] // init perf properties kp.perfProp.latencyIoReqd = kp.loadParamInt("latency_io_reqd", latencyIoReqd) @@ -116,7 +116,7 @@ func (kp *KeyPerfMetrics) InitMatrix() error { } // load an int parameter or use defaultValue -func (kp *KeyPerfMetrics) loadParamInt(name string, defaultValue int) int { +func (kp *KeyPerf) loadParamInt(name string, defaultValue int) int { var ( x string @@ -136,7 +136,7 @@ func (kp *KeyPerfMetrics) loadParamInt(name string, defaultValue int) int { return defaultValue } -func (kp *KeyPerfMetrics) buildCounters() { +func (kp *KeyPerf) buildCounters() { for k := range kp.Prop.Metrics { if _, exists := kp.perfProp.counterInfo[k]; !exists { var ctr *counter @@ -176,7 +176,7 @@ func (kp *KeyPerfMetrics) buildCounters() { } } -func (kp *KeyPerfMetrics) PollData() (map[string]*matrix.Matrix, error) { +func (kp *KeyPerf) PollData() (map[string]*matrix.Matrix, error) { var ( err error perfRecords []gjson.Result @@ -208,7 +208,7 @@ func (kp *KeyPerfMetrics) PollData() (map[string]*matrix.Matrix, error) { // The function iterates over all the metrics in curMat and checks if each metric exists in prevMat. If a metric from curMat // does not exist in prevMat, it is created in prevMat as a new float64 metric. This prevents potential panics or errors // when attempting to perform calculations with metrics that are missing in prevMat. -func (kp *KeyPerfMetrics) validateMatrix(prevMat *matrix.Matrix, curMat *matrix.Matrix) error { +func (kp *KeyPerf) validateMatrix(prevMat *matrix.Matrix, curMat *matrix.Matrix) error { var err error for k := range curMat.GetMetrics() { if prevMat.GetMetric(k) == nil { @@ -221,7 +221,7 @@ func (kp *KeyPerfMetrics) validateMatrix(prevMat *matrix.Matrix, curMat *matrix. return nil } -func (kp *KeyPerfMetrics) pollData( +func (kp *KeyPerf) pollData( startTime time.Time, perfRecords []gjson.Result, endpointFunc func(e *rest.EndPoint) ([]gjson.Result, time.Duration, error), @@ -453,5 +453,5 @@ func (kp *KeyPerfMetrics) pollData( // Interface guards var ( - _ collector.Collector = (*KeyPerfMetrics)(nil) + _ collector.Collector = (*KeyPerf)(nil) ) diff --git a/cmd/collectors/keyperfmetrics/keyperfmetrics_test.go b/cmd/collectors/keyperf/keyperf_test.go similarity index 91% rename from cmd/collectors/keyperfmetrics/keyperfmetrics_test.go rename to cmd/collectors/keyperf/keyperf_test.go index 8877a0674..5cf51530d 100644 --- a/cmd/collectors/keyperfmetrics/keyperfmetrics_test.go +++ b/cmd/collectors/keyperf/keyperf_test.go @@ -1,4 +1,4 @@ -package keyperfmetrics +package keyperf import ( "fmt" @@ -20,7 +20,7 @@ const ( func TestPartialAggregationSequence(t *testing.T) { conf.TestLoadHarvestConfig("testdata/config.yml") - kp := newKeyPerfMetrics("Volume", "volume.yaml") + kp := newKeyPerf("Volume", "volume.yaml") // First Poll t.Log("Running First Poll") @@ -63,7 +63,7 @@ func TestPartialAggregationSequence(t *testing.T) { } } -func (kp *KeyPerfMetrics) testPollInstanceAndDataWithMetrics(t *testing.T, pollDataFile string, expectedExportedInst, expectedExportedMetrics int) *matrix.Matrix { +func (kp *KeyPerf) testPollInstanceAndDataWithMetrics(t *testing.T, pollDataFile string, expectedExportedInst, expectedExportedMetrics int) *matrix.Matrix { // Additional logic to count metrics pollData := collectors.JSONToGson(pollDataFile, true) now := time.Now().Truncate(time.Second) @@ -105,7 +105,7 @@ func (kp *KeyPerfMetrics) testPollInstanceAndDataWithMetrics(t *testing.T, pollD return mat } -func TestKeyPerfMetrics_pollData(t *testing.T) { +func TestKeyPerf_pollData(t *testing.T) { conf.TestLoadHarvestConfig("testdata/config.yml") tests := []struct { name string @@ -152,7 +152,7 @@ func TestKeyPerfMetrics_pollData(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - kp := newKeyPerfMetrics("Volume", "volume.yaml") + kp := newKeyPerf("Volume", "volume.yaml") // First poll data kp.testPollInstanceAndDataWithMetrics(t, tt.pollDataPath1, 0, 0) // Complete Poll @@ -180,15 +180,15 @@ func TestKeyPerfMetrics_pollData(t *testing.T) { } } -func newKeyPerfMetrics(object string, path string) *KeyPerfMetrics { +func newKeyPerf(object string, path string) *KeyPerf { var err error opts := options.New(options.WithConfPath("testdata/conf")) opts.Poller = pollerName opts.HomePath = "testdata" opts.IsTest = true - ac := collector.New("KeyPerfMetrics", object, opts, params(object, path), nil) - kp := KeyPerfMetrics{} + ac := collector.New("KeyPerf", object, opts, params(object, path), nil) + kp := KeyPerf{} err = kp.Init(ac) if err != nil { panic(err) diff --git a/cmd/collectors/keyperfmetrics/testdata/conf/keyperfmetrics/9.15.0/volume.yaml b/cmd/collectors/keyperf/testdata/conf/keyperf/9.15.0/volume.yaml similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/conf/keyperfmetrics/9.15.0/volume.yaml rename to cmd/collectors/keyperf/testdata/conf/keyperf/9.15.0/volume.yaml diff --git a/cmd/collectors/keyperfmetrics/testdata/config.yml b/cmd/collectors/keyperf/testdata/config.yml similarity index 88% rename from cmd/collectors/keyperfmetrics/testdata/config.yml rename to cmd/collectors/keyperf/testdata/config.yml index f5abb7285..28b2c7d77 100644 --- a/cmd/collectors/keyperfmetrics/testdata/config.yml +++ b/cmd/collectors/keyperf/testdata/config.yml @@ -5,7 +5,7 @@ Exporters: Defaults: collectors: - - KeyPerfMetrics + - KeyPerf exporters: - prometheus diff --git a/cmd/collectors/keyperfmetrics/testdata/missingStats/volume-poll-1.json b/cmd/collectors/keyperf/testdata/missingStats/volume-poll-1.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/missingStats/volume-poll-1.json rename to cmd/collectors/keyperf/testdata/missingStats/volume-poll-1.json diff --git a/cmd/collectors/keyperfmetrics/testdata/missingStats/volume-poll-2.json b/cmd/collectors/keyperf/testdata/missingStats/volume-poll-2.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/missingStats/volume-poll-2.json rename to cmd/collectors/keyperf/testdata/missingStats/volume-poll-2.json diff --git a/cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-1.json b/cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-1.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-1.json rename to cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-1.json diff --git a/cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-2.json b/cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-2.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-2.json rename to cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-2.json diff --git a/cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-3.json b/cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-3.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-3.json rename to cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-3.json diff --git a/cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-partial-2.json b/cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-partial-2.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-partial-2.json rename to cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-partial-2.json diff --git a/cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-partial.json b/cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-partial.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/partialAggregation/volume-poll-partial.json rename to cmd/collectors/keyperf/testdata/partialAggregation/volume-poll-partial.json diff --git a/cmd/collectors/keyperfmetrics/testdata/volume-poll-1.json b/cmd/collectors/keyperf/testdata/volume-poll-1.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/volume-poll-1.json rename to cmd/collectors/keyperf/testdata/volume-poll-1.json diff --git a/cmd/collectors/keyperfmetrics/testdata/volume-poll-2.json b/cmd/collectors/keyperf/testdata/volume-poll-2.json similarity index 100% rename from cmd/collectors/keyperfmetrics/testdata/volume-poll-2.json rename to cmd/collectors/keyperf/testdata/volume-poll-2.json diff --git a/cmd/collectors/rest/rest.go b/cmd/collectors/rest/rest.go index eba2dc9b7..2ff810d65 100644 --- a/cmd/collectors/rest/rest.go +++ b/cmd/collectors/rest/rest.go @@ -617,9 +617,9 @@ func (r *Rest) HandleResults(mat *matrix.Matrix, result []gjson.Result, prop *pr } } - // This is relevant for the KeyPerfMetrics collector. + // This is relevant for the KeyPerf collector. // If the `statistics.status` is not OK, then set `partial` to true. - if mat.UUID == "KeyPerfMetrics" { + if mat.UUID == "KeyPerf" { status := instanceData.Get("statistics.status") if status.Exists() && status.String() != "ok" { instance.SetPartial(true) diff --git a/cmd/poller/poller.go b/cmd/poller/poller.go index d55012d97..be0f8f81b 100644 --- a/cmd/poller/poller.go +++ b/cmd/poller/poller.go @@ -31,7 +31,7 @@ import ( "errors" "fmt" _ "github.com/netapp/harvest/v2/cmd/collectors/ems" - _ "github.com/netapp/harvest/v2/cmd/collectors/keyperfmetrics" + _ "github.com/netapp/harvest/v2/cmd/collectors/keyperf" _ "github.com/netapp/harvest/v2/cmd/collectors/restperf" _ "github.com/netapp/harvest/v2/cmd/collectors/simple" _ "github.com/netapp/harvest/v2/cmd/collectors/storagegrid" diff --git a/conf/keyperfmetrics/9.15.0/volume.yaml b/conf/keyperf/9.15.0/volume.yaml similarity index 100% rename from conf/keyperfmetrics/9.15.0/volume.yaml rename to conf/keyperf/9.15.0/volume.yaml diff --git a/conf/keyperfmetrics/default.yaml b/conf/keyperf/default.yaml similarity index 75% rename from conf/keyperfmetrics/default.yaml rename to conf/keyperf/default.yaml index 66af7c2b7..8138417ad 100644 --- a/conf/keyperfmetrics/default.yaml +++ b/conf/keyperf/default.yaml @@ -1,4 +1,4 @@ -collector: KeyPerfMetrics +collector: KeyPerf # Order here matters! schedule: diff --git a/pkg/util/util.go b/pkg/util/util.go index d13f211fa..fb4f8ad97 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -27,15 +27,15 @@ import ( var arrayRegex = regexp.MustCompile(`^([a-zA-Z][\w.]*)(\.[0-9#])`) var IsCollector = map[string]struct{}{ - "ZapiPerf": {}, - "Zapi": {}, - "Rest": {}, - "RestPerf": {}, - "KeyPerfMetrics": {}, - "Ems": {}, - "StorageGrid": {}, - "Unix": {}, - "Simple": {}, + "ZapiPerf": {}, + "Zapi": {}, + "Rest": {}, + "RestPerf": {}, + "KeyPerf": {}, + "Ems": {}, + "StorageGrid": {}, + "Unix": {}, + "Simple": {}, } func GetCollectorSlice() []string {