Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mx51 feature/uds support #167

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
275fcb1
initial draft for uds support
sebcante Sep 14, 2020
54c9f6e
initial draft for uds support
sebcante Sep 14, 2020
91731bf
review pr
sebcante Sep 14, 2020
8a1ca58
review pr
sebcante Sep 14, 2020
969fe44
more docs
sebcante Sep 14, 2020
46084cb
fixes #124
Jan 4, 2021
b2bb979
tagsBuffer: Sort only if needed
tysonmote Feb 9, 2021
dee5f71
Largely cleanup for fmt and linter warnings. (#127)
Feb 11, 2021
fc52212
add comment about Clock duration unit reported to datadog
Mar 5, 2021
367a46f
Fix use of reflect.StringHeader in prometheus/metric.go (#133)
bhavanki Aug 12, 2021
55927e9
Support Datadog distribution metric type (#132)
bhavanki Aug 12, 2021
f2f0b58
Add github workflow
Pryz Apr 29, 2022
66247c7
Disabling influxdb client test
Pryz Apr 29, 2022
abba0e8
Add golangci
Pryz Apr 30, 2022
a914c9c
rename
Pryz Apr 30, 2022
6d406e4
don't run golangci-lint against all PR yet
Pryz Apr 30, 2022
d64705c
main -> master
Pryz Apr 30, 2022
e43ec51
Add an OpenTelemetry handler
Pryz Apr 29, 2022
a3d6e3b
Review feedback
Pryz Apr 29, 2022
036a33f
update doc
Pryz May 2, 2022
1b4a516
add user-agent
Pryz May 2, 2022
7333338
feedback 2
Pryz May 2, 2022
f485775
add disclaimer
Pryz May 3, 2022
088dc63
Add stretcher/testify
boggsboggs Sep 14, 2022
dbfafe5
Add FilteredHandler
boggsboggs Sep 14, 2022
5ddd175
Refactor AppendMeasureFiltered into a serializer method named AppendM…
boggsboggs Sep 14, 2022
d504d6d
Move serializer from client.go into measure.go and reorder functions;…
boggsboggs Sep 14, 2022
7abc8ce
Rename measure.go -> serializer.go
boggsboggs Sep 14, 2022
6b680ea
Add UseDistibutions to datadog client config
boggsboggs Sep 14, 2022
9c4efeb
Apply comment change suggestions from code review
boggsboggs Oct 13, 2022
a2609ef
Code review comment changes
boggsboggs Oct 13, 2022
67beb8d
Remove filteredHandler len == 0 short circuit
boggsboggs Oct 13, 2022
c5616a4
Create dedicated go module for otlp exporter
Pryz Nov 15, 2022
fc2a57d
resolve conflicts
Pryz Nov 15, 2022
7f9502b
procstats/linux: finish function renames
extemporalgenome Jul 16, 2023
a1383f2
update github workflows to supported Go versions
extemporalgenome Jul 15, 2023
d5cea37
fix dependabot issues
extemporalgenome Jul 16, 2023
dfabf88
tag.go: conventional test naming.
extemporalgenome Jul 15, 2023
cce81da
tag.go: use slices package Sort functionality
extemporalgenome Jul 15, 2023
3d9144a
SortTags deduplicates, uses slices.SortStable
extemporalgenome Jul 15, 2023
14da84f
tag.go: improve doc comments regarding tag name duplicates.
extemporalgenome Jul 18, 2023
8a613b0
switch all main-ish branch references to be literally main
extemporalgenome Jul 18, 2023
30ac2fb
.golangci.yml: disable broken linter
extemporalgenome Jul 18, 2023
9d6801f
golangci-lint run --fix
extemporalgenome Jul 18, 2023
60825ce
hand-fix some linting issues
extemporalgenome Jul 18, 2023
ec5f791
just use errgroup instead of reinventing an errgroup
extemporalgenome Jul 18, 2023
08addf6
Update context.go
extemporalgenome Jul 19, 2023
ee51337
syscall.Sysinfo returns an uint32 on linux/arm, but uint64 otherwise
noctarius Aug 14, 2023
71ef609
README.md: spacing fixes
extemporalgenome Sep 28, 2023
e965d2b
fix: update the x/exp package, and updated tagIsLess function (#152)
needcaffeine Sep 28, 2023
0154449
update testify to v1.8.1 to fix snyk issue (#142)
erikdw Sep 28, 2023
b1acd0a
Update to latest fasthash dep (#130)
deankarn Sep 28, 2023
ee98293
Remove CircleCI pipeline yaml (#140)
wdbetts Sep 28, 2023
3a61252
tag: fix build
kevinburkesegment Dec 6, 2023
b577f9f
procstats/linux: skip tests if /sys not available
kevinburkesegment Dec 7, 2023
58d0f83
.github: update CI runner
kevinburkesegment Jun 19, 2024
a16086e
procstats: fix tests on Macs
kevinburkesegment Jun 19, 2024
3bdf434
datadog: fix race in test
kevinburkesegment Jun 19, 2024
b1c6825
.github: ensure golangci-lint runs on PR's as well
kevinburkesegment Jun 21, 2024
8c593af
all: fix lint issues
kevinburkesegment Jun 21, 2024
ce6ec28
go.mod: update dependabot
kevinburkesegment Jun 21, 2024
c696754
docker-compose.yml: specify AMD64 platform (#166)
kevinburkesegment Jul 16, 2024
0f4933a
engine: add AllowDuplicates flag that skips tag duplicate removal log…
sungjujin Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .circleci/config.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Test
"on":
- pull_request

jobs:
test:
strategy:
matrix:
go:
- 'oldstable'
- 'stable'
label:
- [self-hosted, linux, arm64, segment]
- ubuntu-latest

runs-on: ${{ matrix.label }}

steps:
- uses: actions/checkout@v4

- name: Setup Go (${{ matrix.go }})
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Identify OS
run: uname -a

- name: Identify Go Version
run: go version

- name: Download Dependencies
run: go mod download

- name: Run Tests
run: go test -race -tags=${{ matrix.tags }} ./...
32 changes: 32 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: golangci-lint
"on":
push:
tags:
- v*
branches: [main]
paths:
- '**.go'
- .golangci.yml
- .github/workflows/golangci-lint.yml
pull_request:
branches:
- main


jobs:
lint:
name: lint
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/setup-go@v5
with:
go-version: '>=1.20'

- uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/golangci-lint-action@v6.0.1
with:
version: v1.59.1
38 changes: 38 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
run:
deadline: 5m

output:
sort-results: true

linters:
disable:
- depguard # this linter is broken in golangci-lint as of 2023-07-18.

enable:
- godot
- gofumpt
- goimports
- revive
- whitespace
- misspell

issues:
exclude-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
exclude-rules:
- path: _test.go
linters:
- errcheck

linters-settings:
depguard:
list-type: blacklist
include-go-root: true
packages-with-error-message: []
goimports:
local-prefixes: github.com/segmentio/stats
gofumpt:
extra-rules: true
misspell:
locale: US
28 changes: 28 additions & 0 deletions .otel/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
receivers:
otlp:
protocols:
grpc:
http:
endpoint: 0.0.0.0:4318

processors:
batch:

exporters:
logging:
logLevel: debug

prometheus:
endpoint: "0.0.0.0:4319"

service:
telemetry:
logs:
level: "debug"

pipelines:
metrics:
receivers: [otlp]
processors: []
exporters: [logging, prometheus]

9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Installation
------------

```
go get github.com/segmentio/stats
go get github.com/segmentio/stats/v4
```

Migration to v4
Expand All @@ -30,7 +30,7 @@ type funcMetrics struct {
```go
t := time.Now()
f()
callTime := time.Now().Sub(t)
callTime := time.Since(t)

m := &funcMetrics{}
m.calls.count = 1
Expand Down Expand Up @@ -192,6 +192,7 @@ Statistics are collected for the current process and metrics including Goroutine
count and memory usage are reported.

Here's an example of how to use the collector:

```go
package main

Expand Down Expand Up @@ -237,6 +238,7 @@ collection to a HTTP handler, reporting things like request processing time,
error counters, header and body sizes...

Here's an example of how to use the decorator:

```go
package main

Expand Down Expand Up @@ -270,6 +272,7 @@ package exposes a decorator of `http.RoundTripper` which collects and reports
metrics for client requests the same way it's done on the server side.

Here's an example of how to use the decorator:

```go
package main

Expand Down Expand Up @@ -298,6 +301,7 @@ func main() {

You can also modify the default HTTP client to automatically get metrics for all
packages using it, this is very convinient to get insights into dependencies.

```go
package main

Expand Down Expand Up @@ -332,6 +336,7 @@ package exposes:
which collects metrics for server requests.

Here's an example of how to use the decorator on the client side:

```go
package main

Expand Down
2 changes: 1 addition & 1 deletion buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func makeKey(s string) Key {
return Key{Measure: measure, Field: field}
}

func splitMeasureField(s string) (measure string, field string) {
func splitMeasureField(s string) (measure, field string) {
if i := strings.LastIndexByte(s, '.'); i >= 0 {
measure, field = s[:i], s[i+1:]
} else {
Expand Down
8 changes: 2 additions & 6 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type Serializer interface {
type buffer struct {
lock uint64
data []byte
pad [32]byte // padding to avoid false sharing between threads
_ [32]byte // padding to avoid false sharing between threads
}

func (b *buffer) acquire() bool {
Expand All @@ -155,12 +155,8 @@ func (b *buffer) len() int {
return len(b.data)
}

func (b *buffer) cap() int {
return cap(b.data)
}

func (b *buffer) flush(w io.Writer, n int) {
w.Write(b.data[:n])
_, _ = w.Write(b.data[:n])
n = copy(b.data, b.data[n:])
b.data = b.data[:n]
}
2 changes: 2 additions & 0 deletions clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "time"
//
// Clocks are useful to measure the duration taken by sequential execution steps
// and therefore aren't safe to be used concurrently by multiple goroutines.
//
// Note: Clock times are reported to datadog in seconds. See `stats/datadog/measure.go`.
type Clock struct {
name string
first time.Time
Expand Down
22 changes: 9 additions & 13 deletions cmd/dogstatsd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ commands:
}

func client(cmd string, args ...string) {
var fset = flag.NewFlagSet("dogstatsd "+cmd+" [options...] metric value [-- args...]", flag.ExitOnError)
fset := flag.NewFlagSet("dogstatsd "+cmd+" [options...] metric value [-- args...]", flag.ExitOnError)
var extra []string
var tags tags
var addr string
Expand All @@ -59,7 +59,7 @@ func client(cmd string, args ...string) {
args, extra = split(args, "--")
fset.StringVar(&addr, "addr", "localhost:8125", "The network address where a dogstatsd server is listening for incoming UDP datagrams")
fset.Var(&tags, "tags", "A comma-separated list of tags to set on the metric")
fset.Parse(args)
_ = fset.Parse(args)
args = fset.Args()

if len(args) == 0 {
Expand All @@ -74,17 +74,13 @@ func client(cmd string, args ...string) {
value = 1.0
} else if value, err = strconv.ParseFloat(args[0], 64); err != nil {
errorf("bad metric value: %s", args[0])
} else {
args = args[1:]
}

case "set":
if len(args) == 0 {
errorf("missing metric value")
} else if value, err = strconv.ParseFloat(args[0], 64); err != nil {
errorf("bad metric value: %s", args[0])
} else {
args = args[1:]
}
}

Expand All @@ -101,28 +97,28 @@ func client(cmd string, args ...string) {
case "time":
start := time.Now()
run(extra...)
stats.Observe(name, time.Now().Sub(start), tags...)
stats.Observe(name, time.Since(start), tags...)
}
}

func server(args ...string) {
var fset = flag.NewFlagSet("dogstatsd agent [options...]", flag.ExitOnError)
fset := flag.NewFlagSet("dogstatsd agent [options...]", flag.ExitOnError)
var bind string

fset.StringVar(&bind, "bind", ":8125", "The network address to listen on for incoming UDP datagrams")
fset.Parse(args)
_ = fset.Parse(args)
log.Printf("listening for incoming UDP datagram on %s", bind)

datadog.ListenAndServe(bind, handlers{})
_ = datadog.ListenAndServe(bind, handlers{})
}

type handlers struct{}

func (h handlers) HandleMetric(m datadog.Metric, a net.Addr) {
func (h handlers) HandleMetric(m datadog.Metric, _ net.Addr) {
log.Print(m)
}

func (h handlers) HandleEvent(e datadog.Event, a net.Addr) {
func (h handlers) HandleEvent(e datadog.Event, _ net.Addr) {
log.Print(e)
}

Expand All @@ -146,7 +142,7 @@ func errorf(msg string, args ...interface{}) {
os.Exit(1)
}

func split(args []string, sep string) (head []string, tail []string) {
func split(args []string, sep string) (head, tail []string) {
if i := indexOf(args, sep); i < 0 {
head = args
} else {
Expand Down
6 changes: 3 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ContextAddTags(ctx context.Context, tags ...Tag) bool {
}

// ContextTags returns a copy of the tags on the context if they exist and nil
// if they don't exist
// if they don't exist.
func ContextTags(ctx context.Context) []Tag {
if x := getTagSlice(ctx); x != nil {
x.lock.Lock()
Expand Down Expand Up @@ -62,12 +62,12 @@ type tagSlice struct {
// for defining context keys was copied from Go 1.7's new use of context in net/http.
type tagsKey struct{}

// String is Stringer implementation
// String implements the fmt.Stringer interface.
func (k tagsKey) String() string {
return "stats_tags_context_key"
}

// contextKeyReqTags is contextKey for tags
// contextKeyReqTags is contextKey for tags.
var (
contextKeyReqTags = tagsKey{}
)
3 changes: 2 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func TestContextTags(t *testing.T) {
assert.Equal(t, 0, len(ContextTags(x)), "Original context should have no tags (because no context with key)")

// create a child context which creates a child context
z := context.WithValue(y, "not", "important")
type unimportant struct{}
z := context.WithValue(y, unimportant{}, "important")
assert.Equal(t, 1, len(ContextTags(z)), "We should still be able to see original tags")

// Add tags to the child context's reference to the original tag slice
Expand Down
2 changes: 1 addition & 1 deletion datadog/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "testing"

func TestAppendMetric(t *testing.T) {
for _, test := range testMetrics {
t.Run(test.m.Name, func(b *testing.T) {
t.Run(test.m.Name, func(t *testing.T) {
if s := string(appendMetric(nil, test.m)); s != test.s {
t.Errorf("\n<<< %#v\n>>> %#v", test.s, s)
}
Expand Down
Loading