Skip to content

Commit

Permalink
chore: bump workflows, update Go
Browse files Browse the repository at this point in the history
Touch up versions.
  • Loading branch information
smira committed Oct 3, 2023
1 parent 36cb201 commit 60e773d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 41 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
on: [push, pull_request]
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

name: Lint
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.28
version: v1.54
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
on: [push, pull_request]
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.14.x, 1.15.x]
go-version: [1.20.x, 1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Test
run: go test -v ./...
- name: Test Race
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ linters:
- megacheck
- staticcheck
- unused
- deadcode
- typecheck
- ineffassign
- golint
- revive
- stylecheck
- unparam
- nakedret
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func TestConcurrent(t *testing.T) {
i2 := strings.Index(part, "|")

if i1 == -1 || i2 == -1 {
t.Logf("unaparseable part: %#v", part)
t.Logf("non-parsable part: %#v", part)
continue
}

Expand Down Expand Up @@ -334,8 +334,8 @@ func TestConcurrent(t *testing.T) {

_ = client.Close()

// wait for 10 seconds for all the packets to be received
for i := 0; i < 10; i++ {
// wait for 20 seconds for all the packets to be received
for i := 0; i < 20; i++ {
if atomic.LoadInt64(&totalSent) == atomic.LoadInt64(&totalReceived) {
break
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/smira/go-statsd

go 1.12
go 1.20
2 changes: 1 addition & 1 deletion loops.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ WAIT:
}

// drain send queue waiting for flush loops to terminate
for range t.sendQueue {
for range t.sendQueue { //nolint:revive
}
}

Expand Down
52 changes: 26 additions & 26 deletions statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,56 @@ Performance of statsd client library is critical to introduce as little overhead
Client has zero memory allocation per metric being sent, architecture is the following:
* there's ring of buffers, each buffer is UDP packet
* buffer is taken from the pool, filled with metrics, passed on to the network delivery and
passed back to the pool
* buffer is flushed either when it is full or when flush period comes (e.g. every 100ms)
* separate goroutine is handling network operations: sending UDP packets and reconnecting UDP socket
(to handle statsd DNS address change)
* when metric is serialized, zero allocation methods are used to avoid `reflect` and memory allocation
- there's ring of buffers, each buffer is UDP packet
- buffer is taken from the pool, filled with metrics, passed on to the network delivery and
passed back to the pool
- buffer is flushed either when it is full or when flush period comes (e.g. every 100ms)
- separate goroutine is handling network operations: sending UDP packets and reconnecting UDP socket
(to handle statsd DNS address change)
- when metric is serialized, zero allocation methods are used to avoid `reflect` and memory allocation
Ideas were borrowed from the following stastd clients:
* https://github.com/quipo/statsd
* https://github.com/Unix4ever/statsd
* https://github.com/alexcesaro/statsd/
* https://github.com/armon/go-metrics
- https://github.com/quipo/statsd
- https://github.com/Unix4ever/statsd
- https://github.com/alexcesaro/statsd/
- https://github.com/armon/go-metrics
Usage
# Usage
Initialize client instance with options, one client per application is usually enough:
client := statsd.NewClient("localhost:8125",
statsd.MaxPacketSize(1400),
statsd.MetricPrefix("web."))
client := statsd.NewClient("localhost:8125",
statsd.MaxPacketSize(1400),
statsd.MetricPrefix("web."))
Send metrics as events happen in the application, metrics will be packed together and
delivered to statsd server:
start := time.Now()
client.Incr("requests.http", 1)
...
client.PrecisionTiming("requests.route.api.latency", time.Since(start))
start := time.Now()
client.Incr("requests.http", 1)
...
client.PrecisionTiming("requests.route.api.latency", time.Since(start))
Shutdown client during application shutdown to flush all the pending metrics:
client.Close()
client.Close()
Tagging
# Tagging
Metrics could be tagged to support aggregation on TSDB side. go-statsd supports
tags in InfluxDB and Datadog formats. Format and default tags (applied to every
metric) are passed as options to the client initialization:
client := statsd.NewClient("localhost:8125",
statsd.TagStyle(TagFormatDatadog),
statsd.DefaultTags(statsd.StringTag("app", "billing")))
client := statsd.NewClient("localhost:8125",
statsd.TagStyle(TagFormatDatadog),
statsd.DefaultTags(statsd.StringTag("app", "billing")))
For every metric sent, tags could be added as the last argument(s) to the function
call:
client.Incr("request", 1,
statsd.StringTag("protocol", "http"), statsd.IntTag("port", 80))
client.Incr("request", 1,
statsd.StringTag("protocol", "http"), statsd.IntTag("port", 80))
*/
package statsd

Expand Down

0 comments on commit 60e773d

Please sign in to comment.