diff --git a/.github/workflows/container_description.yml b/.github/workflows/container_description.yml index dcca16f..7de8bb8 100644 --- a/.github/workflows/container_description.yml +++ b/.github/workflows/container_description.yml @@ -19,6 +19,8 @@ jobs: steps: - name: git checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - name: Set docker hub repo name run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> $GITHUB_ENV - name: Push README to Dockerhub @@ -41,6 +43,8 @@ jobs: steps: - name: git checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - name: Set quay.io org name run: echo "DOCKER_REPO=$(echo quay.io/${GITHUB_REPOSITORY_OWNER} | tr -d '-')" >> $GITHUB_ENV - name: Set quay.io repo name diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5342cbe..7989155 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -25,15 +25,20 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - name: Install Go - uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 with: - go-version: 1.24.x + go-version: 1.25.x - name: Install snmp_exporter/generator dependencies run: sudo apt-get update && sudo apt-get -y install libsnmp-dev if: github.repository == 'prometheus/snmp_exporter' + - name: Get golangci-lint version + id: golangci-lint-version + run: echo "version=$(make print-golangci-lint-version)" >> $GITHUB_OUTPUT - name: Lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 with: args: --verbose - version: v1.64.6 + version: ${{ steps.golangci-lint-version.outputs.version }} diff --git a/.golangci.yml b/.golangci.yml index 6175bc1..1eff4c1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,13 +1,9 @@ ---- +version: "2" linters: enable: - - sloglint - -run: - timeout: 5m - -issues: - exclude-rules: - - path: _test.go - linters: - - errcheck + - sloglint + exclusions: + rules: + - linters: + - errcheck + path: _test.go diff --git a/Makefile.common b/Makefile.common index 8cb3838..6762d0f 100644 --- a/Makefile.common +++ b/Makefile.common @@ -61,7 +61,8 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_ SKIP_GOLANGCI_LINT := GOLANGCI_LINT := GOLANGCI_LINT_OPTS ?= -GOLANGCI_LINT_VERSION ?= v1.64.6 +GOLANGCI_LINT_VERSION ?= v2.4.0 +GOLANGCI_FMT_OPTS ?= # golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64. # windows isn't included here because of the path separator being different. ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) @@ -138,7 +139,7 @@ common-deps: update-go-deps: @echo ">> updating Go dependencies" @for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \ - $(GO) get -d $$m; \ + $(GO) get $$m; \ done $(GO) mod tidy @@ -156,9 +157,13 @@ $(GOTEST_DIR): @mkdir -p $@ .PHONY: common-format -common-format: +common-format: $(GOLANGCI_LINT) @echo ">> formatting code" $(GO) fmt $(pkgs) +ifdef GOLANGCI_LINT + @echo ">> formatting code with golangci-lint" + $(GOLANGCI_LINT) fmt $(GOLANGCI_FMT_OPTS) +endif .PHONY: common-vet common-vet: @@ -248,8 +253,8 @@ $(PROMU): cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu rm -r $(PROMU_TMP) -.PHONY: proto -proto: +.PHONY: common-proto +common-proto: @echo ">> generating code from proto files" @./scripts/genproto.sh @@ -261,6 +266,10 @@ $(GOLANGCI_LINT): | sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION) endif +.PHONY: common-print-golangci-lint-version +common-print-golangci-lint-version: + @echo $(GOLANGCI_LINT_VERSION) + .PHONY: precheck precheck:: diff --git a/collectors/monitoring_collector.go b/collectors/monitoring_collector.go index a2c1543..21a5861 100644 --- a/collectors/monitoring_collector.go +++ b/collectors/monitoring_collector.go @@ -424,7 +424,7 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics( for _, point := range timeSeries.Points { endTime, err := time.Parse(time.RFC3339Nano, point.Interval.EndTime) if err != nil { - return fmt.Errorf("Error parsing TimeSeries Point interval end time `%s`: %s", point.Interval.EndTime, err) + return fmt.Errorf("error parsing TimeSeries Point interval end time `%s`: %s", point.Interval.EndTime, err) } if endTime.After(newestEndTime) { newestEndTime = endTime @@ -541,7 +541,7 @@ func (c *MonitoringCollector) generateHistogramBuckets( bucketKeys[i] = opts.ExponentialBuckets.Scale * math.Pow(opts.ExponentialBuckets.GrowthFactor, float64(i)) } default: - return nil, errors.New("Unknown distribution buckets") + return nil, errors.New("unknown distribution buckets") } // The last bucket is always infinity // @see https://cloud.google.com/monitoring/api/ref_v3/rest/v3/TypedValue#bucketoptions diff --git a/stackdriver_exporter.go b/stackdriver_exporter.go index 90c33b8..14876fb 100644 --- a/stackdriver_exporter.go +++ b/stackdriver_exporter.go @@ -161,7 +161,7 @@ func getDefaultGCPProject(ctx context.Context) (*string, error) { func createMonitoringService(ctx context.Context) (*monitoring.Service, error) { googleClient, err := google.DefaultClient(ctx, monitoring.MonitoringReadScope) if err != nil { - return nil, fmt.Errorf("Error creating Google client: %v", err) + return nil, fmt.Errorf("error creating Google client: %v", err) } googleClient.Timeout = *stackdriverHttpTimeout @@ -175,7 +175,7 @@ func createMonitoringService(ctx context.Context) (*monitoring.Service, error) { monitoringService, err := monitoring.NewService(ctx, option.WithHTTPClient(googleClient), option.WithUniverseDomain(*googleUniverseDomain)) if err != nil { - return nil, fmt.Errorf("Error creating Google Stackdriver Monitoring service: %v", err) + return nil, fmt.Errorf("error creating Google Stackdriver Monitoring service: %v", err) } return monitoringService, nil