add functions/vendor files

This commit is contained in:
Reed Allman
2017-06-11 02:05:36 -07:00
parent 6ee9c1fa0a
commit f2c7aa5ee6
7294 changed files with 1629834 additions and 0 deletions

73
vendor/github.com/amir/raidman/README.md generated vendored Normal file
View File

@@ -0,0 +1,73 @@
Raidman
=======
Go Riemann client
```go
package main
import (
"github.com/amir/raidman"
)
func main() {
c, err := raidman.Dial("tcp", "localhost:5555")
if err != nil {
panic(err)
}
var event = &raidman.Event{
State: "success",
Host: "raidman",
Service: "raidman-sample",
Metric: 100,
Ttl: 10,
}
// send one event
err = c.Send(event)
if err != nil {
panic(err)
}
// send multiple events at once
err = c.SendMulti([]*raidman.Event{
&raidman.Event{
State: "success",
Host: "raidman",
Service: "raidman-sample",
Metric: 100,
Ttl: 10,
},
&raidman.Event{
State: "failure",
Host: "raidman",
Service: "raidman-sample",
Metric: 100,
Ttl: 10,
},
&raidman.Event{
State: "success",
Host: "raidman",
Service: "raidman-sample",
Metric: 100,
Ttl: 10,
},
})
if err != nil {
panic(err)
}
events, err := c.Query("host = \"raidman\"")
if err != nil {
panic(err)
}
if len(events) < 1 {
panic("Submitted event not found")
}
c.Close()
}
```

24
vendor/github.com/amir/raidman/UNLICENSE generated vendored Normal file
View File

@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

6
vendor/github.com/amir/raidman/proto/Makefile generated vendored Normal file
View File

@@ -0,0 +1,6 @@
proto.pb.go: proto.proto
mkdir -p _pb
protoc --go_out=_pb $<
cat _pb/$@\
|gofmt >$@
rm -rf _pb

273
vendor/github.com/amir/raidman/proto/proto.pb.go generated vendored Normal file
View File

