From 383a1e17940cdd8d11ebc99253b1a886fe3eb90d Mon Sep 17 00:00:00 2001 From: Silvestre Zabala Date: Thu, 29 Aug 2024 16:29:20 +0200 Subject: [PATCH] fixup! chore(deps): Bump `golangci-lint` to 1.60.2 --- src/autoscaler/api/broker/broker.go | 2 +- src/autoscaler/api/config/config.go | 3 ++- .../api/policyvalidator/policy_validator.go | 4 ++-- src/autoscaler/cf/oauth.go | 4 ++-- .../envelopeprocessor/envelope_processor.go | 12 +++++------ .../eventgenerator/aggregator/appManager.go | 2 +- .../eventgenerator/metric/fetcher.go | 2 +- .../metric/fetcher_factory_test.go | 1 + src/autoscaler/go.mod | 1 + src/autoscaler/go.sum | 1 + src/autoscaler/helpers/hash.go | 6 +++--- src/autoscaler/models/metrics.go | 2 +- src/autoscaler/scalingengine/striped_lock.go | 2 +- .../testhelpers/gomega_extensions.go | 21 +++++++------------ src/changelog/github/github.go | 2 +- 15 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/autoscaler/api/broker/broker.go b/src/autoscaler/api/broker/broker.go index c3bd81b975..05d15baada 100644 --- a/src/autoscaler/api/broker/broker.go +++ b/src/autoscaler/api/broker/broker.go @@ -737,7 +737,7 @@ func (b *Broker) planDefinitionExceeded(policy *models.ScalingPolicy, planID str return apiresponses.NewFailureResponse(errors.New("error validating policy"), http.StatusInternalServerError, "failed to check policy for plan adherence") } if !ok { - b.logger.Error("policy did not adhere to plan", fmt.Errorf(checkResult), lager.Data{"instanceID": instanceID, "policy": policy}) + b.logger.Error("policy did not adhere to plan", errors.New(checkResult), lager.Data{"instanceID": instanceID, "policy": policy}) return apiresponses.NewFailureResponse(fmt.Errorf("error: policy did not adhere to plan: %s", checkResult), http.StatusBadRequest, "policy did not adhere to plan") } return nil diff --git a/src/autoscaler/api/config/config.go b/src/autoscaler/api/config/config.go index a9a286f4a9..33ae26ca4f 100644 --- a/src/autoscaler/api/config/config.go +++ b/src/autoscaler/api/config/config.go @@ -11,6 +11,7 @@ import ( "golang.org/x/crypto/bcrypt" "github.com/xeipuuv/gojsonschema" + "gopkg.in/errgo.v2/fmt/errors" "gopkg.in/yaml.v3" "code.cloudfoundry.org/app-autoscaler/src/autoscaler/db" @@ -267,7 +268,7 @@ func (c *Config) Validate() error { } } errString += "}" - return fmt.Errorf(errString) + return errors.New(errString) } return nil diff --git a/src/autoscaler/api/policyvalidator/policy_validator.go b/src/autoscaler/api/policyvalidator/policy_validator.go index 966107234b..6f55d2c0ef 100644 --- a/src/autoscaler/api/policyvalidator/policy_validator.go +++ b/src/autoscaler/api/policyvalidator/policy_validator.go @@ -415,7 +415,7 @@ func (pv *PolicyValidator) validateOverlappingInRecurringSchedules(policy *model recScheds := policy.Schedules.RecurringSchedules for scheduleIndexB := 0; scheduleIndexB < length-1; scheduleIndexB++ { for scheduleIndexA := scheduleIndexB + 1; scheduleIndexA < length; scheduleIndexA++ { - if (recScheds[scheduleIndexA].DaysOfWeek != nil && len(recScheds[scheduleIndexA].DaysOfWeek) > 0) && (recScheds[scheduleIndexB].DaysOfWeek != nil && len(recScheds[scheduleIndexB].DaysOfWeek) > 0) { + if (len(recScheds[scheduleIndexA].DaysOfWeek) > 0) && (len(recScheds[scheduleIndexB].DaysOfWeek) > 0) { if hasIntersection(recScheds[scheduleIndexA].DaysOfWeek, recScheds[scheduleIndexB].DaysOfWeek) { if compareTimesGTEQ(recScheds[scheduleIndexB].EndTime, recScheds[scheduleIndexA].StartTime) && compareTimesGTEQ(recScheds[scheduleIndexA].EndTime, recScheds[scheduleIndexB].StartTime) && compareDatesGTEQ(recScheds[scheduleIndexB].EndDate, recScheds[scheduleIndexA].StartDate) && compareDatesGTEQ(recScheds[scheduleIndexA].EndDate, recScheds[scheduleIndexB].StartDate) { @@ -432,7 +432,7 @@ func (pv *PolicyValidator) validateOverlappingInRecurringSchedules(policy *model } } - if (recScheds[scheduleIndexA].DaysOfMonth != nil && len(recScheds[scheduleIndexA].DaysOfMonth) > 0) && (recScheds[scheduleIndexB].DaysOfMonth != nil && len(recScheds[scheduleIndexB].DaysOfMonth) > 0) { + if (len(recScheds[scheduleIndexA].DaysOfMonth) > 0) && (len(recScheds[scheduleIndexB].DaysOfMonth) > 0) { if hasIntersection(recScheds[scheduleIndexA].DaysOfMonth, recScheds[scheduleIndexB].DaysOfMonth) { if compareTimesGTEQ(recScheds[scheduleIndexB].EndTime, recScheds[scheduleIndexA].StartTime) && compareTimesGTEQ(recScheds[scheduleIndexA].EndTime, recScheds[scheduleIndexB].StartTime) && compareDatesGTEQ(recScheds[scheduleIndexB].EndDate, recScheds[scheduleIndexA].StartDate) && compareDatesGTEQ(recScheds[scheduleIndexA].EndDate, recScheds[scheduleIndexB].StartDate) { diff --git a/src/autoscaler/cf/oauth.go b/src/autoscaler/cf/oauth.go index 8fe6c938dc..f5c37196e7 100644 --- a/src/autoscaler/cf/oauth.go +++ b/src/autoscaler/cf/oauth.go @@ -17,8 +17,8 @@ const ( ) var ( - ErrUnauthorized = fmt.Errorf(http.StatusText(http.StatusUnauthorized)) - ErrInvalidTokenFormat = fmt.Errorf("Invalid token format") + ErrUnauthorized = errors.New(http.StatusText(http.StatusUnauthorized)) + ErrInvalidTokenFormat = errors.New("invalid token format") ) func (c *Client) IsUserSpaceDeveloper(userToken string, appId Guid) (bool, error) { diff --git a/src/autoscaler/envelopeprocessor/envelope_processor.go b/src/autoscaler/envelopeprocessor/envelope_processor.go index a29f6865dd..78686d544e 100644 --- a/src/autoscaler/envelopeprocessor/envelope_processor.go +++ b/src/autoscaler/envelopeprocessor/envelope_processor.go @@ -112,7 +112,7 @@ func getResponsetimeInstanceMetrics(envelopes []*loggregator_v2.Envelope, appID responseTimeMetric := models.AppInstanceMetric{ AppId: appID, - InstanceIndex: uint32(instanceIndex), + InstanceIndex: instanceIndex, Name: models.MetricNameResponseTime, Unit: models.UnitMilliseconds, Value: fmt.Sprintf("%d", int64(math.Ceil(float64(sumResponseTime)/float64(numReq*1000*1000)))), @@ -145,7 +145,7 @@ func getThroughputInstanceMetrics(envelopes []*loggregator_v2.Envelope, appID st throughputMetric := models.AppInstanceMetric{ AppId: appID, - InstanceIndex: uint32(instanceIndex), + InstanceIndex: instanceIndex, Name: models.MetricNameThroughput, Unit: models.UnitRPS, Value: fmt.Sprintf("%d", int(math.Ceil(float64(numReq)/collectionInterval.Seconds()))), @@ -196,13 +196,13 @@ func isContainerMetricEnvelope(e *loggregator_v2.Envelope) bool { func processContainerMetrics(e *loggregator_v2.Envelope, currentTimeStamp int64) []models.AppInstanceMetric { var metrics []models.AppInstanceMetric appID := e.SourceId - instanceIndex, _ := strconv.ParseInt(e.InstanceId, 10, 32) + instanceIndex, _ := strconv.ParseUint(e.InstanceId, 10, 64) g := e.GetGauge() timestamp := e.Timestamp baseAppInstanceMetric := models.AppInstanceMetric{ AppId: appID, - InstanceIndex: uint32(instanceIndex), + InstanceIndex: instanceIndex, CollectedAt: currentTimeStamp, Timestamp: timestamp, } @@ -296,12 +296,12 @@ func getCPUEntitlementInstanceMetric(cpuEntitlementValue float64) models.AppInst func processCustomMetrics(e *loggregator_v2.Envelope, currentTimestamp int64) []models.AppInstanceMetric { var metrics []models.AppInstanceMetric - instanceIndex, _ := strconv.ParseInt(e.InstanceId, 10, 32) + instanceIndex, _ := strconv.ParseUint(e.InstanceId, 10, 64) for n, v := range e.GetGauge().GetMetrics() { metrics = append(metrics, models.AppInstanceMetric{ AppId: e.SourceId, - InstanceIndex: uint32(instanceIndex), + InstanceIndex: instanceIndex, CollectedAt: currentTimestamp, Name: n, Unit: v.Unit, diff --git a/src/autoscaler/eventgenerator/aggregator/appManager.go b/src/autoscaler/eventgenerator/aggregator/appManager.go index abdb50b3ec..c76f064a4e 100644 --- a/src/autoscaler/eventgenerator/aggregator/appManager.go +++ b/src/autoscaler/eventgenerator/aggregator/appManager.go @@ -103,7 +103,7 @@ func (am *AppManager) retrievePolicies() ([]*models.PolicyJson, error) { } func (am *AppManager) isEventgeneratorRespForApp(appID string) bool { - return helpers.FNVHash(appID)%uint32(am.nodeNum) == uint32(am.nodeIndex) + return helpers.FNVHash(appID)%uint64(am.nodeNum) == uint64(am.nodeIndex) } func (am *AppManager) computePolicies(policyJsons []*models.PolicyJson) map[string]*models.AppPolicy { diff --git a/src/autoscaler/eventgenerator/metric/fetcher.go b/src/autoscaler/eventgenerator/metric/fetcher.go index 1ab423957f..98a020fea2 100644 --- a/src/autoscaler/eventgenerator/metric/fetcher.go +++ b/src/autoscaler/eventgenerator/metric/fetcher.go @@ -116,7 +116,7 @@ func (l *logCacheFetcher) getMetricsPromQLAPI(appId string, metricType string, c return []models.AppInstanceMetric{}, fmt.Errorf("sample does not contain a point") } - instanceId := uint32(instanceIdUInt) + instanceId := instanceIdUInt valueWithoutDecimalsRoundedToCeiling := fmt.Sprintf("%.0f", math.Ceil(point.GetValue())) metrics = append(metrics, models.AppInstanceMetric{ diff --git a/src/autoscaler/eventgenerator/metric/fetcher_factory_test.go b/src/autoscaler/eventgenerator/metric/fetcher_factory_test.go index a830db8118..c408c7f412 100644 --- a/src/autoscaler/eventgenerator/metric/fetcher_factory_test.go +++ b/src/autoscaler/eventgenerator/metric/fetcher_factory_test.go @@ -129,5 +129,6 @@ var _ = Describe("logCacheFetcherFactory", func() { func getUnexportedField(name string, client metric.LogCacheClient) interface{} { field := reflect.ValueOf(client).Elem().FieldByName(name) + // #nosec G115 -- test code return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface() } diff --git a/src/autoscaler/go.mod b/src/autoscaler/go.mod index 99e5113fe7..a58473f903 100644 --- a/src/autoscaler/go.mod +++ b/src/autoscaler/go.mod @@ -46,6 +46,7 @@ require ( golang.org/x/net v0.28.0 golang.org/x/time v0.5.0 google.golang.org/grpc v1.65.0 + gopkg.in/errgo.v2 v2.1.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/src/autoscaler/go.sum b/src/autoscaler/go.sum index 355ff7cda4..2a4405189d 100644 --- a/src/autoscaler/go.sum +++ b/src/autoscaler/go.sum @@ -1746,6 +1746,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/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/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= diff --git a/src/autoscaler/helpers/hash.go b/src/autoscaler/helpers/hash.go index 67fb416f41..3506aaa5e1 100644 --- a/src/autoscaler/helpers/hash.go +++ b/src/autoscaler/helpers/hash.go @@ -2,8 +2,8 @@ package helpers import "hash/fnv" -func FNVHash(key string) uint32 { - h := fnv.New32a() +func FNVHash(key string) uint64 { + h := fnv.New64a() h.Write([]byte(key)) - return h.Sum32() + return h.Sum64() } diff --git a/src/autoscaler/models/metrics.go b/src/autoscaler/models/metrics.go index 8a45269b4b..797887d513 100644 --- a/src/autoscaler/models/metrics.go +++ b/src/autoscaler/models/metrics.go @@ -27,7 +27,7 @@ const ( type AppInstanceMetric struct { AppId string `json:"app_id" db:"app_id"` - InstanceIndex uint32 `json:"instance_index" db:"instance_index"` + InstanceIndex uint64 `json:"instance_index" db:"instance_index"` CollectedAt int64 `json:"collected_at" db:"collected_at"` Name string `json:"name" db:"name"` Unit string `json:"unit" db:"unit"` diff --git a/src/autoscaler/scalingengine/striped_lock.go b/src/autoscaler/scalingengine/striped_lock.go index baf9a34d7e..5a1ca9cd6a 100644 --- a/src/autoscaler/scalingengine/striped_lock.go +++ b/src/autoscaler/scalingengine/striped_lock.go @@ -30,5 +30,5 @@ func (sl *StripedLock) GetLock(key string) *sync.Mutex { if err != nil { return nil } - return sl.locks[h.Sum32()%uint32(len(sl.locks))] + return sl.locks[int(h.Sum32())%len(sl.locks)] } diff --git a/src/autoscaler/testhelpers/gomega_extensions.go b/src/autoscaler/testhelpers/gomega_extensions.go index a8c41d0e22..596306b676 100644 --- a/src/autoscaler/testhelpers/gomega_extensions.go +++ b/src/autoscaler/testhelpers/gomega_extensions.go @@ -10,34 +10,27 @@ var noOpHandler = func(_ http.ResponseWriter, _ *http.Request) { } func RespondWithMultiple(handlers ...http.HandlerFunc) http.HandlerFunc { - var responseNumber int32 = 0 + var responseNumber int64 = 0 if len(handlers) > 0 { return func(w http.ResponseWriter, req *http.Request) { - responseNum := atomic.LoadInt32(&responseNumber) - handlerNumber := Min(responseNum, int32(len(handlers)-1)) + responseNum := atomic.LoadInt64(&responseNumber) + handlerNumber := min(responseNum, int64(len(handlers)-1)) handlers[handlerNumber](w, req) - atomic.AddInt32(&responseNumber, 1) + atomic.AddInt64(&responseNumber, 1) } } return noOpHandler } func RoundRobinWithMultiple(handlers ...http.HandlerFunc) http.HandlerFunc { - var responseNumber int32 = 0 + var responseNumber int64 = 0 if len(handlers) > 0 { return func(w http.ResponseWriter, req *http.Request) { - handlerNumber := atomic.LoadInt32(&responseNumber) % int32(len(handlers)) + handlerNumber := atomic.LoadInt64(&responseNumber) % int64(len(handlers)) handlers[handlerNumber](w, req) - atomic.AddInt32(&responseNumber, 1) + atomic.AddInt64(&responseNumber, 1) } } return noOpHandler } - -func Min(one, two int32) int32 { - if one < two { - return one - } - return two -} diff --git a/src/changelog/github/github.go b/src/changelog/github/github.go index b581c45383..26c5b619b4 100644 --- a/src/changelog/github/github.go +++ b/src/changelog/github/github.go @@ -238,7 +238,7 @@ func (g GitHub) FetchPullRequests(startingCommitSHA, lastCommitSHA string) ([]Pu } } -func (g GitHub) FetchLabelsForPullRequest(owner, repo string, pullRequestNumber int) ([]string, error) { +func (g GitHub) FetchLabelsForPullRequest(owner, repo string, pullRequestNumber int32) ([]string, error) { var PullRequestlabelsQuery struct { Repository struct { PullRequest struct {