Skip to content

Commit 9cd8632

Browse files
committed
update makefile and improve lint
Signed-off-by: Markus Blaschke <[email protected]>
1 parent afd22e7 commit 9cd8632

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

Makefile

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
.PHONY: all build clean image check vendor dependencies
2-
3-
NAME := azure-resourcemanager-exporter
1+
PROJECT_NAME := azure-resourcemanager-exporter
42
GIT_TAG := $(shell git describe --dirty --tags --always)
53
GIT_COMMIT := $(shell git rev-parse --short HEAD)
6-
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -extldflags "-static"
7-
8-
PKGS := $(shell go list ./... | grep -v -E '/vendor/|/test')
9-
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
10-
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
4+
LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -extldflags "-static"
115

6+
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
7+
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
128

9+
.PHONY: all
1310
all: build
1411

12+
.PHONY: clean
1513
clean:
1614
git clean -Xfd .
1715

16+
.PHONY: build
1817
build:
19-
CGO_ENABLED=0 go build -a -ldflags '$(LDFLAGS)' -o $(NAME) .
18+
CGO_ENABLED=0 go build -a -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
2019

20+
.PHONY: vendor
2121
vendor:
2222
go mod tidy
2323
go mod vendor
2424
go mod verify
2525

26+
.PHONY: image
2627
image: build
27-
docker build -t $(NAME):$(TAG) .
28+
docker build -t $(PROJECT_NAME):$(GIT_TAG) .
2829

2930
build-push-development:
30-
docker build -t webdevops/$(NAME):development . && docker push webdevops/$(NAME):development
31+
docker build -t webdevops/$(PROJECT_NAME):development . && docker push webdevops/$(PROJECT_NAME):development
3132

33+
.PHONY: test
3234
test:
3335
go test ./...
3436

3537
.PHONY: lint
3638
lint: $(GOLANGCI_LINT_BIN)
37-
# megacheck fails to respect build flags, causing compilation failure during linting.
38-
# instead, use the unused, gosimple, and staticcheck linters directly
39-
$(GOLANGCI_LINT_BIN) run -D megacheck -E unused,gosimple,staticcheck --timeout=10m
39+
$(GOLANGCI_LINT_BIN) run -E exportloopref,gofmt --timeout=10m
4040

41+
.PHONY: dependencies
4142
dependencies: $(GOLANGCI_LINT_BIN)
42-
go mod download
4343

4444
$(GOLANGCI_LINT_BIN):
45-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(FIRST_GOPATH)/bin v1.30.0
46-
45+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(FIRST_GOPATH)/bin v1.32.2

collector_base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *CollectorBase) collectionStart() {
4747
}
4848

4949
func (c *CollectorBase) collectionFinish() {
50-
duration := time.Now().Sub(c.collectionStartTime)
50+
duration := time.Since(c.collectionStartTime)
5151
c.LastScrapeDuration = &duration
5252

5353
if !c.isHidden {

config/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type (
1919
Azure struct {
2020
Environment *string `long:"azure-environment" env:"AZURE_ENVIRONMENT" description:"Azure environment name" default:"AZUREPUBLICCLOUD"`
2121
Subscription []string `long:"azure-subscription" env:"AZURE_SUBSCRIPTION_ID" env-delim:" " description:"Azure subscription ID"`
22-
Location []string `long:"azure-location" env:"AZURE_LOCATION" env-delim:" " description:"Azure locations" default:"westeurope" default:"northeurope"`
22+
Location []string `long:"azure-location" env:"AZURE_LOCATION" env-delim:" " description:"Azure locations" default:"westeurope" default:"northeurope"` //nolint:staticcheck
2323
ResourceGroupTags []string `long:"azure-resourcegroup-tag" env:"AZURE_RESOURCEGROUP_TAG" env-delim:" " description:"Azure ResourceGroup tags" default:"owner"`
2424
ResourceTags []string `long:"azure-resource-tag" env:"AZURE_RESOURCE_TAG" env-delim:" " description:"Azure Resource tags" default:"owner"`
2525
}

metrics_azurerm_network.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ func (m *MetricsCollectorAzureRmNetwork) collectAzureNics(ctx context.Context, l
304304

305305
// Collect Azure PublicIP metrics
306306
func (m *MetricsCollectorAzureRmNetwork) collectAzurePublicIp(ctx context.Context, logger *log.Entry, callback chan<- func(), subscription subscriptions.Subscription) {
307-
ipAddressList := []string{}
308-
309307
client := network.NewPublicIPAddressesClient(*subscription.SubscriptionID)
310308
client.Authorizer = AzureAuthorizer
311309

@@ -325,7 +323,6 @@ func (m *MetricsCollectorAzureRmNetwork) collectAzurePublicIp(ctx context.Contex
325323

326324
if val.IPAddress != nil {
327325
ipAddress = stringPtrToString(val.IPAddress)
328-
ipAddressList = append(ipAddressList, ipAddress)
329326
} else {
330327
ipAddress = "not allocated"
331328
gaugeValue = 0

portscanner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (c *Portscanner) Cleanup() {
116116
c.mux.Lock()
117117

118118
orphanedIpList := []string{}
119-
for ipAddress, _ := range c.List {
119+
for ipAddress := range c.List {
120120
if _, ok := c.PublicIps[ipAddress]; !ok {
121121
orphanedIpList = append(orphanedIpList, ipAddress)
122122
}

0 commit comments

Comments
 (0)