@@ -0,0 +1,273 @@
// Code generated by protoc-gen-go.
// source: proto.proto
// DO NOT EDIT!
package proto
import proto1 "github.com/golang/protobuf/proto"
import json "encoding/json"
import math "math"
// Reference proto, json, and math imports to suppress error if they are not otherwise used.
var _ = proto1.Marshal
var _ = &json.SyntaxError{}
var _ = math.Inf
type State struct {
Time *int64 `protobuf:"varint,1,opt,name=time" json:"time,omitempty"`
State *string `protobuf:"bytes,2,opt,name=state" json:"state,omitempty"`
Service *string `protobuf:"bytes,3,opt,name=service" json:"service,omitempty"`
Host *string `protobuf:"bytes,4,opt,name=host" json:"host,omitempty"`
Description *string `protobuf:"bytes,5,opt,name=description" json:"description,omitempty"`
Once *bool `protobuf:"varint,6,opt,name=once" json:"once,omitempty"`
Tags []string `protobuf:"bytes,7,rep,name=tags" json:"tags,omitempty"`
Ttl *float32 `protobuf:"fixed32,8,opt,name=ttl" json:"ttl,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *State) Reset() { *this = State{} }
func (this *State) String() string { return proto1.CompactTextString(this) }
func (*State) ProtoMessage() {}
func (this *State) GetTime() int64 {
if this != nil && this.Time != nil {
return *this.Time
}
return 0
}
func (this *State) GetState() string {
if this != nil && this.State != nil {
return *this.State
}
return ""
}
func (this *State) GetService() string {
if this != nil && this.Service != nil {
return *this.Service
}
return ""
}
func (this *State) GetHost() string {
if this != nil && this.Host != nil {
return *this.Host
}
return ""
}
func (this *State) GetDescription() string {
if this != nil && this.Description != nil {
return *this.Description
}
return ""
}
func (this *State) GetOnce() bool {
if this != nil && this.Once != nil {
return *this.Once
}
return false
}
func (this *State) GetTags() []string {
if this != nil {
return this.Tags
}
return nil
}
func (this *State) GetTtl() float32 {
if this != nil && this.Ttl != nil {
return *this.Ttl
}
return 0
}
type Event struct {
Time *int64 `protobuf:"varint,1,opt,name=time" json:"time,omitempty"`
State *string `protobuf:"bytes,2,opt,name=state" json:"state,omitempty"`
Service *string `protobuf:"bytes,3,opt,name=service" json:"service,omitempty"`
Host *string `protobuf:"bytes,4,opt,name=host" json:"host,omitempty"`
Description *string `protobuf:"bytes,5,opt,name=description" json:"description,omitempty"`
Tags []string `protobuf:"bytes,7,rep,name=tags" json:"tags,omitempty"`
Ttl *float32 `protobuf:"fixed32,8,opt,name=ttl" json:"ttl,omitempty"`
Attributes []*Attribute `protobuf:"bytes,9,rep,name=attributes" json:"attributes,omitempty"`
MetricSint64 *int64 `protobuf:"zigzag64,13,opt,name=metric_sint64" json:"metric_sint64,omitempty"`
MetricD *float64 `protobuf:"fixed64,14,opt,name=metric_d" json:"metric_d,omitempty"`
MetricF *float32 `protobuf:"fixed32,15,opt,name=metric_f" json:"metric_f,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *Event) Reset() { *this = Event{} }
func (this *Event) String() string { return proto1.CompactTextString(this) }
func (*Event) ProtoMessage() {}
func (this *Event) GetTime() int64 {
if this != nil && this.Time != nil {
return *this.Time
}
return 0
}
func (this *Event) GetState() string {
if this != nil && this.State != nil {
return *this.State
}
return ""
}
func (this *Event) GetService() string {
if this != nil && this.Service != nil {
return *this.Service
}
return ""
}
func (this *Event) GetHost() string {
if this != nil && this.Host != nil {
return *this.Host
}
return ""
}
func (this *Event) GetDescription() string {
if this != nil && this.Description != nil {
return *this.Description
}
return ""
}
func (this *Event) GetTags() []string {
if this != nil {
return this.Tags
}
return nil
}
func (this *Event) GetTtl() float32 {
if this != nil && this.Ttl != nil {
return *this.Ttl
}
return 0
}
func (this *Event) GetAttributes() []*Attribute {
if this != nil {
return this.Attributes
}
return nil
}
func (this *Event) GetMetricSint64() int64 {
if this != nil && this.MetricSint64 != nil {
return *this.MetricSint64
}
return 0
}
func (this *Event) GetMetricD() float64 {
if this != nil && this.MetricD != nil {
return *this.MetricD
}
return 0
}
func (this *Event) GetMetricF() float32 {
if this != nil && this.MetricF != nil {
return *this.MetricF
}
return 0
}
type Query struct {
String_ *string `protobuf:"bytes,1,opt,name=string" json:"string,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *Query) Reset() { *this = Query{} }
func (this *Query) String() string { return proto1.CompactTextString(this) }
func (*Query) ProtoMessage() {}
func (this *Query) GetString_() string {
if this != nil && this.String_ != nil {
return *this.String_
}
return ""
}
type Msg struct {
Ok *bool `protobuf:"varint,2,opt,name=ok" json:"ok,omitempty"`
Error *string `protobuf:"bytes,3,opt,name=error" json:"error,omitempty"`
States []*State `protobuf:"bytes,4,rep,name=states" json:"states,omitempty"`
Query *Query `protobuf:"bytes,5,opt,name=query" json:"query,omitempty"`
Events []*Event `protobuf:"bytes,6,rep,name=events" json:"events,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *Msg) Reset() { *this = Msg{} }
func (this *Msg) String() string { return proto1.CompactTextString(this) }
func (*Msg) ProtoMessage() {}
func (this *Msg) GetOk() bool {
if this != nil && this.Ok != nil {
return *this.Ok
}
return false
}
func (this *Msg) GetError() string {
if this != nil && this.Error != nil {
return *this.Error
}
return ""
}
func (this *Msg) GetStates() []*State {
if this != nil {
return this.States
}
return nil
}
func (this *Msg) GetQuery() *Query {
if this != nil {
return this.Query
}
return nil
}
func (this *Msg) GetEvents() []*Event {
if this != nil {
return this.Events
}
return nil
}
type Attribute struct {
Key *string `protobuf:"bytes,1,req,name=key" json:"key,omitempty"`
Value *string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *Attribute) Reset() { *this = Attribute{} }
func (this *Attribute) String() string { return proto1.CompactTextString(this) }
func (*Attribute) ProtoMessage() {}
func (this *Attribute) GetKey() string {
if this != nil && this.Key != nil {
return *this.Key
}
return ""
}
func (this *Attribute) GetValue() string {
if this != nil && this.Value != nil {
return *this.Value
}
return ""
}
func init() {
}

45
vendor/github.com/amir/raidman/proto/proto.proto generated vendored Normal file
View File

@@ -0,0 +1,45 @@
option java_package = "com.aphyr.riemann";
option java_outer_classname = "Proto";
message State {
optional int64 time = 1;
optional string state = 2;
optional string service = 3;
optional string host = 4;
optional string description = 5;
optional bool once = 6;
repeated string tags = 7;
optional float ttl = 8;
}
message Event {
optional int64 time = 1;
optional string state = 2;
optional string service = 3;
optional string host = 4;
optional string description = 5;
repeated string tags = 7;
optional float ttl = 8;
repeated Attribute attributes = 9;
optional sint64 metric_sint64 = 13;
optional double metric_d = 14;
optional float metric_f = 15;
}
message Query {
optional string string = 1;
}
message Msg {
optional bool ok = 2;
optional string error = 3;
repeated State states = 4;
optional Query query = 5;
repeated Event events = 6;
}
message Attribute {
required string key = 1;
optional string value = 2;
}

341
vendor/github.com/amir/raidman/raidman.go generated vendored Normal file
View File

@@ -0,0 +1,341 @@
// Go Riemann client
package raidman
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"net"
"net/url"
"os"
"reflect"
"sync"
"time"
"github.com/amir/raidman/proto"
pb "github.com/golang/protobuf/proto"
"golang.org/x/net/proxy"
)
type network interface {
Send(message *proto.Msg, conn net.Conn) (*proto.Msg, error)
}
type tcp struct{}
type udp struct{}
// Client represents a connection to a Riemann server
type Client struct {
sync.Mutex
net network
connection net.Conn
timeout time.Duration
}
// An Event represents a single Riemann event
type Event struct {
Ttl float32 `json:"ttl,omitempty"`
Time int64 `json:"time,omitempty"`
Tags []string `json:"tags,omitempty"`
Host string `json:"host,omitempty"` // Defaults to os.Hostname()
State string `json:"state,omitempty"`
Service string `json:"service,omitempty"`
Metric interface{} `json:"metric,omitempty"` // Could be Int, Float32, Float64
Description string `json:"description,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
}
// Dial establishes a connection to a Riemann server at addr, on the network
// netwrk, with a timeout of timeout
//
// Known networks are "tcp", "tcp4", "tcp6", "udp", "udp4", and "udp6".
func DialWithTimeout(netwrk, addr string, timeout time.Duration) (c *Client, err error) {
c = new(Client)
var cnet network
switch netwrk {
case "tcp", "tcp4", "tcp6":
cnet = new(tcp)
case "udp", "udp4", "udp6":
cnet = new(udp)
default:
return nil, fmt.Errorf("dial %q: unsupported network %q", netwrk, netwrk)
}
dialer, err := newDialer()
if err != nil {
return nil, err
}
c.net = cnet
c.timeout = timeout
c.connection, err = dialer.Dial(netwrk, addr)
if err != nil {
return nil, err
}
return c, nil
}
func newDialer() (proxy.Dialer, error) {
var proxyUrl = os.Getenv("RIEMANN_PROXY")
var dialer proxy.Dialer = proxy.Direct
// Get a proxy Dialer that will create the connection on our
// behalf via the SOCKS5 proxy. Specify the authentication
// and re-create the dialer/transport/client if tor's
// IsolateSOCKSAuth is needed.
if len(proxyUrl) > 0 {
u, err := url.Parse(proxyUrl)
if err != nil {
return nil, fmt.Errorf("failed to obtain proxy dialer: %v\n", err)
}
if dialer, err = proxy.FromURL(u, dialer); err != nil {
return nil, fmt.Errorf("failed to parse " + proxyUrl + " as a proxy: " + err.Error())
}
}
return dialer, nil
}
// Dial establishes a connection to a Riemann server at addr, on the network
// netwrk.
//
// Known networks are "tcp", "tcp4", "tcp6", "udp", "udp4", and "udp6".
func Dial(netwrk, addr string) (c *Client, err error) {
return DialWithTimeout(netwrk, addr, 0)
}
func (network *tcp) Send(message *proto.Msg, conn net.Conn) (*proto.Msg, error) {
msg := &proto.Msg{}
data, err := pb.Marshal(message)
if err != nil {
return msg, err
}
b := new(bytes.Buffer)
if err = binary.Write(b, binary.BigEndian, uint32(len(data))); err != nil {
return msg, err
}
if _, err = conn.Write(b.Bytes()); err != nil {
return msg, err
}
if _, err = conn.Write(data); err != nil {
return msg, err
}
var header uint32
if err = binary.Read(conn, binary.BigEndian, &header); err != nil {
return msg, err
}
response := make([]byte, header)
if err = readFully(conn, response); err != nil {
return msg, err
}
if err = pb.Unmarshal(response, msg); err != nil {
return msg, err
}
if msg.GetOk() != true {
return msg, errors.New(msg.GetError())
}
return msg, nil
}
func readFully(r io.Reader, p []byte) error {
for len(p) > 0 {
n, err := r.Read(p)
p = p[n:]
if err != nil {
return err
}
}
return nil
}
func (network *udp) Send(message *proto.Msg, conn net.Conn) (*proto.Msg, error) {
data, err := pb.Marshal(message)
if err != nil {
return nil, err
}
if _, err = conn.Write(data); err != nil {
return nil, err
}
return nil, nil
}
func isZero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Map:
return v.IsNil()
case reflect.Slice:
zero := true
for i := 0; i < v.Len(); i++ {
zero = zero && isZero(v.Index(i))
}
return zero
}
zero := reflect.Zero(v.Type())
return v.Interface() == zero.Interface()
}
func eventToPbEvent(event *Event) (*proto.Event, error) {
var e proto.Event
if event.Host == "" {
event.Host, _ = os.Hostname()
}
t := reflect.ValueOf(&e).Elem()
s := reflect.ValueOf(event).Elem()
typeOfEvent := s.Type()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)
value := reflect.ValueOf(f.Interface())
if !isZero(f) {
name := typeOfEvent.Field(i).Name
switch name {
case "State", "Service", "Host", "Description":
tmp := reflect.ValueOf(pb.String(value.String()))
t.FieldByName(name).Set(tmp)
case "Ttl":
tmp := reflect.ValueOf(pb.Float32(float32(value.Float())))
t.FieldByName(name).Set(tmp)
case "Time":
tmp := reflect.ValueOf(pb.Int64(value.Int()))
t.FieldByName(name).Set(tmp)
case "Tags":
tmp := reflect.ValueOf(value.Interface().([]string))
t.FieldByName(name).Set(tmp)
case "Metric":
switch reflect.TypeOf(f.Interface()).Kind() {
case reflect.Int, reflect.Int64:
tmp := reflect.ValueOf(pb.Int64(int64(value.Int())))
t.FieldByName("MetricSint64").Set(tmp)
case reflect.Uint64:
tmp := reflect.ValueOf(pb.Int64(int64(value.Uint())))
t.FieldByName("MetricSint64").Set(tmp)
case reflect.Float32:
tmp := reflect.ValueOf(pb.Float32(float32(value.Float())))
t.FieldByName("MetricF").Set(tmp)
case reflect.Float64:
tmp := reflect.ValueOf(pb.Float64(value.Float()))
t.FieldByName("MetricD").Set(tmp)
default:
return nil, fmt.Errorf("Metric of invalid type (type %v)",
reflect.TypeOf(f.Interface()).Kind())
}
case "Attributes":
var attrs []*proto.Attribute
for k, v := range value.Interface().(map[string]string) {
// Copy k,v so we can take
// pointers to the new
// temporaries
k_, v_ := k, v
attrs = append(attrs, &proto.Attribute{
Key: &k_,
Value: &v_,
})
}
t.FieldByName(name).Set(reflect.ValueOf(attrs))
}
}
}
return &e, nil
}
func pbEventsToEvents(pbEvents []*proto.Event) []Event {
var events []Event
for _, event := range pbEvents {
e := Event{
State: event.GetState(),
Service: event.GetService(),
Host: event.GetHost(),
Description: event.GetDescription(),
Ttl: event.GetTtl(),
Time: event.GetTime(),
Tags: event.GetTags(),
}
if event.MetricF != nil {
e.Metric = event.GetMetricF()
} else if event.MetricD != nil {
e.Metric = event.GetMetricD()
} else {
e.Metric = event.GetMetricSint64()
}
if event.Attributes != nil {
e.Attributes = make(map[string]string, len(event.GetAttributes()))
for _, attr := range event.GetAttributes() {
e.Attributes[attr.GetKey()] = attr.GetValue()
}
}
events = append(events, e)
}
return events
}
// Send sends an event to Riemann
func (c *Client) Send(event *Event) error {
return c.SendMulti([]*Event{event})
}
// SendMulti sends multiple events to Riemann
func (c *Client) SendMulti(events []*Event) error {
message := &proto.Msg{}
for _, event := range events {
e, err := eventToPbEvent(event)
if err != nil {
return err
}
message.Events = append(message.Events, e)
}
c.Lock()
defer c.Unlock()
if c.timeout > 0 {
err := c.connection.SetDeadline(time.Now().Add(c.timeout))
if err != nil {
return err
}
}
_, err := c.net.Send(message, c.connection)
if err != nil {
return err
}
return nil
}
// Query returns a list of events matched by query
func (c *Client) Query(q string) ([]Event, error) {
switch c.net.(type) {
case *udp:
return nil, errors.New("Querying over UDP is not supported")
}
query := &proto.Query{}
query.String_ = pb.String(q)
message := &proto.Msg{}
message.Query = query
c.Lock()
defer c.Unlock()
response, err := c.net.Send(message, c.connection)
if err != nil {
return nil, err
}
return pbEventsToEvents(response.GetEvents()), nil
}
// Close closes the connection to Riemann
func (c *Client) Close() error {
c.Lock()
defer c.Unlock()
return c.connection.Close()
}

286
vendor/github.com/amir/raidman/raidman_test.go generated vendored Normal file
View File

@@ -0,0 +1,286 @@
package raidman
import (
"fmt"
"os"
"reflect"
"testing"
)
func TestTCP(t *testing.T) {
c, err := Dial("tcp", "localhost:5555")
if err != nil {
t.Fatal(err.Error())
}
var event = &Event{
State: "success",
Host: "raidman",
Service: "tcp",
Metric: 42,
Ttl: 1,
Tags: []string{"tcp", "test", "raidman"},
Attributes: map[string]string{"type": "test"},
}
err = c.Send(event)
if err != nil {
t.Error(err.Error())
}
events, err := c.Query("tagged \"test\"")
if err != nil {
t.Error(err.Error())
}
if len(events) < 1 {
t.Error("Submitted event not found")
}
testAttributeExists := false
for _, event := range events {
if val, ok := event.Attributes["type"]; ok && val == "test" {
testAttributeExists = true
}
}
if !testAttributeExists {
t.Error("Attribute \"type\" is missing")
}
c.Close()
}
func TestMultiTCP(t *testing.T) {
c, err := Dial("tcp", "localhost:5555")
if err != nil {
t.Fatal(err.Error())
}
err = c.SendMulti([]*Event{
&Event{
State: "success",
Host: "raidman",
Service: "tcp-multi-1",
Metric: 42,
Ttl: 1,
Tags: []string{"tcp", "test", "raidman", "multi"},
Attributes: map[string]string{"type": "test"},
},
&Event{
State: "success",
Host: "raidman",
Service: "tcp-multi-2",
Metric: 42,
Ttl: 1,
Tags: []string{"tcp", "test", "raidman", "multi"},
Attributes: map[string]string{"type": "test"},
},
})
if err != nil {
t.Error(err.Error())
}
events, err := c.Query("tagged \"test\" and tagged \"multi\"")
if err != nil {
t.Error(err.Error())
}
if len(events) != 2 {
t.Error("Submitted event not found")
}
c.Close()
}
func TestMetricIsInt64(t *testing.T) {
c, err := Dial("tcp", "localhost:5555")
if err != nil {
t.Fatal(err.Error())
}
var int64metric int64 = 9223372036854775807
var event = &Event{
State: "success",
Host: "raidman",
Service: "tcp",
Metric: int64metric,
Ttl: 1,
Tags: []string{"tcp", "test", "raidman"},
Attributes: map[string]string{"type": "test"},
}
err = c.Send(event)
if err != nil {
t.Error(err.Error())
}
}
func TestUDP(t *testing.T) {
c, err := Dial("udp", "localhost:5555")
if err != nil {
t.Fatal(err.Error())
}
var event = &Event{
State: "warning",
Host: "raidman",
Service: "udp",
Metric: 3.4,
Ttl: 10.7,
}
err = c.Send(event)
if err != nil {
t.Error(err.Error())
}
c.Close()
}
func TestTCPWithoutHost(t *testing.T) {
c, err := Dial("tcp", "localhost:5555")
if err != nil {
t.Fatal(err.Error())
}
defer c.Close()
var event = &Event{
State: "success",
Service: "tcp-host-not-set",
Ttl: 5,
}
err = c.Send(event)
if err != nil {
t.Error(err.Error())
}
events, err := c.Query("service = \"tcp-host-not-set\"")
if err != nil {
t.Error(err.Error())
}
if len(events) < 1 {
t.Error("Submitted event not found")
}
for _, e := range events {
if e.Host == "" {
t.Error("Default host name is not set")
}
}
}
func TestIsZero(t *testing.T) {
event := &Event{
Time: 1,
}
elem := reflect.ValueOf(event).Elem()
eventType := elem.Type()
for i := 0; i < elem.NumField(); i++ {
field := elem.Field(i)
name := eventType.Field(i).Name
if name == "Time" {
if isZero(field) {
t.Error("Time should not be zero")
}
} else {
if !isZero(field) {
t.Errorf("%s should be zero", name)
}
}
}
}
func TestDialer(t *testing.T) {
proxyAddr := "localhost:9999"
os.Setenv("RIEMANN_PROXY", "socks5://"+proxyAddr)
defer os.Unsetenv("RIEMANN_PROXY")
dialer, err := newDialer()
if err != nil {
t.Error(err.Error())
}
val := reflect.Indirect(reflect.ValueOf(dialer))
// this is a horrible hack but proxy.Dialer exports nothing.
addr := fmt.Sprintf("%s", val.FieldByName("addr"))
if addr != proxyAddr {
t.Errorf("RIEMANN_PROXY is set and is %s but dialer's proxy is %s", proxyAddr, addr)
}
}
func BenchmarkTCP(b *testing.B) {
c, err := Dial("tcp", "localhost:5555")
var event = &Event{
State: "good",
Host: "raidman",
Service: "benchmark",
}
if err == nil {
for i := 0; i < b.N; i++ {
c.Send(event)
}
}
c.Close()
}
func BenchmarkUDP(b *testing.B) {
c, err := Dial("udp", "localhost:5555")
var event = &Event{
State: "good",
Host: "raidman",
Service: "benchmark",
}
if err == nil {
for i := 0; i < b.N; i++ {
c.Send(event)
}
}
c.Close()
}
func BenchmarkConcurrentTCP(b *testing.B) {
c, err := Dial("tcp", "localhost:5555")
var event = &Event{
Host: "raidman",
Service: "tcp_concurrent",
Tags: []string{"concurrent", "tcp", "benchmark"},
}
ch := make(chan int, b.N)
for i := 0; i < b.N; i++ {
go func(metric int) {
event.Metric = metric
err = c.Send(event)
ch <- i
}(i)
}
<-ch
c.Close()
}
func BenchmarkConcurrentUDP(b *testing.B) {
c, err := Dial("udp", "localhost:5555")
var event = &Event{
Host: "raidman",
Service: "udp_concurrent",
Tags: []string{"concurrent", "udp", "benchmark"},
}
ch := make(chan int, b.N)
for i := 0; i < b.N; i++ {
go func(metric int) {
event.Metric = metric
err = c.Send(event)
ch <- i
}(i)
}
<-ch
c.Close()
}