Skip to content

Commit

Permalink
fix lint warnings (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimanjain authored Aug 9, 2024
1 parent 26ba3c8 commit 5b8a79e
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 94 deletions.
5 changes: 1 addition & 4 deletions pkg/k8sclient/resources/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,7 @@ func (pod *Pod) Sync(ctx context.Context) *Pod {

// HasError checks whether pod has any error
func (pod *Pod) HasError() bool {
if pod.error != nil {
return true
}
return false
return pod.error != nil
}

// GetError returns pod error
Expand Down
5 changes: 1 addition & 4 deletions pkg/k8sclient/resources/pv/pv.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,7 @@ func (pv *PersistentVolume) Sync(ctx context.Context) *PersistentVolume {

// HasError checks if PV contains error
func (pv *PersistentVolume) HasError() bool {
if pv.error != nil {
return true
}
return false
return pv.error != nil
}

// GetError returns PV error
Expand Down
5 changes: 1 addition & 4 deletions pkg/k8sclient/resources/sc/sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ func (c *Client) DuplicateStorageClass(name string, sourceSc *v1.StorageClass) *

// HasError checks whether storage class has error
func (sc *StorageClass) HasError() bool {
if sc.error != nil {
return true
}
return false
return sc.error != nil
}

// GetError returns storage class error
Expand Down
5 changes: 1 addition & 4 deletions pkg/k8sclient/resources/statefulset/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,7 @@ func (sts *StatefulSet) Sync(ctx context.Context) *StatefulSet {

// HasError checks if statefulset contains error
func (sts *StatefulSet) HasError() bool {
if sts.error != nil {
return true
}
return false
return sts.error != nil
}

// GetError returns statefulset error
Expand Down
5 changes: 1 addition & 4 deletions pkg/k8sclient/resources/volumegroupsnapshot/vgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,7 @@ func (vgs *VGS) Name() string {

// HasError checks whether VGS has error
func (vgs *VGS) HasError() bool {
if vgs.error != nil {
return true
}
return false
return vgs.error != nil
}

// GetError returns VGS error
Expand Down
5 changes: 1 addition & 4 deletions pkg/k8sclient/resources/volumesnapshot/v1/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,7 @@ func (snap *Snapshot) WaitForRunning(ctx context.Context) error {

// HasError checks whether Snapshot has error
func (snap *Snapshot) HasError() bool {
if snap.error != nil {
return true
}
return false
return snap.error != nil
}

// GetError returns snapshot error
Expand Down
5 changes: 1 addition & 4 deletions pkg/k8sclient/resources/volumesnapshot/v1beta1/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ func (snap *Snapshot) WaitForRunning(ctx context.Context) error {

// HasError checks whether Snapshot has error
func (snap *Snapshot) HasError() bool {
if snap.error != nil {
return true
}
return false
return snap.error != nil
}

// GetError returns snapshot error
Expand Down
5 changes: 1 addition & 4 deletions pkg/k8sclient/resources/volumesnapshotcontent/v1/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ func (cont *SnapshotContent) WaitForRunning(ctx context.Context) error {

// HasError checks if snapshot content has error
func (cont *SnapshotContent) HasError() bool {
if cont.error != nil {
return true
}
return false
return cont.error != nil
}

// GetError returns snapshot content error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,7 @@ func (cont *SnapshotContent) WaitForRunning(ctx context.Context) error {

// HasError checks if snapshot content has error
func (cont *SnapshotContent) HasError() bool {
if cont.error != nil {
return true
}
return false
return cont.error != nil
}

// GetError returns snapshot content error
Expand Down
2 changes: 1 addition & 1 deletion pkg/observer/va.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (vao *VaObserver) StartWatching(_ context.Context, runner *Runner) {
select {
case <-vao.finished:
// We can't finish if we haven't received all deletion events
if len(attachedVAs) == len(deletedVAs) || runner.ShouldClean == false {
if len(attachedVAs) == len(deletedVAs) || !runner.ShouldClean {
err := runner.Database.SaveEvents(events)
if err != nil {
log.Errorf("Error saving events; error=%v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/observer/va_alt.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (vao *VaListObserver) StartWatching(ctx context.Context, runner *Runner) {
pollErr := wait.PollImmediate(500*time.Millisecond, time.Duration(timeout)*time.Second, func() (bool, error) {
select {
case <-vao.finished:
if len(attachedVAs) == len(deletedVAs) || runner.ShouldClean == false {
if len(attachedVAs) == len(deletedVAs) || !runner.ShouldClean {
log.Debugf("%s finished watching", vao.GetName())
saveErr := runner.Database.SaveEvents(events)
if saveErr != nil {
Expand Down
72 changes: 32 additions & 40 deletions pkg/plotter/plotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ func GetReportPathDir(reportName string) (string, error) {
// PlotStageMetricHistogram creates and saves a histogram of time distributions
// +returns absolute filepath to created plot
func PlotStageMetricHistogram(tc collector.TestCaseMetrics, stage interface{}, reportName string) (*plot.Plot, error) {
var metrics map[int]int
metrics = make(map[int]int)
metrics := make(map[int]int)

var min int
var max int
Expand All @@ -90,14 +89,12 @@ func PlotStageMetricHistogram(tc collector.TestCaseMetrics, stage interface{}, r

if isPvc {
for _, pvcMetric := range tc.PVCs {
var value int
value = int(math.Round(pvcMetric.Metrics[pvcStage].Seconds()))
value := int(math.Round(pvcMetric.Metrics[pvcStage].Seconds()))
metrics[value]++
}
} else if isPod {
for _, podMetric := range tc.Pods {
var value int
value = int(math.Round(podMetric.Metrics[podStage].Seconds()))
value := int(math.Round(podMetric.Metrics[podStage].Seconds()))
metrics[value]++
}
} else {
Expand All @@ -117,8 +114,8 @@ func PlotStageMetricHistogram(tc collector.TestCaseMetrics, stage interface{}, r
p := plot.New()

if p == nil {
log.Errorf("Can't create new plot")
return nil, errors.New("Can't create new plot")
log.Errorf("can't create new plot")
return nil, errors.New("can't create new plot")
}

p.Title.Text = fmt.Sprintf("Distribution of %s times. Pods=%d, PVCs=%d", stage, len(tc.Pods), len(tc.PVCs))
Expand All @@ -132,7 +129,7 @@ func PlotStageMetricHistogram(tc collector.TestCaseMetrics, stage interface{}, r

p.Add(barsBind)

filePath, err := GetReportPathDir(reportName)
filePath, _ := GetReportPathDir(reportName)
filePath = fmt.Sprintf("%s/%s", filePath, tc.TestCase.Name+strconv.Itoa(int(tc.TestCase.ID)))

_ = os.MkdirAll(filePath, 0o750)
Expand All @@ -155,15 +152,13 @@ func PlotStageBoxPlot(tc collector.TestCaseMetrics, stage interface{}, reportNam
if isPvc {
values = make(plotter.Values, len(tc.PVCs))
for i, pvcMetric := range tc.PVCs {
var value float64
value = pvcMetric.Metrics[pvcStage].Seconds()
value := pvcMetric.Metrics[pvcStage].Seconds()
values[i] = value
}
} else if isPod {
values = make(plotter.Values, len(tc.Pods))
for i, podMetric := range tc.Pods {
var value float64
value = podMetric.Metrics[podStage].Seconds()
value := podMetric.Metrics[podStage].Seconds()
values[i] = value
}
} else {
Expand All @@ -174,8 +169,8 @@ func PlotStageBoxPlot(tc collector.TestCaseMetrics, stage interface{}, reportNam
p := plot.New()

if p == nil {
log.Errorf("Can't create new plot")
return nil, errors.New("Can't create new plot")
log.Errorf("can't create new plot")
return nil, errors.New("can't create new plot")
}
p.Title.Text = fmt.Sprintf("Box plot of %s times. Pods=%d, PVCs=%d", stage, len(tc.Pods), len(tc.PVCs))
p.Y.Label.Text = "times"
Expand All @@ -188,7 +183,7 @@ func PlotStageBoxPlot(tc collector.TestCaseMetrics, stage interface{}, reportNam

p.Add(boxPlot)

filePath, err := GetReportPathDir(reportName)
filePath, _ := GetReportPathDir(reportName)
filePath = fmt.Sprintf("%s/%s", filePath, tc.TestCase.Name+strconv.Itoa(int(tc.TestCase.ID)))

_ = os.MkdirAll(filePath, 0o750)
Expand Down Expand Up @@ -256,10 +251,10 @@ func PlotEntityOverTime(tc collector.TestCaseMetrics, reportName string) (*plot.
p := plot.New()

if p == nil {
log.Errorf("Can't create new plot")
return nil, errors.New("Can't create new plot")
log.Errorf("can't create new plot")
return nil, errors.New("can't create new plot")
}
p.Title.Text = fmt.Sprintf("EntityNumber over time")
p.Title.Text = "EntityNumber over time"
p.Y.Label.Text = "number"
p.X.Label.Text = "time"
// Draw a grid behind the data
Expand Down Expand Up @@ -411,13 +406,12 @@ func PlotEntityOverTime(tc collector.TestCaseMetrics, reportName string) (*plot.
dc = draw.Crop(dc, 0, -legendWidth-vg.Millimeter, 0, 0) // Make space for the legend.
p.Draw(dc)

filePath, err := GetReportPathDir(reportName)
filePath, _ := GetReportPathDir(reportName)
filePath = fmt.Sprintf("%s/%s", filePath, tc.TestCase.Name+strconv.Itoa(int(tc.TestCase.ID)))

_ = os.MkdirAll(filePath, 0o750)
var fileName string

fileName = fmt.Sprintf("%s.png", "EntityNumberOverTime")
fileName := fmt.Sprintf("%s.png", "EntityNumberOverTime")
filePath = filepath.Join(filePath, fileName)

w, err := os.Create(filepath.Clean(filePath))
Expand Down Expand Up @@ -585,8 +579,8 @@ func PlotIterationTimes(tcMetrics []collector.TestCaseMetrics, reportName string
}
p := plot.New()
if p == nil {
log.Error("Can't create a new plot")
return nil, errors.New("Can't create new plot")
log.Error("can't create a new plot")
return nil, errors.New("can't create new plot")
}

p.Title.Text = "IterationTimes"
Expand All @@ -599,11 +593,11 @@ func PlotIterationTimes(tcMetrics []collector.TestCaseMetrics, reportName string
return nil, err
}

filePath, err := GetReportPathDir(reportName)
filePath, _ := GetReportPathDir(reportName)

_ = os.MkdirAll(filePath, 0o750)

filePath = filepath.Join(filePath, fmt.Sprintf("IterationTimes.png"))
filePath = filepath.Join(filePath, "IterationTimes.png")

// Save the plot to a PNG file.
if err := p.Save(6*vg.Inch, 4*vg.Inch, filePath); err != nil {
Expand Down Expand Up @@ -651,8 +645,8 @@ func PlotAvgStageTimeOverIterations(tcMetrics []collector.TestCaseMetrics, repor

p := plot.New()
if p == nil {
log.Error("Can't create a new plot")
return errors.New("Can't create new plot")
log.Error("can't create a new plot")
return errors.New("can't create new plot")
}
p.Title.Text = fmt.Sprintf("Avg time of %s", name)
p.Y.Label.Text = "time, s"
Expand All @@ -668,10 +662,9 @@ func PlotAvgStageTimeOverIterations(tcMetrics []collector.TestCaseMetrics, repor

p.Add(line)

filePath, err := GetReportPathDir(reportName)
filePath, _ := GetReportPathDir(reportName)
_ = os.MkdirAll(filePath, 0o750)
var fileName string
fileName = fmt.Sprintf("%sOverIterations.png", name)
fileName := fmt.Sprintf("%sOverIterations.png", name)
filePath = filepath.Join(filePath, fileName)

if err := p.Save(8*vg.Inch, 4*vg.Inch, filePath); err != nil {
Expand All @@ -685,10 +678,10 @@ func PlotAvgStageTimeOverIterations(tcMetrics []collector.TestCaseMetrics, repor
func plotMemoryOrCPU(metrics map[string]plotter.XYs, reportName string, name string) error {
p := plot.New()
if p == nil {
log.Errorf("Can't create new plot")
return errors.New("Can't create new plot")
log.Errorf("can't create new plot")
return errors.New("can't create new plot")
}
p.Title.Text = fmt.Sprintf(name)
p.Title.Text = name
p.Y.Label.Text = "value"
p.X.Label.Text = "time"
// Draw a grid behind the data
Expand Down Expand Up @@ -731,10 +724,9 @@ func plotMemoryOrCPU(metrics map[string]plotter.XYs, reportName string, name str
// Make space for the legend.
p.Draw(dc)

filePath, err := GetReportPathDir(reportName)
filePath, _ := GetReportPathDir(reportName)
_ = os.MkdirAll(filePath, 0o750)
var fileName string
fileName = fmt.Sprintf("%s.png", name)
fileName := fmt.Sprintf("%s.png", name)
filePath = filepath.Join(filePath, fileName)
w, err := os.Create(filepath.Clean(filePath))
if err != nil {
Expand All @@ -752,8 +744,8 @@ func plotMemoryOrCPU(metrics map[string]plotter.XYs, reportName string, name str
func plotMinMax(minMetrics plotter.XYs, maxMetrics plotter.XYs, reportName string, name string) error {
p := plot.New()
if p == nil {
log.Errorf("Can't create new plot")
return errors.New("Can't create new plot")
log.Errorf("can't create new plot")
return errors.New("can't create new plot")
}
p.Title.Text = fmt.Sprintf("%s over time", name)
p.Y.Label.Text = "number"
Expand Down Expand Up @@ -815,7 +807,7 @@ func plotMinMax(minMetrics plotter.XYs, maxMetrics plotter.XYs, reportName strin
// Make space for the legend.
p.Draw(dc)

filePath, err := GetReportPathDir(reportName)
filePath, _ := GetReportPathDir(reportName)

_ = os.MkdirAll(filePath, 0o750)

Expand Down
2 changes: 1 addition & 1 deletion pkg/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (suite *StoreTestSuite) TestAllStores() {
suite.Equal(len(entities), 1, fmt.Sprintf("able to get entity relations using %s store", key))
suite.Equal(entities[0].Name, "pvc1", fmt.Sprintf("able to get entity name from relation using %s store", key))

entities, err = store.GetEntities(Conditions{"type": Pvc}, "", 0)
entities, _ = store.GetEntities(Conditions{"type": Pvc}, "", 0)
suite.Equal(len(entities), 1)

nEntities := []*NumberEntities{
Expand Down
Loading

0 comments on commit 5b8a79e

Please sign in to comment.