From bfe6ebcb0f31710a9f4b1fed6fc7e4efe200e801 Mon Sep 17 00:00:00 2001 From: maier Date: Wed, 31 Mar 2021 07:37:49 -0400 Subject: [PATCH 1/7] add: lint workflow --- .github/workflow/golangci-lint.yml | 19 +++ .golangci.yml | 262 +++++++++++++++++++++++++++++ 2 files changed, 281 insertions(+) create mode 100644 .github/workflow/golangci-lint.yml create mode 100644 .golangci.yml diff --git a/.github/workflow/golangci-lint.yml b/.github/workflow/golangci-lint.yml new file mode 100644 index 0000000..75119eb --- /dev/null +++ b/.github/workflow/golangci-lint.yml @@ -0,0 +1,19 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + pull_request: +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.38 + args: --timeout=5m diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d862e90 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,262 @@ +run: + # default is true. Enables skipping of directories: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs-use-default: true + skip-files: + - ".*_mock_test.go$" + # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + #commented out for: https://github.com/golangci/golangci-lint/issues/1502 + #modules-download-mode: readonly + +# all available settings of specific linters +linters-settings: + errcheck: + # report about not checking of errors in type assetions: `a := b.(MyStruct)`; + # default is false: such cases aren't reported by default. + check-type-assertions: false + + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; + # default is false: such cases aren't reported by default. + check-blank: false + + funlen: + lines: 100 + statements: 50 + + govet: + # report about shadowed variables + check-shadowing: true + + # settings per analyzer + # settings: + # printf: # analyzer name, run `go tool vet help` to see all analyzers + # funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer + # - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + # - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + # - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + # - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + + # enable or disable analyzers by name + # enable: + # - atomicalign + enable-all: true + # disable: + # - shadow + # disable-all: false + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0.8 + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: true + goimports: + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + local-prefixes: github.com/circonus-labs + gocyclo: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 10 + gocognit: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 10 + dupl: + # tokens count to trigger issue, 150 by default + threshold: 100 + goconst: + # minimal length of string constant, 3 by default + min-len: 3 + # minimal occurrences count to trigger, 3 by default + min-occurrences: 3 + depguard: + # list-type: blacklist + # include-go-root: false + # packages: + # - github.com/sirupsen/logrus + # packages-with-error-messages: + # # specify an error message to output when a blacklisted package is used + # github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" + misspell: + # Correct spellings using locale preferences for US or UK. + # Default is to use a neutral variety of English. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + locale: US + # ignore-words: + # - someword + lll: + # max line length, lines longer will be reported. Default is 120. + # '\t' is counted as 1 character by default, and can be changed with the tab-width option + line-length: 120 + # tab width in spaces. Default to 1. + tab-width: 1 + unused: + # treat code as a program (not a library) and report unused exported identifiers; default is false. + # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find funcs usages. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + unparam: + # Inspect exported functions, default is false. Set to true if no external program/library imports your code. + # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find external interfaces. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + nakedret: + # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 + max-func-lines: 30 + prealloc: + # XXX: we don't recommend using this linter before doing performance profiling. + # For most programs usage of prealloc will be a premature optimization. + + # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. + # True by default. + simple: true + range-loops: true # Report preallocation suggestions on range loops, true by default + for-loops: false # Report preallocation suggestions on for loops, false by default + gocritic: + # # Which checks should be enabled; can't be combined with 'disabled-checks'; + # # See https://go-critic.github.io/overview#checks-overview + # # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` + # # By default list of stable checks is used. + # enabled-checks: + # - rangeValCopy + + # # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty + # disabled-checks: + # - regexpMust + + # # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. + # # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". + # enabled-tags: + # - performance + + # settings: # settings passed to gocritic + # captLocal: # must be valid enabled check name + # paramsOnly: true + # rangeValCopy: + # sizeThreshold: 32 + godox: + # # report any comments starting with keywords, this is useful for TODO or FIXME comments that + # # might be left in the code accidentally and should be resolved before merging + # keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting + # - NOTE + # - OPTIMIZE # marks code that should be optimized before merging + # - HACK # marks hack-arounds that should be removed before merging + dogsled: + # checks assignments with too many blank identifiers; default is 2 + max-blank-identifiers: 2 + + whitespace: + multi-if: false # Enforces newlines (or comments) after every multi-line if statement + multi-func: false # Enforces newlines (or comments) after every multi-line function signature + wsl: + # If true append is only allowed to be cuddled if appending value is + # matching variables, fields or types on line above. Default is true. + strict-append: true + # Allow calls and assignments to be cuddled as long as the lines have any + # matching variables, fields or types. Default is true. + allow-assign-and-call: true + # Allow multiline assignments to be cuddled. Default is true. + allow-multiline-assign: true + # Allow case blocks to end with a whitespace. + allow-case-traling-whitespace: true + # Allow declarations (var) to be cuddled. + allow-cuddle-declarations: false + +linters: + enable: + - deadcode + - errcheck + - gocritic + - gofmt + - golint + - gosec + - gosimple + - govet + - ineffassign + - megacheck + - misspell + - prealloc + - scopelint + - staticcheck + - structcheck + - typecheck + - unparam + - unused + - varcheck + disable: + # - prealloc + disable-all: false + presets: + - bugs + - unused + fast: false + + +issues: + # List of regexps of issue texts to exclude, empty list by default. + # But independently from this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. To list all + # excluded by default patterns execute `golangci-lint run --help` + exclude: + - abcdef + + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + + # Exclude known linters from partially hard-vendored code, + # which is impossible to exclude via "nolint" comments. + - path: internal/hmac/ + text: "weak cryptographic primitive" + linters: + - gosec + + # Exclude some staticcheck messages + - linters: + - staticcheck + text: "SA9003:" + + # Exclude lll issues for long lines with go:generate + - linters: + - lll + source: "^//go:generate " + + # # Independently from option `exclude` we use default exclude patterns, + # # it can be disabled by this option. To list all + # # excluded by default patterns execute `golangci-lint run --help`. + # # Default value for this option is true. + # exclude-use-default: false + + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + + # # Show only new issues: if there are unstaged changes or untracked files, + # # only those changes are analyzed, else only changes in HEAD~ are analyzed. + # # It's a super-useful option for integration of golangci-lint into existing + # # large codebase. It's not practical to fix all existing issues at the moment + # # of integration: much better don't allow issues in new code. + # # Default is false. + # new: false + + # # Show only new issues created after git revision `REV` + # new-from-rev: REV + + # # Show only new issues created in git patch with set file path. + # new-from-patch: path/to/patch/file + From 2ea60b0f2548a1541ab679aad2faf052efa53f2f Mon Sep 17 00:00:00 2001 From: maier Date: Wed, 31 Mar 2021 07:38:10 -0400 Subject: [PATCH 2/7] upd: dependencies (go-apiclient,circonusllhst) --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 1f38fac..89ea246 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/circonus-labs/circonus-gometrics/v3 go 1.14 require ( - github.com/circonus-labs/circonusllhist v0.1.5 - github.com/circonus-labs/go-apiclient v0.7.10 + github.com/circonus-labs/go-apiclient v0.7.12 github.com/hashicorp/go-retryablehttp v0.6.8 + github.com/openhistogram/circonusllhist v0.2.1 github.com/pkg/errors v0.9.1 github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c ) diff --git a/go.sum b/go.sum index 6439e8d..e274539 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ -github.com/circonus-labs/circonusllhist v0.1.5 h1:ZSFhQTeulzPZW0V8reKXXQ3a2fa4Bld2X+aLUopckSw= -github.com/circonus-labs/circonusllhist v0.1.5/go.mod h1:qYdvAhMwBRcpDX02mwOjBk0EZltij0Q7ZmzZM0BzUaY= -github.com/circonus-labs/go-apiclient v0.7.10 h1:9HdVReOvecmU15lv7jIyHLhQKRBavdfEFRSl8XJz4mM= -github.com/circonus-labs/go-apiclient v0.7.10/go.mod h1:BDt91sr9gHxvll8eVCybGIZvXAd49B6vhrICMqEim8Y= +github.com/circonus-labs/go-apiclient v0.7.12 h1:1iHRxXFOGUvu4dJNvIfI4INlIZfriykTVS2nepfJlfI= +github.com/circonus-labs/go-apiclient v0.7.12/go.mod h1:BDt91sr9gHxvll8eVCybGIZvXAd49B6vhrICMqEim8Y= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= @@ -11,6 +9,8 @@ github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrj github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs= github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= +github.com/openhistogram/circonusllhist v0.2.1 h1:x3U4T8CL+RyLq+PNqZ4g9WMCEYuZ3qlD7m+zkIQ6QYI= +github.com/openhistogram/circonusllhist v0.2.1/go.mod h1:PfeYJ/RW2+Jfv3wTz0upbY2TRour/LLqIm2K2Kw5zg0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From 5752b3fe9e710a8471c213fae01dd2533c554c21 Mon Sep 17 00:00:00 2001 From: maier Date: Wed, 31 Mar 2021 07:38:26 -0400 Subject: [PATCH 3/7] dep: Gopkg.* --- Gopkg.lock | 67 ------------------------------------------------------ Gopkg.toml | 33 --------------------------- 2 files changed, 100 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index f84e298..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,67 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:df3dc94b3fe86e95c1417202ee2fa5f63fb0903e063fff5ac81d440facb4c8cb" - name = "github.com/circonus-labs/circonusllhist" - packages = ["."] - pruneopts = "" - revision = "87d4d00b35adeefe4911ece727838749e0fab113" - version = "v0.1.3" - -[[projects]] - digest = "1:d6643f70ce124da435062a081e4997d65a282ccac0ff484020226a7bb1627fb5" - name = "github.com/circonus-labs/go-apiclient" - packages = [ - ".", - "config", - ] - pruneopts = "" - revision = "e8c5a730387fbfd1b87b41fd00acc6ca46493704" - version = "v0.5.3" - -[[projects]] - digest = "1:05334858a0cfb538622a066e065287f63f42bee26a7fda93a789674225057201" - name = "github.com/hashicorp/go-cleanhttp" - packages = ["."] - pruneopts = "" - revision = "e8ab9daed8d1ddd2d3c4efba338fe2eeae2e4f18" - version = "v0.5.0" - -[[projects]] - digest = "1:62327a30877f944b5fd23d130487731a3004b319ff1864daa677d7e554898cc1" - name = "github.com/hashicorp/go-retryablehttp" - packages = ["."] - pruneopts = "" - revision = "4502c0ecdaf0b50d857611af23831260f99be6bf" - version = "v0.5.0" - -[[projects]] - digest = "1:7365acd48986e205ccb8652cc746f09c8b7876030d53710ea6ef7d0bd0dcd7ca" - name = "github.com/pkg/errors" - packages = ["."] - pruneopts = "" - revision = "645ef00459ed84a119197bfb8d8205042c6df63d" - version = "v0.8.0" - -[[projects]] - branch = "master" - digest = "1:eac3ff8988045e7700540ce20abeb0f7e858bed9f1914e24bb85d74e41670c6c" - name = "github.com/tv42/httpunix" - packages = ["."] - pruneopts = "" - revision = "b75d8614f926c077e48d85f1f8f7885b758c6225" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/circonus-labs/circonusllhist", - "github.com/circonus-labs/go-apiclient", - "github.com/circonus-labs/go-apiclient/config", - "github.com/hashicorp/go-retryablehttp", - "github.com/pkg/errors", - "github.com/tv42/httpunix", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index e9dc475..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,33 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - version = "0.5.0" - name = "github.com/hashicorp/go-retryablehttp" - -[[constraint]] - name = "github.com/pkg/errors" - version = "0.8.0" - -[[constraint]] - branch = "master" - name = "github.com/tv42/httpunix" From 0bffea9bf4d28a4425282ae765431743be069876 Mon Sep 17 00:00:00 2001 From: maier Date: Wed, 31 Mar 2021 07:38:55 -0400 Subject: [PATCH 4/7] fix: lint issues --- checkmgr/check.go | 2 +- checkmgr/check_test.go | 4 +-- checkmgr/checkmgr_test.go | 6 ++-- circonus-gometrics.go | 69 +++++++++++++++++---------------------- histogram.go | 4 +-- metric_output.go | 2 +- submit.go | 10 +++--- tags.go | 2 +- tags_test.go | 2 +- 9 files changed, 47 insertions(+), 54 deletions(-) diff --git a/checkmgr/check.go b/checkmgr/check.go index b8a51b3..47e9abc 100644 --- a/checkmgr/check.go +++ b/checkmgr/check.go @@ -134,7 +134,7 @@ func (cm *CheckManager) initializeTrapURL() error { // unless the new submission url can be fetched with the API (which is no // longer possible using the original submission url) var id int - id, err = strconv.Atoi(strings.Replace(check.CID, "/check/", "", -1)) + id, err = strconv.Atoi(strings.ReplaceAll(check.CID, "/check/", "")) if err == nil { cm.checkID = apiclient.IDType(id) cm.checkSubmissionURL = "" diff --git a/checkmgr/check_test.go b/checkmgr/check_test.go index ac05044..0303d9d 100644 --- a/checkmgr/check_test.go +++ b/checkmgr/check_test.go @@ -114,7 +114,7 @@ func testCheckServer() *httptest.Server { case "/check_bundle": switch r.Method { case "GET": // search - //fmt.Println(r.URL.String()) + // fmt.Println(r.URL.String()) switch { case strings.HasPrefix(r.URL.String(), "/check_bundle?f_notes=") && strings.Contains(r.URL.String(), "found_notes"): r := []apiclient.CheckBundle{testCheckBundle} @@ -147,7 +147,7 @@ func testCheckServer() *httptest.Server { } var bundle apiclient.CheckBundle - if err := json.Unmarshal(cfg, &bundle); err != nil { + if err = json.Unmarshal(cfg, &bundle); err != nil { panic(err) } bundle.CID = testCheckBundle.CID diff --git a/checkmgr/checkmgr_test.go b/checkmgr/checkmgr_test.go index 65c2f5b..22b6e1b 100644 --- a/checkmgr/checkmgr_test.go +++ b/checkmgr/checkmgr_test.go @@ -151,7 +151,7 @@ func testCMServer() *httptest.Server { } var bundle apiclient.CheckBundle - if err := json.Unmarshal(cfg, &bundle); err != nil { + if err = json.Unmarshal(cfg, &bundle); err != nil { panic(err) } bundle.CID = testCheckBundle.CID @@ -415,9 +415,11 @@ func TestNewCheckManager(t *testing.T) { // quick request to make sure the trap.TLS is the one passed and not the default client := &http.Client{Transport: &http.Transport{TLSClientConfig: trap.TLS}} - if _, err := client.Get(trap.URL.String()); err != nil { + resp, err := client.Get(trap.URL.String()) //nolint:noctx + if err != nil { t.Fatalf("expected no error, got (%s)", err) } + resp.Body.Close() t.Log("test ResetTrap") { diff --git a/circonus-gometrics.go b/circonus-gometrics.go index 0d2cfdc..8997fdb 100644 --- a/circonus-gometrics.go +++ b/circonus-gometrics.go @@ -93,8 +93,8 @@ type Logger interface { // Metric defines an individual metric type Metric struct { - Type string `json:"_type"` Value interface{} `json:"_value"` + Type string `json:"_type"` Timestamp uint64 `json:"_ts,omitempty"` } @@ -104,65 +104,56 @@ type Metrics map[string]Metric // Config options for circonus-gometrics type Config struct { Log Logger - Debug bool ResetCounters string // reset/delete counters on flush (default true) ResetGauges string // reset/delete gauges on flush (default true) ResetHistograms string // reset/delete histograms on flush (default true) ResetText string // reset/delete text on flush (default true) + // how frequenly to submit metrics to Circonus, default 10 seconds. + // Set to 0 to disable automatic flushes and call Flush manually. + Interval string // API, Check and Broker configuration options CheckManager checkmgr.Config - // how frequenly to submit metrics to Circonus, default 10 seconds. - // Set to 0 to disable automatic flushes and call Flush manually. - Interval string + Debug bool } type prevMetrics struct { metrics *Metrics - metricsmu sync.Mutex ts time.Time + metricsmu sync.Mutex } // CirconusMetrics state type CirconusMetrics struct { - Log Logger - Debug bool - + Log Logger + lastMetrics *prevMetrics + check *checkmgr.CheckManager + gauges map[string]interface{} + histograms map[string]*Histogram + custom map[string]Metric + text map[string]string + textFuncs map[string]func() string + counterFuncs map[string]func() uint64 + gaugeFuncs map[string]func() int64 + counters map[string]uint64 + flushInterval time.Duration + flushmu sync.Mutex + packagingmu sync.Mutex + cm sync.Mutex + cfm sync.Mutex + gm sync.Mutex + gfm sync.Mutex + hm sync.Mutex + tm sync.Mutex + tfm sync.Mutex + custm sync.Mutex + flushing bool + Debug bool resetCounters bool resetGauges bool resetHistograms bool resetText bool - flushInterval time.Duration - flushing bool - flushmu sync.Mutex - packagingmu sync.Mutex - check *checkmgr.CheckManager - lastMetrics *prevMetrics - - counters map[string]uint64 - cm sync.Mutex - - counterFuncs map[string]func() uint64 - cfm sync.Mutex - - gauges map[string]interface{} - gm sync.Mutex - - gaugeFuncs map[string]func() int64 - gfm sync.Mutex - - histograms map[string]*Histogram - hm sync.Mutex - - text map[string]string - tm sync.Mutex - - textFuncs map[string]func() string - tfm sync.Mutex - - custom map[string]Metric - custm sync.Mutex } // NewCirconusMetrics returns a CirconusMetrics instance diff --git a/histogram.go b/histogram.go index ba6c69e..fc24788 100644 --- a/histogram.go +++ b/histogram.go @@ -8,14 +8,14 @@ import ( "sync" "time" - "github.com/circonus-labs/circonusllhist" + "github.com/openhistogram/circonusllhist" "github.com/pkg/errors" ) // Histogram measures the distribution of a stream of values. type Histogram struct { - name string hist *circonusllhist.Histogram + name string rw sync.RWMutex } diff --git a/metric_output.go b/metric_output.go index 48e8e59..bd565d0 100644 --- a/metric_output.go +++ b/metric_output.go @@ -12,8 +12,8 @@ import ( "sync" "time" - "github.com/circonus-labs/circonusllhist" "github.com/circonus-labs/go-apiclient" + "github.com/openhistogram/circonusllhist" "github.com/pkg/errors" ) diff --git a/submit.go b/submit.go index 6715c86..a874a54 100644 --- a/submit.go +++ b/submit.go @@ -88,7 +88,7 @@ func (m *CirconusMetrics) trapCall(payload []byte) (int, error) { if resp.StatusCode == 0 || resp.StatusCode >= 500 { body, readErr := ioutil.ReadAll(resp.Body) if readErr != nil { - lastHTTPError = fmt.Errorf("- last HTTP error: %d %+v", resp.StatusCode, readErr) + lastHTTPError = fmt.Errorf("- last HTTP error: %d %w", resp.StatusCode, readErr) } else { lastHTTPError = fmt.Errorf("- last HTTP error: %d %s", resp.StatusCode, string(body)) } @@ -149,14 +149,14 @@ func (m *CirconusMetrics) trapCall(payload []byte) (int, error) { resp, err := client.Do(req) if err != nil { if lastHTTPError != nil { - return 0, fmt.Errorf("submitting: %+v %+v", err, lastHTTPError) + return 0, fmt.Errorf("submitting: %w previous: %s", err, lastHTTPError) } if attempts == client.RetryMax { - if err := m.check.RefreshTrap(); err != nil { - return 0, errors.Wrap(err, "refreshing trap") + if err = m.check.RefreshTrap(); err != nil { + return 0, fmt.Errorf("refreshing trap: %w", err) } } - return 0, errors.Wrap(err, "trap call") + return 0, fmt.Errorf("trap call: %w", err) } defer resp.Body.Close() diff --git a/tags.go b/tags.go index fb8ce9c..55af502 100644 --- a/tags.go +++ b/tags.go @@ -96,7 +96,7 @@ func (m *CirconusMetrics) EncodeMetricStreamTags(metricName string, tags Tags) s // EncodeMetricTags encodes Tags into an array of strings. The format // check_bundle.metircs.metric.tags needs. This helper is intended to work // with legacy check bundle metrics. Tags directly on named metrics are being -// deprecated in favor of stream tags. +// removed in favor of stream tags. func (m *CirconusMetrics) EncodeMetricTags(metricName string, tags Tags) []string { if len(tags) == 0 { return []string{} diff --git a/tags_test.go b/tags_test.go index 897ece5..e6b3195 100644 --- a/tags_test.go +++ b/tags_test.go @@ -84,7 +84,7 @@ func TestEncodeMetricStreamTags(t *testing.T) { result[name] = matches[i] } } - if cat, found := result["cat"]; !found { + if cat, found := result["cat"]; !found { //nolint:gocritic t.Fatalf("category: named match not found '%s'", cat) } else if cat == "" { t.Fatalf("category: invalid (empty) '%s'", cat) From b2f91d18c02191424e7a88c172032de4acc16121 Mon Sep 17 00:00:00 2001 From: maier Date: Wed, 31 Mar 2021 07:39:10 -0400 Subject: [PATCH 5/7] fix: lint issues fix: service tag file path --- checkmgr/checkmgr.go | 116 ++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 63 deletions(-) diff --git a/checkmgr/checkmgr.go b/checkmgr/checkmgr.go index f880aa1..5a6aedd 100644 --- a/checkmgr/checkmgr.go +++ b/checkmgr/checkmgr.go @@ -13,7 +13,7 @@ import ( "log" "net/url" "os" - "path" + "path/filepath" "regexp" "strconv" "strings" @@ -97,24 +97,26 @@ type CheckConfig struct { // in the UI) **only relevant when check management is enabled** // e.g. 5m, 30m, 1h, etc. MaxURLAge string + // Type of check to use (default: httptrap) + Type string // force metric activation - if a metric has been disabled via the UI // the default behavior is to *not* re-activate the metric; this setting // overrides the behavior and will re-activate the metric when it is // encountered. "(true|false)", default "false" // NOTE: ONLY applies to checks without metric_filters ForceMetricActivation string + // Custom check config fields (default: none) + CustomConfigFields map[string]string // MetricFilters list of regular expression filters defining what metrics // will be automatically enabled. These are evaluated in order and the first // match stops evaluation. Default []MetricFilter{{"deny","^$",""},{"allow","^.+$",""}} MetricFilters []MetricFilter - // Type of check to use (default: httptrap) - Type string - // Custom check config fields (default: none) - CustomConfigFields map[string]string } // BrokerConfig options for broker type BrokerConfig struct { + // TLS configuration to use when communicating within broker + TLSConfig *tls.Config // a specific broker id (numeric portion of cid) ID string // one or more tags used to select 1-n brokers from which to select @@ -123,21 +125,18 @@ type BrokerConfig struct { // for a broker to be considered viable it must respond to a // connection attempt within this amount of time e.g. 200ms, 2s, 1m MaxResponseTime string - // TLS configuration to use when communicating within broker - TLSConfig *tls.Config } // Config options type Config struct { - Log Logger - Debug bool - + Log Logger // Circonus API config API apiclient.Config - // Check specific configuration options - Check CheckConfig // Broker specific configuration options Broker BrokerConfig + // Check specific configuration options + Check CheckConfig + Debug bool } // CheckTypeType check type @@ -163,60 +162,51 @@ type BrokerCNType string // CheckManager settings type CheckManager struct { - enabled bool - manageMetrics bool - Log Logger - Debug bool - apih *apiclient.API - - initialized bool - initializedmu sync.RWMutex - - // check - checkType CheckTypeType - checkID apiclient.IDType - checkInstanceID CheckInstanceIDType - checkTarget CheckTargetType - checkSearchTag apiclient.TagType - checkSecret CheckSecretType - checkTags apiclient.TagType - checkMetricFilters []MetricFilter - customConfigFields map[string]string - checkSubmissionURL apiclient.URLType - checkDisplayName CheckDisplayNameType - forceMetricActivation bool - forceCheckUpdate bool - - // metric tags - metricTags map[string][]string - mtmu sync.Mutex - - // broker - brokerID apiclient.IDType - brokerSelectTag apiclient.TagType - brokerMaxResponseTime time.Duration - brokerTLS *tls.Config - - // state - checkBundle *apiclient.CheckBundle - cbmu sync.Mutex - availableMetrics map[string]bool - availableMetricsmu sync.Mutex - trapURL apiclient.URLType - trapCN BrokerCNType - trapLastUpdate time.Time - trapMaxURLAge time.Duration - trapmu sync.Mutex - certPool *x509.CertPool - sockRx *regexp.Regexp + metricTags map[string][]string // metric tags + customConfigFields map[string]string // check + availableMetrics map[string]bool // state + apih *apiclient.API // general + checkBundle *apiclient.CheckBundle // state + brokerTLS *tls.Config // broker + certPool *x509.CertPool // state + sockRx *regexp.Regexp // state + Log Logger // general + trapLastUpdate time.Time // state + checkType CheckTypeType // check + checkInstanceID CheckInstanceIDType // check + checkTarget CheckTargetType // check + checkSecret CheckSecretType // check + checkSubmissionURL apiclient.URLType // check + checkDisplayName CheckDisplayNameType // check + trapURL apiclient.URLType // state + trapCN BrokerCNType // state + checkMetricFilters []MetricFilter // check + checkTags apiclient.TagType // check + brokerSelectTag apiclient.TagType // broker + checkSearchTag apiclient.TagType // check + brokerMaxResponseTime time.Duration // broker + trapMaxURLAge time.Duration // state + brokerID apiclient.IDType // broker + checkID apiclient.IDType // check + initializedmu sync.RWMutex // general + cbmu sync.Mutex // state + trapmu sync.Mutex // state + mtmu sync.Mutex // metric tags + availableMetricsmu sync.Mutex // state + enabled bool // general + manageMetrics bool // general + Debug bool // general + initialized bool // general + forceMetricActivation bool // check + forceCheckUpdate bool // check } // Trap config type Trap struct { URL *url.URL TLS *tls.Config - IsSocket bool SockTransport *httpunix.Transport + IsSocket bool } // NewCheckManager returns a new check manager @@ -304,7 +294,7 @@ func New(cfg *Config) (*CheckManager, error) { } cm.forceMetricActivation = fm - _, an := path.Split(os.Args[0]) + _, an := filepath.Split(os.Args[0]) hn, err := os.Hostname() if err != nil { hn = "unknown" @@ -322,11 +312,11 @@ func New(cfg *Config) (*CheckManager, error) { if cfg.Check.SearchTag == "" { cm.checkSearchTag = []string{fmt.Sprintf("service:%s", an)} } else { - cm.checkSearchTag = strings.Split(strings.Replace(cfg.Check.SearchTag, " ", "", -1), ",") + cm.checkSearchTag = strings.Split(strings.ReplaceAll(cfg.Check.SearchTag, " ", ""), ",") } if cfg.Check.Tags != "" { - cm.checkTags = strings.Split(strings.Replace(cfg.Check.Tags, " ", "", -1), ",") + cm.checkTags = strings.Split(strings.ReplaceAll(cfg.Check.Tags, " ", ""), ",") } if len(cfg.Check.MetricFilters) > 0 { @@ -362,7 +352,7 @@ func New(cfg *Config) (*CheckManager, error) { cm.brokerID = apiclient.IDType(id) if cfg.Broker.SelectTag != "" { - cm.brokerSelectTag = strings.Split(strings.Replace(cfg.Broker.SelectTag, " ", "", -1), ",") + cm.brokerSelectTag = strings.Split(strings.ReplaceAll(cfg.Broker.SelectTag, " ", ""), ",") } dur = cfg.Broker.MaxResponseTime From 44e298df3d5acbb51bb617dcdaa6d8939fb744fd Mon Sep 17 00:00:00 2001 From: maier Date: Wed, 31 Mar 2021 07:59:57 -0400 Subject: [PATCH 6/7] v3.4.0 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c634d90..570a124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v3.4.0 + +* fix: service tag file path +* fix: lint issues +* add: lint workflow +* upd: dependencies (go-apiclient,circonusllhst) + # v3.3.4 * upd: dependencies (cgm,circonusllhst,retryablehttp) From caaf570bb12c017e53ccc59035f902f63642a846 Mon Sep 17 00:00:00 2001 From: maier Date: Wed, 31 Mar 2021 08:13:06 -0400 Subject: [PATCH 7/7] upd: dependencies (go-apiclient) --- go.mod | 2 +- go.sum | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 89ea246..b1339d9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/circonus-labs/circonus-gometrics/v3 go 1.14 require ( - github.com/circonus-labs/go-apiclient v0.7.12 + github.com/circonus-labs/go-apiclient v0.7.13 github.com/hashicorp/go-retryablehttp v0.6.8 github.com/openhistogram/circonusllhist v0.2.1 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index e274539..39d355f 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,11 @@ -github.com/circonus-labs/go-apiclient v0.7.12 h1:1iHRxXFOGUvu4dJNvIfI4INlIZfriykTVS2nepfJlfI= -github.com/circonus-labs/go-apiclient v0.7.12/go.mod h1:BDt91sr9gHxvll8eVCybGIZvXAd49B6vhrICMqEim8Y= +github.com/circonus-labs/go-apiclient v0.7.13 h1:jiZw0DXsP06WxPFvmFNpcYFfQxC0GiYIVzC78lbCVXw= +github.com/circonus-labs/go-apiclient v0.7.13/go.mod h1:RFgkvdYEkimzgu3V2vVYlS1bitjOz1SF6uw109ieNeY= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs= github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/openhistogram/circonusllhist v0.2.1 h1:x3U4T8CL+RyLq+PNqZ4g9WMCEYuZ3qlD7m+zkIQ6QYI=