go client library for datadog
Go
Clone or download
vcabbage and ofek Reduce `Client.format` allocations (#53)
* add BenchmarkClientFormat

* reduce allocations in `Client.format`

* Avoid conversions to/from `string` as much as possible.
* Preallocate a sufficiently large `[]byte` in `Client.format` and
  use it in such a way that it doesn't escape. This allows the compiler
  to stack allocate the buffer.

Results (go version go1.10 darwin/amd64):

name               old time/op    new time/op    delta
ClientFormat/0-8      347ns ± 1%     236ns ± 2%  -32.08%  (p=0.000 n=20+18)
ClientFormat/1-8      343ns ± 1%     236ns ± 2%  -31.31%  (p=0.000 n=17+20)
ClientFormat/2-8      450ns ± 1%     250ns ± 2%  -44.49%  (p=0.000 n=20+19)
ClientFormat/3-8      539ns ± 1%     261ns ± 2%  -51.63%  (p=0.000 n=18+20)
ClientFormat/4-8      450ns ± 1%     249ns ± 2%  -44.55%  (p=0.000 n=20+20)
ClientFormat/5-8      266ns ± 1%      79ns ± 2%  -70.12%  (p=0.000 n=19+19)
ClientFormat/6-8      275ns ± 1%      86ns ± 1%  -68.58%  (p=0.000 n=17+18)
ClientFormat/7-8      567ns ± 3%     355ns ± 2%  -37.38%  (p=0.000 n=17+20)
ClientFormat/8-8      570ns ± 2%     357ns ± 2%  -37.40%  (p=0.000 n=18+20)
ClientFormat/9-8      228ns ± 1%      74ns ± 1%  -67.45%  (p=0.000 n=17+19)
ClientFormat/10-8     237ns ± 1%      77ns ± 1%  -67.55%  (p=0.000 n=20+19)
ClientFormat/11-8     319ns ± 1%      86ns ± 3%  -72.94%  (p=0.000 n=20+19)
ClientFormat/12-8     348ns ± 1%     154ns ± 2%  -55.85%  (p=0.000 n=20+17)

name               old alloc/op   new alloc/op   delta
ClientFormat/0-8       152B ± 0%       32B ± 0%  -78.95%  (p=0.000 n=20+20)
ClientFormat/1-8       152B ± 0%       32B ± 0%  -78.95%  (p=0.000 n=20+20)
ClientFormat/2-8       168B ± 0%       32B ± 0%  -80.95%  (p=0.000 n=20+20)
ClientFormat/3-8       184B ± 0%       32B ± 0%  -82.61%  (p=0.000 n=20+20)
ClientFormat/4-8       168B ± 0%       32B ± 0%  -80.95%  (p=0.000 n=20+20)
ClientFormat/5-8       168B ± 0%       32B ± 0%  -80.95%  (p=0.000 n=20+20)
ClientFormat/6-8       168B ± 0%       32B ± 0%  -80.95%  (p=0.000 n=20+20)
ClientFormat/7-8       168B ± 0%       32B ± 0%  -80.95%  (p=0.000 n=20+20)
ClientFormat/8-8       184B ± 0%       48B ± 0%  -73.91%  (p=0.000 n=20+20)
ClientFormat/9-8       160B ± 0%       32B ± 0%  -80.00%  (p=0.000 n=20+20)
ClientFormat/10-8      160B ± 0%       32B ± 0%  -80.00%  (p=0.000 n=20+20)
ClientFormat/11-8      176B ± 0%       32B ± 0%  -81.82%  (p=0.000 n=20+20)
ClientFormat/12-8      200B ± 0%       32B ± 0%  -84.00%  (p=0.000 n=20+20)

name               old allocs/op  new allocs/op  delta
ClientFormat/0-8       3.00 ± 0%      1.00 ± 0%  -66.67%  (p=0.000 n=20+20)
ClientFormat/1-8       3.00 ± 0%      1.00 ± 0%  -66.67%  (p=0.000 n=20+20)
ClientFormat/2-8       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.000 n=20+20)
ClientFormat/3-8       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.000 n=20+20)
ClientFormat/4-8       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.000 n=20+20)
ClientFormat/5-8       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.000 n=20+20)
ClientFormat/6-8       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.000 n=20+20)
ClientFormat/7-8       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.000 n=20+20)
ClientFormat/8-8       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.000 n=20+20)
ClientFormat/9-8       3.00 ± 0%      1.00 ± 0%  -66.67%  (p=0.000 n=20+20)
ClientFormat/10-8      3.00 ± 0%      1.00 ± 0%  -66.67%  (p=0.000 n=20+20)
ClientFormat/11-8      3.00 ± 0%      1.00 ± 0%  -66.67%  (p=0.000 n=20+20)
ClientFormat/12-8      6.00 ± 0%      1.00 ± 0%  -83.33%  (p=0.000 n=20+20)

* Prevent attempting to build benchmarks with < go1.7
Latest commit ef3a9da Jul 2, 2018

README.md

Build Status

Overview

Packages in datadog-go provide Go clients for various APIs at DataDog.

Statsd

Godoc license

The statsd package provides a client for dogstatsd:

import "github.com/DataDog/datadog-go/statsd"

func main() {
    c, err := statsd.New("127.0.0.1:8125")
    if err != nil {
        log.Fatal(err)
    }
    // prefix every metric with the app name
    c.Namespace = "flubber."
    // send the EC2 availability zone as a tag with every metric
    c.Tags = append(c.Tags, "region:us-east-1a")
    err = c.Gauge("request.duration", 1.2, nil, 1)
    // ...
}

License

All code distributed under the MIT License unless otherwise specified.