From 5f7e583731a07b61f6814aeefd2eed4213518304 Mon Sep 17 00:00:00 2001 From: Soumya Ghosh Dastidar Date: Sat, 9 Nov 2024 11:46:42 +0530 Subject: [PATCH] fix: pass by reference Signed-off-by: Soumya Ghosh Dastidar --- .github/workflows/build.yml | 4 ++-- .github/workflows/push.yml | 2 +- .github/workflows/release.yml | 2 +- controller/controller.go | 2 +- controller/mocks/mock_collect-data.go | 24 +++++++++--------------- controller/scrap_test.go | 4 ++-- controller/scrape.go | 6 +++--- go.mod | 4 ++-- go.sum | 5 +---- 9 files changed, 22 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ad35fc..3463d07 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: # Install golang - uses: actions/setup-go@v2 with: - go-version: 1.22.0 + go-version: 1.20.0 # Checkout to the latest commit # On specific directory/path @@ -98,7 +98,7 @@ jobs: # Install golang - uses: actions/setup-go@v2 with: - go-version: 1.22.0 + go-version: 1.20.0 # Checkout to the latest commit # On specific directory/path diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 546af17..38499b9 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -13,7 +13,7 @@ jobs: # Install golang - uses: actions/setup-go@v2 with: - go-version: 1.22.0 + go-version: 1.20.0 # Checkout to the latest commit # On specific directory/path diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d047fa9..5cdb406 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ jobs: # Install golang - uses: actions/setup-go@v2 with: - go-version: 1.22.0 + go-version: 1.20.0 # Checkout to the latest commit # On specific directory/path diff --git a/controller/controller.go b/controller/controller.go index 1194884..1bf610d 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -47,7 +47,7 @@ func Exporter(clientSet clients.ClientSets, wq workqueue.RateLimitingInterface) // refresh metrics whenever there's a change in chaosengine or chaosresult // or every informer resync duration, whichever is earlier for _, done := wq.Get(); !done; _, done = wq.Get() { - needRequeue, err := r.GetLitmusChaosMetrics(clientSet, overallChaosResults, &monitoringEnabled) + needRequeue, err := r.GetLitmusChaosMetrics(clientSet, &overallChaosResults, &monitoringEnabled) if err != nil { log.Errorf("err: %v", err) } diff --git a/controller/mocks/mock_collect-data.go b/controller/mocks/mock_collect-data.go index cdb1802..d7c2bf5 100644 --- a/controller/mocks/mock_collect-data.go +++ b/controller/mocks/mock_collect-data.go @@ -1,10 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/litmuschaos/chaos-exporter/controller (interfaces: ResultCollector) -// -// Generated by this command: -// -// mockgen -destination=mocks/mock_collect-data.go -package=mocks github.com/litmuschaos/chaos-exporter/controller ResultCollector -// // Package mocks is a generated GoMock package. package mocks @@ -12,17 +7,16 @@ package mocks import ( reflect "reflect" + gomock "github.com/golang/mock/gomock" controller "github.com/litmuschaos/chaos-exporter/controller" clients "github.com/litmuschaos/chaos-exporter/pkg/clients" v1alpha1 "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" - gomock "go.uber.org/mock/gomock" ) // MockResultCollector is a mock of ResultCollector interface. type MockResultCollector struct { ctrl *gomock.Controller recorder *MockResultCollectorMockRecorder - isgomock struct{} } // MockResultCollectorMockRecorder is the mock recorder for MockResultCollector. @@ -43,18 +37,18 @@ func (m *MockResultCollector) EXPECT() *MockResultCollectorMockRecorder { } // GetExperimentMetricsFromResult mocks base method. -func (m *MockResultCollector) GetExperimentMetricsFromResult(chaosResult *v1alpha1.ChaosResult, clients clients.ClientSets) (bool, error) { +func (m *MockResultCollector) GetExperimentMetricsFromResult(arg0 *v1alpha1.ChaosResult, arg1 clients.ClientSets) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetExperimentMetricsFromResult", chaosResult, clients) + ret := m.ctrl.Call(m, "GetExperimentMetricsFromResult", arg0, arg1) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // GetExperimentMetricsFromResult indicates an expected call of GetExperimentMetricsFromResult. -func (mr *MockResultCollectorMockRecorder) GetExperimentMetricsFromResult(chaosResult, clients any) *gomock.Call { +func (mr *MockResultCollectorMockRecorder) GetExperimentMetricsFromResult(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetExperimentMetricsFromResult", reflect.TypeOf((*MockResultCollector)(nil).GetExperimentMetricsFromResult), chaosResult, clients) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetExperimentMetricsFromResult", reflect.TypeOf((*MockResultCollector)(nil).GetExperimentMetricsFromResult), arg0, arg1) } // GetResultDetails mocks base method. @@ -72,18 +66,18 @@ func (mr *MockResultCollectorMockRecorder) GetResultDetails() *gomock.Call { } // GetResultList mocks base method. -func (m *MockResultCollector) GetResultList(clients clients.ClientSets, chaosNamespace string, monitoringEnabled *controller.MonitoringEnabled) ([]*v1alpha1.ChaosResult, error) { +func (m *MockResultCollector) GetResultList(arg0 clients.ClientSets, arg1 string, arg2 *controller.MonitoringEnabled) ([]*v1alpha1.ChaosResult, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetResultList", clients, chaosNamespace, monitoringEnabled) + ret := m.ctrl.Call(m, "GetResultList", arg0, arg1, arg2) ret0, _ := ret[0].([]*v1alpha1.ChaosResult) ret1, _ := ret[1].(error) return ret0, ret1 } // GetResultList indicates an expected call of GetResultList. -func (mr *MockResultCollectorMockRecorder) GetResultList(clients, chaosNamespace, monitoringEnabled any) *gomock.Call { +func (mr *MockResultCollectorMockRecorder) GetResultList(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetResultList", reflect.TypeOf((*MockResultCollector)(nil).GetResultList), clients, chaosNamespace, monitoringEnabled) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetResultList", reflect.TypeOf((*MockResultCollector)(nil).GetResultList), arg0, arg1, arg2) } // SetResultDetails mocks base method. diff --git a/controller/scrap_test.go b/controller/scrap_test.go index dc9abad..6b0ee79 100644 --- a/controller/scrap_test.go +++ b/controller/scrap_test.go @@ -8,7 +8,7 @@ import ( "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" "github.com/pkg/errors" "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" + "github.com/golang/mock/gomock" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -73,7 +73,7 @@ func TestGetLitmusChaosMetrics(t *testing.T) { tt.execFunc() client := CreateFakeClient(t) - _, err := r.GetLitmusChaosMetrics(client, tt.overallChaosResult, tt.monitoring) + _, err := r.GetLitmusChaosMetrics(client, &tt.overallChaosResult, tt.monitoring) if tt.isErr { require.Error(t, err) return diff --git a/controller/scrape.go b/controller/scrape.go index a0597c9..3564592 100644 --- a/controller/scrape.go +++ b/controller/scrape.go @@ -35,7 +35,7 @@ import ( var err error // GetLitmusChaosMetrics derive and send the chaos metrics -func (m *MetricesCollecter) GetLitmusChaosMetrics(clients clients.ClientSets, overallChaosResults []*litmuschaosv1alpha1.ChaosResult, monitoringEnabled *MonitoringEnabled) (*time.Duration, error) { +func (m *MetricesCollecter) GetLitmusChaosMetrics(clients clients.ClientSets, overallChaosResults *[]*litmuschaosv1alpha1.ChaosResult, monitoringEnabled *MonitoringEnabled) (*time.Duration, error) { engineCount := 0 // initialising the parameters for the namespaced scope metrics @@ -59,9 +59,9 @@ func (m *MetricesCollecter) GetLitmusChaosMetrics(clients clients.ClientSets, ov return nil, err } // unset the metrics correspond to deleted chaosresults - m.GaugeMetrics.unsetDeletedChaosResults(overallChaosResults, resultList) + m.GaugeMetrics.unsetDeletedChaosResults(*overallChaosResults, resultList) // updating the overall chaosresults items to latest - overallChaosResults = resultList + *overallChaosResults = resultList var needRequeue *time.Duration diff --git a/go.mod b/go.mod index fd2630f..dfa675a 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,11 @@ module github.com/litmuschaos/chaos-exporter -go 1.22 +go 1.20 require ( github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 github.com/aws/aws-sdk-go v1.40.27 + github.com/golang/mock v1.5.0 github.com/litmuschaos/chaos-operator v0.0.0-20230629040437-de73ffdd63da github.com/litmuschaos/litmus-go v0.0.0-20230605073551-d73728198577 github.com/onsi/ginkgo v1.16.4 @@ -13,7 +14,6 @@ require ( github.com/prometheus/client_golang v1.12.1 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 - go.uber.org/mock v0.5.0 k8s.io/api v0.26.0 k8s.io/apimachinery v0.26.0 k8s.io/client-go v12.0.0+incompatible diff --git a/go.sum b/go.sum index 272017a..e6adb63 100644 --- a/go.sum +++ b/go.sum @@ -178,7 +178,6 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -186,6 +185,7 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -484,8 +484,6 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= -go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= -go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= @@ -834,7 +832,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=