mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-25 08:41:00 +00:00
*: add staticcheck target back
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
65070524c3
commit
8f56cc811d
7 changed files with 44 additions and 40 deletions
7
Makefile
7
Makefile
|
@ -11,14 +11,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# By being first, this takes over plain `make`. It cuts out `staticcheck`
|
||||
# because in the circleci/golang:1.11 image it chokes on the go module cache.
|
||||
default: precheck style unused build test
|
||||
|
||||
include Makefile.common
|
||||
|
||||
STATICCHECK_IGNORE = \
|
||||
github.com/prometheus/statsd_exporter/main.go:SA1019 \
|
||||
STATICCHECK_IGNORE =
|
||||
|
||||
DOCKER_IMAGE_NAME ?= statsd-exporter
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ GO ?= go
|
|||
GOFMT ?= $(GO)fmt
|
||||
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
|
||||
GOOPTS ?=
|
||||
GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
|
||||
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
|
||||
|
||||
GO_VERSION ?= $(shell $(GO) version)
|
||||
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
|
||||
|
@ -62,17 +64,30 @@ PROMU := $(FIRST_GOPATH)/bin/promu
|
|||
STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
|
||||
pkgs = ./...
|
||||
|
||||
GO_VERSION ?= $(shell $(GO) version)
|
||||
GO_BUILD_PLATFORM ?= $(subst /,-,$(lastword $(GO_VERSION)))
|
||||
ifeq (arm, $(GOHOSTARCH))
|
||||
GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
|
||||
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
|
||||
else
|
||||
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
|
||||
endif
|
||||
|
||||
PROMU_VERSION ?= 0.2.0
|
||||
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
|
||||
STATICCHECK_VERSION ?= 2019.1
|
||||
STATICCHECK_URL := https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_$(GOHOSTOS)_$(GOHOSTARCH)
|
||||
|
||||
PREFIX ?= $(shell pwd)
|
||||
BIN_DIR ?= $(shell pwd)
|
||||
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
|
||||
DOCKER_REPO ?= prom
|
||||
|
||||
ifeq ($(GOHOSTARCH),amd64)
|
||||
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows))
|
||||
# Only supported on amd64
|
||||
test-flags := -race
|
||||
endif
|
||||
endif
|
||||
|
||||
.PHONY: all
|
||||
all: precheck style staticcheck unused build test
|
||||
|
||||
|
@ -110,12 +125,12 @@ common-test-short:
|
|||
.PHONY: common-test
|
||||
common-test:
|
||||
@echo ">> running all tests"
|
||||
GO111MODULE=$(GO111MODULE) $(GO) test -race $(GOOPTS) $(pkgs)
|
||||
GO111MODULE=$(GO111MODULE) $(GO) test $(test-flags) $(GOOPTS) $(pkgs)
|
||||
|
||||
.PHONY: common-format
|
||||
common-format:
|
||||
@echo ">> formatting code"
|
||||
GO111MODULE=$(GO111MODULE) $(GO) fmt $(GOOPTS) $(pkgs)
|
||||
GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
|
||||
|
||||
.PHONY: common-vet
|
||||
common-vet:
|
||||
|
@ -125,8 +140,12 @@ common-vet:
|
|||
.PHONY: common-staticcheck
|
||||
common-staticcheck: $(STATICCHECK)
|
||||
@echo ">> running staticcheck"
|
||||
chmod +x $(STATICCHECK)
|
||||
ifdef GO111MODULE
|
||||
GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" -checks "SA*" $(pkgs)
|
||||
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
|
||||
# Otherwise staticcheck might fail randomly for some reason not yet explained.
|
||||
GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
|
||||
GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
|
||||
else
|
||||
$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
|
||||
endif
|
||||
|
@ -140,8 +159,9 @@ else
|
|||
ifdef GO111MODULE
|
||||
@echo ">> running check for unused/missing packages in go.mod"
|
||||
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
|
||||
ifeq (,$(wildcard vendor))
|
||||
@git diff --exit-code -- go.sum go.mod
|
||||
ifneq (,$(wildcard vendor))
|
||||
else
|
||||
@echo ">> running check for unused packages in vendor/"
|
||||
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
|
||||
@git diff --exit-code -- go.sum go.mod vendor/
|
||||
|
@ -175,30 +195,20 @@ common-docker-tag-latest:
|
|||
promu: $(PROMU)
|
||||
|
||||
$(PROMU):
|
||||
curl -s -L $(PROMU_URL) | tar -xvz -C /tmp
|
||||
mkdir -v -p $(FIRST_GOPATH)/bin
|
||||
cp -v /tmp/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(PROMU)
|
||||
$(eval PROMU_TMP := $(shell mktemp -d))
|
||||
curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
|
||||
mkdir -p $(FIRST_GOPATH)/bin
|
||||
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
|
||||
rm -r $(PROMU_TMP)
|
||||
|
||||
.PHONY: proto
|
||||
proto:
|
||||
@echo ">> generating code from proto files"
|
||||
@./scripts/genproto.sh
|
||||
|
||||
.PHONY: $(STATICCHECK)
|
||||
$(STATICCHECK):
|
||||
ifdef GO111MODULE
|
||||
# Get staticcheck from a temporary directory to avoid modifying the local go.{mod,sum}.
|
||||
# See https://github.com/golang/go/issues/27643.
|
||||
# For now, we are using the next branch of staticcheck because master isn't compatible yet with Go modules.
|
||||
tmpModule=$$(mktemp -d 2>&1) && \
|
||||
mkdir -p $${tmpModule}/staticcheck && \
|
||||
cd "$${tmpModule}"/staticcheck && \
|
||||
GO111MODULE=on $(GO) mod init example.com/staticcheck && \
|
||||
GO111MODULE=on GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck@next && \
|
||||
rm -rf $${tmpModule};
|
||||
else
|
||||
GOOS= GOARCH= GO111MODULE=off $(GO) get -u honnef.co/go/tools/cmd/staticcheck
|
||||
endif
|
||||
mkdir -p $(FIRST_GOPATH)/bin
|
||||
curl -s -L $(STATICCHECK_URL) > $(STATICCHECK)
|
||||
|
||||
ifdef GOVENDOR
|
||||
.PHONY: $(GOVENDOR)
|
||||
|
|
|
@ -487,7 +487,7 @@ func NewExporter(mapper *mapper.MetricMapper) *Exporter {
|
|||
Summaries: NewSummaryContainer(mapper),
|
||||
Histograms: NewHistogramContainer(mapper),
|
||||
mapper: mapper,
|
||||
labelValues: make(map[string]map[uint64]*LabelValues, 0),
|
||||
labelValues: make(map[string]map[uint64]*LabelValues),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -513,9 +513,9 @@ func buildEvent(statType, metric string, value float64, relative bool, labels ma
|
|||
labels: labels,
|
||||
}, nil
|
||||
case "s":
|
||||
return nil, fmt.Errorf("No support for StatsD sets")
|
||||
return nil, fmt.Errorf("no support for StatsD sets")
|
||||
default:
|
||||
return nil, fmt.Errorf("Bad stat type %s", statType)
|
||||
return nil, fmt.Errorf("bad stat type %s", statType)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ func TestNegativeCounter(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
events := make(chan Events, 0)
|
||||
events := make(chan Events)
|
||||
go func() {
|
||||
c := Events{
|
||||
&CounterEvent{
|
||||
|
@ -68,7 +68,7 @@ func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
events := make(chan Events, 0)
|
||||
events := make(chan Events)
|
||||
|
||||
go func() {
|
||||
for _, l := range []statsDPacketHandler{&StatsDUDPListener{}, &mockStatsDTCPListener{}} {
|
||||
|
@ -83,7 +83,7 @@ func TestInvalidUtf8InDatadogTagValue(t *testing.T) {
|
|||
|
||||
func TestHistogramUnits(t *testing.T) {
|
||||
// Start exporter with a synchronous channel
|
||||
events := make(chan Events, 0)
|
||||
events := make(chan Events)
|
||||
go func() {
|
||||
ex := NewExporter(&mapper.MetricMapper{})
|
||||
ex.mapper.Defaults.TimerType = mapper.TimerTypeHistogram
|
||||
|
@ -181,7 +181,7 @@ func TestEscapeMetricName(t *testing.T) {
|
|||
// bazqux metric should expire with ttl of 2s
|
||||
func TestTtlExpiration(t *testing.T) {
|
||||
// Mock a time.NewTicker
|
||||
tickerCh := make(chan time.Time, 0)
|
||||
tickerCh := make(chan time.Time)
|
||||
clock.ClockInstance = &clock.Clock{
|
||||
TickerCh: tickerCh,
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ mappings:
|
|||
if err != nil {
|
||||
t.Fatalf("Config load error: %s %s", config, err)
|
||||
}
|
||||
events := make(chan Events, 0)
|
||||
events := make(chan Events)
|
||||
defer close(events)
|
||||
go func() {
|
||||
ex := NewExporter(testMapper)
|
||||
|
|
1
main.go
1
main.go
|
@ -34,6 +34,7 @@ func init() {
|
|||
}
|
||||
|
||||
func serveHTTP(listenAddress, metricsEndpoint string) {
|
||||
//lint:ignore SA1019 prometheus.Handler() is deprecated.
|
||||
http.Handle(metricsEndpoint, prometheus.Handler())
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(`<html>
|
||||
|
|
|
@ -262,7 +262,7 @@ func TestIfNeedBacktracking(mappings []string, orderingDisabled bool) bool {
|
|||
for i1, r1 := range rules {
|
||||
currentRuleNeedBacktrack := false
|
||||
re1 := rulesRE[i1]
|
||||
if re1 == nil || strings.Index(r1, "*") == -1 {
|
||||
if re1 == nil || !strings.Contains(r1, "*") {
|
||||
continue
|
||||
}
|
||||
// if rule r1 is A.B.C.*.E.*, is there a rule r2 is A.B.C.D.x.x or A.B.C.*.E.F ? (x is any string or *)
|
||||
|
|
|
@ -54,8 +54,6 @@ type MetricMapper struct {
|
|||
MappingsCount prometheus.Gauge
|
||||
}
|
||||
|
||||
type matchMetricType string
|
||||
|
||||
type MetricMapping struct {
|
||||
Match string `yaml:"match"`
|
||||
Name string `yaml:"name"`
|
||||
|
|
Loading…
Reference in a new issue