Skip to content

Commit e075051

Browse files
prombotSuperQ
andauthored
Synchronize common files from prometheus/prometheus (#202)
* Update common Prometheus files Signed-off-by: prombot <prometheus-team@googlegroups.com> * Update linter config/fixes. Signed-off-by: SuperQ <superq@gmail.com> --------- Signed-off-by: prombot <prometheus-team@googlegroups.com> Signed-off-by: SuperQ <superq@gmail.com> Co-authored-by: SuperQ <superq@gmail.com>
1 parent 0426fd3 commit e075051

File tree

6 files changed

+87
-31
lines changed

6 files changed

+87
-31
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
# This action is synced from https://github.com/prometheus/prometheus
3+
name: golangci-lint
4+
on:
5+
push:
6+
paths:
7+
- "go.sum"
8+
- "go.mod"
9+
- "**.go"
10+
- "scripts/errcheck_excludes.txt"
11+
- ".github/workflows/golangci-lint.yml"
12+
- ".golangci.yml"
13+
pull_request:
14+
15+
permissions: # added using https://github.com/step-security/secure-repo
16+
contents: read
17+
18+
jobs:
19+
golangci:
20+
permissions:
21+
contents: read # for actions/checkout to fetch code
22+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
23+
name: lint
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
persist-credentials: false
30+
- name: Install Go
31+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
32+
with:
33+
go-version: 1.25.x
34+
- name: Install snmp_exporter/generator dependencies
35+
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
36+
if: github.repository == 'prometheus/snmp_exporter'
37+
- name: Get golangci-lint version
38+
id: golangci-lint-version
39+
run: echo "version=$(make print-golangci-lint-version)" >> $GITHUB_OUTPUT
40+
- name: Lint
41+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
42+
with:
43+
args: --verbose
44+
version: ${{ steps.golangci-lint-version.outputs.version }}

.golangci.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
version: "2"
2-
3-
run:
4-
deadline: 5m
5-
6-
issues:
7-
exclude-rules:
8-
- path: _test.go
9-
linters:
10-
- errcheck
11-
12-
linters-settings:
13-
errcheck:
14-
exclude-functions:
15-
- (github.com/go-kit/log.Logger).Log
16-
- fmt.Fprintln
17-
- fmt.Fprint
2+
linters:
3+
settings:
4+
errcheck:
5+
exclude-functions:
6+
- (github.com/go-kit/log.Logger).Log
7+
- fmt.Fprintln
8+
- fmt.Fprint
9+
exclusions:
10+
generated: lax
11+
presets:
12+
- comments
13+
- common-false-positives
14+
- legacy
15+
- std-error-handling
16+
rules:
17+
- linters:
18+
- errcheck
19+
path: _test.go
20+
formatters:
21+
exclusions:
22+
generated: lax

Makefile.common

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
6161
SKIP_GOLANGCI_LINT :=
6262
GOLANGCI_LINT :=
6363
GOLANGCI_LINT_OPTS ?=
64-
GOLANGCI_LINT_VERSION ?= v1.61.0
64+
GOLANGCI_LINT_VERSION ?= v2.1.5
65+
GOLANGCI_FMT_OPTS ?=
6566
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
6667
# windows isn't included here because of the path separator being different.
6768
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
@@ -156,9 +157,13 @@ $(GOTEST_DIR):
156157
@mkdir -p $@
157158

158159
.PHONY: common-format
159-
common-format:
160+
common-format: $(GOLANGCI_LINT)
160161
@echo ">> formatting code"
161162
$(GO) fmt $(pkgs)
163+
ifdef GOLANGCI_LINT
164+
@echo ">> formatting code with golangci-lint"
165+
$(GOLANGCI_LINT) fmt $(GOLANGCI_FMT_OPTS)
166+
endif
162167

163168
.PHONY: common-vet
164169
common-vet:
@@ -248,8 +253,8 @@ $(PROMU):
248253
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
249254
rm -r $(PROMU_TMP)
250255

251-
.PHONY: proto
252-
proto:
256+
.PHONY: common-proto
257+
common-proto:
253258
@echo ">> generating code from proto files"
254259
@./scripts/genproto.sh
255260

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func substituteEnvVars(b []byte, logger log.Logger) (r []byte, err error) {
9292

9393
v, ok := os.LookupEnv(string(n))
9494
if !ok {
95-
err = fmt.Errorf("Missing env variable: %q", n)
95+
err = fmt.Errorf("missing env variable: %q", n)
9696
return nil
9797
}
9898
return []byte(v)

pkg/config/config_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,12 @@ func newReceiverTestConfig(mandatory []string, optional []string) *receiverTestC
380380

381381
for _, name := range mandatory {
382382
var value reflect.Value
383-
if name == "APIURL" {
383+
switch name {
384+
case "APIURL":
384385
value = reflect.ValueOf("https://jiralert.atlassian.net")
385-
} else if name == "ReopenDuration" {
386+
case "ReopenDuration":
386387
value = reflect.ValueOf("30d")
387-
} else {
388+
default:
388389
value = reflect.ValueOf(name)
389390
}
390391

@@ -393,15 +394,16 @@ func newReceiverTestConfig(mandatory []string, optional []string) *receiverTestC
393394

394395
for _, name := range optional {
395396
var value reflect.Value
396-
if name == "AddGroupLabels" {
397+
switch name {
398+
case "AddGroupLabels":
397399
value = reflect.ValueOf(&addGroupLabelsDefaultVal)
398-
} else if name == "UpdateInComment" {
400+
case "UpdateInComment":
399401
value = reflect.ValueOf(&updateInCommentDefaultVal)
400-
} else if name == "AutoResolve" {
402+
case "AutoResolve":
401403
value = reflect.ValueOf(&AutoResolve{State: "Done"})
402-
} else if name == "StaticLabels" {
404+
case "StaticLabels":
403405
value = reflect.ValueOf([]string{})
404-
} else {
406+
default:
405407
value = reflect.ValueOf(name)
406408
}
407409

pkg/notify/notify.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,11 @@ func toGroupTicketLabel(groupLabels alertmanager.KV, hashJiraLabel bool) string
319319
buf := bytes.NewBufferString("ALERT{")
320320
for _, p := range groupLabels.SortedPairs() {
321321
buf.WriteString(p.Name)
322-
buf.WriteString(fmt.Sprintf("=%q,", p.Value))
322+
fmt.Fprintf(buf, "=%q,", p.Value)
323323
}
324324
buf.Truncate(buf.Len() - 1)
325325
buf.WriteString("}")
326-
return strings.Replace(buf.String(), " ", "", -1)
326+
return strings.ReplaceAll(buf.String(), " ", "")
327327
}
328328

329329
func (r *Receiver) search(projects []string, issueLabel string) (*jira.Issue, bool, error) {

0 commit comments

Comments
 (0)