Skip to content

Commit

Permalink
feat: change to use KeyPerf name
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Aug 2, 2024
1 parent 0780744 commit 676eaa5
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keyperfmetrics
package keyperf

import (
"fmt"
Expand All @@ -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
}
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -453,5 +453,5 @@ func (kp *KeyPerfMetrics) pollData(

// Interface guards
var (
_ collector.Collector = (*KeyPerfMetrics)(nil)
_ collector.Collector = (*KeyPerf)(nil)
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keyperfmetrics
package keyperf

import (
"fmt"
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Exporters:

Defaults:
collectors:
- KeyPerfMetrics
- KeyPerf
exporters:
- prometheus

Expand Down
4 changes: 2 additions & 2 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
collector: KeyPerfMetrics
collector: KeyPerf

# Order here matters!
schedule:
Expand Down
18 changes: 9 additions & 9 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 676eaa5

Please sign in to comment.