Skip to content

Commit

Permalink
all: appease the linter
Browse files Browse the repository at this point in the history
Turn off the thing where the tests can pass even though lint fails
- it's as good as not running the linter at all.

The "stats" name import next to "github.com/segmentio/stats/v5" is not
necessary but was prompted by golangci-lint at one point.
  • Loading branch information
kevinburkesegment committed Dec 12, 2024
1 parent f0bbab5 commit f81e32d
Show file tree
Hide file tree
Showing 44 changed files with 92 additions and 56 deletions.
1 change: 0 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
lint:
name: lint
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/setup-go@v5
with:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Monitoring

> 🚧 Go metrics reported with the `procstats` package were previously tagged with a
> `version` label that reported the Go runtime version. This label was renamed to
> `go_version` in v5.6.0.
> `go_version` in v4.6.0.
The
[github.com/segmentio/stats/procstats](https://godoc.org/github.com/segmentio/stats/procstats)
Expand Down Expand Up @@ -389,11 +389,11 @@ func main() {
### Addendum

By default, the stats library will report the running go version when you
invoke NewEngine() as three metrics:
invoke NewEngine() as a metric:

- `go_version.major`
- `go_version.minor`
- `go_version.patch`
- `go_version` with value 1 and a `tag` set to the current version.
- `stats_version` with value ` and a `tag` set to the tag value of
segmentio/stats.

Set `STATS_DISABLE_GO_VERSION_REPORTING` to `true` in your environment, or set
`stats.GoVersionReportingEnabled` to `false` before collecting any metrics, to
Expand Down
2 changes: 1 addition & 1 deletion cmd/dogstatsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
"github.com/segmentio/stats/v5/datadog"
)

Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// ContextWithTags returns a new child context with the given tags. If the
// parent context already has tags set on it, they are _not_ propegated into
// parent context already has tags set on it, they are _not_ propagated into
// the context children.
func ContextWithTags(ctx context.Context, tags ...Tag) context.Context {
// initialize the context reference and return a new context
Expand Down
2 changes: 1 addition & 1 deletion datadog/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strconv"
"strings"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

func appendMetric(b []byte, m Metric) []byte {
Expand Down
2 changes: 1 addition & 1 deletion datadog/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"

"golang.org/x/sys/unix"
)
Expand Down
2 changes: 1 addition & 1 deletion datadog/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"

"github.com/stretchr/testify/assert"
)
Expand Down
2 changes: 1 addition & 1 deletion datadog/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package datadog
import (
"fmt"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// EventPriority is an enumeration providing the available datadog event
Expand Down
2 changes: 1 addition & 1 deletion datadog/event_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package datadog

import (
"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

var testEvents = []struct {
Expand Down
2 changes: 1 addition & 1 deletion datadog/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"sync"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// MetricType is an enumeration providing symbols to represent the different
Expand Down
2 changes: 1 addition & 1 deletion datadog/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package datadog
import (
"testing"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

var testMetrics = []struct {
Expand Down
2 changes: 1 addition & 1 deletion datadog/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"strings"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// Adapted from https://github.com/DataDog/datadog-agent/blob/6789e98a1e41e98700fa1783df62238bb23cb454/pkg/dogstatsd/parser.go#L141
Expand Down
2 changes: 1 addition & 1 deletion datadog/serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// Datagram format: https://docs.datadoghq.com/developers/dogstatsd/datagram_shell
Expand Down
2 changes: 1 addition & 1 deletion datadog/serializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

var testMeasures = []struct {
Expand Down
2 changes: 1 addition & 1 deletion datadog/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

func TestServer(t *testing.T) {
Expand Down
28 changes: 25 additions & 3 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"sync"
"time"

"github.com/segmentio/stats/v5/version"
)

// An Engine carries the context for producing metrics. It is configured by
Expand Down Expand Up @@ -168,10 +170,30 @@ func (eng *Engine) measure(t time.Time, name string, value interface{}, ftype Fi
vsn := strings.TrimPrefix(runtime.Version(), "go")
fmt.Println("vsn", vsn)
parts := strings.Split(vsn, ".")
// this filters out weird compiled Go versions like tip.
// older Go version might be "go1.13"
// this filters out weird compiled Go versions like tip. len(parts)
// may equal 2 because older Go version might be "go1.13"
if len(parts) == 2 || len(parts) == 3 {
eng.measureOne(t, "go_version", 1, Gauge, []Tag{{"go_version", vsn}}...)
eng.Handler.HandleMeasures(t, Measure{
Name: "go_version",
Fields: []Field{{
Name: "go_version",
Value: intValue(1),
}},
Tags: []Tag{
{"go_version", vsn},
},
},
Measure{
Name: "stats_version",
Fields: []Field{{
Name: "stats_version",
Value: intValue(1),
}},
Tags: []Tag{
{"stats_version", version.Version},
},
},
)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
"github.com/segmentio/stats/v5/datadog"
"github.com/segmentio/stats/v5/influxdb"
"github.com/segmentio/stats/v5/prometheus"
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/segmentio/stats/v5

go 1.22.0

toolchain go1.23.1

require (
github.com/mdlayher/taskstats v0.0.0-20190313225729-7cbba52ee072
github.com/segmentio/fasthash v1.0.3
Expand Down
2 changes: 1 addition & 1 deletion handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
"github.com/segmentio/stats/v5/statstest"

"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion httpstats/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package httpstats
import (
"net/http"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// RequestWithTags returns a shallow copy of req with its context updated to
Expand Down
8 changes: 4 additions & 4 deletions httpstats/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
stats "github.com/segmentio/stats/v5"

"github.com/segmentio/stats/v5"
"github.com/stretchr/testify/assert"
)

// TestRequestContextTagPropegation verifies that the root ancestor tags are
// TestRequestContextTagPropagation verifies that the root ancestor tags are
// updated in the event the context or request has children. It's nearly
// identical to the context_test in the stats package itself, but we want to
// keep this to ensure that changes to the request context code doesn't drift
// and cause bugs.
func TestRequestContextTagPropegation(t *testing.T) {
func TestRequestContextTagPropagation(t *testing.T) {
// dummy request
x := httptest.NewRequest(http.MethodGet, "http://example.com/blah", nil)

Expand Down
2 changes: 1 addition & 1 deletion httpstats/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// NewHandler wraps h to produce metrics on the default engine for every request
Expand Down
2 changes: 1 addition & 1 deletion httpstats/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
"github.com/segmentio/stats/v5/statstest"
)

Expand Down
2 changes: 1 addition & 1 deletion httpstats/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion httpstats/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// NewTransport wraps t to produce metrics on the default engine for every request
Expand Down
2 changes: 1 addition & 1 deletion httpstats/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
"github.com/segmentio/stats/v5/statstest"
)

Expand Down
2 changes: 1 addition & 1 deletion influxdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/segmentio/objconv/json"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion influxdb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

func DisabledTestClient(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion influxdb/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strconv"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// AppendMeasure is a formatting routine to append the InflxDB line protocol
Expand Down
2 changes: 1 addition & 1 deletion influxdb/measure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@ func (c *measureCache) load() *map[reflect.Type][]measureFuncs {
return (*map[reflect.Type][]measureFuncs)(atomic.LoadPointer(&c.cache))
}

func (c *measureCache) compareAndSwap(old, new *map[reflect.Type][]measureFuncs) bool {
func (c *measureCache) compareAndSwap(old, newPtr *map[reflect.Type][]measureFuncs) bool {
return atomic.CompareAndSwapPointer(&c.cache,
unsafe.Pointer(old),
unsafe.Pointer(new),
unsafe.Pointer(newPtr),
)
}
2 changes: 1 addition & 1 deletion netstats/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/segmentio/vpcinfo"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion netstats/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
"github.com/segmentio/stats/v5/statstest"
)

Expand Down
2 changes: 1 addition & 1 deletion netstats/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"net"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// Handler is an interface that can be implemented by types that serve network
Expand Down
2 changes: 1 addition & 1 deletion netstats/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net"
"sync/atomic"

"github.com/segmentio/stats/v5"
stats "github.com/segmentio/stats/v5"
)

// NewListener returns a new net.Listener which uses the stats.DefaultEngine.
Expand Down
Loading

0 comments on commit f81e32d

Please sign in to comment.