forked from uber-go/tally
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add M3 reporter backend to tally (uber-go#24)
- Loading branch information
1 parent
70e704c
commit febc00f
Showing
39 changed files
with
4,323 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,6 @@ _testmain.go | |
*.log | ||
|
||
.DS_Store | ||
node_modules/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ cache: | |
directories: | ||
- vendor | ||
install: | ||
- npm i uber-licence | ||
- make dependencies | ||
script: | ||
- make test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,4 @@ | ||
#!/bin/bash | ||
|
||
text=`head -1 LICENSE` | ||
|
||
ERROR_COUNT=0 | ||
while read file | ||
do | ||
head -1 ${file} | grep -q "${text}" | ||
if [ $? -ne 0 ]; then | ||
echo "$file is missing license header." | ||
ERROR_COUNT+=1 | ||
fi | ||
done < <(git ls-files "\.go") | ||
|
||
exit $ERROR_COUNT | ||
./node_modules/.bin/uber-licence --version || npm i uber-licence@latest | ||
./node_modules/.bin/uber-licence --dry --file "*.go" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// 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 OR COPYRIGHT HOLDERS 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. | ||
|
||
package m3 | ||
|
||
// Configuration is a configuration for a M3 reporter. | ||
type Configuration struct { | ||
// HostPort is the host and port of the M3 server. | ||
HostPort string `yaml:"hostPort" validate:"nonzero"` | ||
|
||
// HostPorts are the host and port of the M3 server. | ||
HostPorts []string `yaml:"hostPorts"` | ||
|
||
// Service is the service tag to that this client emits. | ||
Service string `yaml:"service" validate:"nonzero"` | ||
|
||
// Env is the env tag to use that this client emits. | ||
Env string `yaml:"env" validate:"nonzero"` | ||
|
||
// CommonTags are tags that are common for all metrics this client emits. | ||
CommonTags map[string]string `yaml:"tags" ` | ||
|
||
// Queue is the maximum metric queue size of client. | ||
Queue int `yaml:"queue"` | ||
|
||
// PacketSize is the maximum packet size for a batch of metrics. | ||
PacketSize int32 `yaml:"packetSize"` | ||
|
||
// IncludeHost is whether or not to include host tag. | ||
IncludeHost bool `yaml:"includeHost"` | ||
} | ||
|
||
// NewReporter creates a new M3 reporter from this configuration. | ||
func (c Configuration) NewReporter() (Reporter, error) { | ||
hostPorts := c.HostPorts | ||
if len(hostPorts) == 0 { | ||
hostPorts = []string{c.HostPort} | ||
} | ||
return NewReporter(Options{ | ||
HostPorts: hostPorts, | ||
Service: c.Service, | ||
Env: c.Env, | ||
CommonTags: c.CommonTags, | ||
MaxQueueSize: c.Queue, | ||
MaxPacketSizeBytes: c.PacketSize, | ||
IncludeHost: c.IncludeHost, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// 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 OR COPYRIGHT HOLDERS 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. | ||
|
||
package m3 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/uber-go/tally/m3/thriftudp" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConfigSimple(t *testing.T) { | ||
c := Configuration{ | ||
HostPort: "127.0.0.1:9052", | ||
Service: "my-service", | ||
Env: "test", | ||
} | ||
r, err := c.NewReporter() | ||
require.NoError(t, err) | ||
|
||
reporter := r.(*reporter) | ||
_, ok := reporter.client.Transport.(*thriftudp.TUDPTransport) | ||
assert.True(t, ok) | ||
assert.True(t, tagEquals(reporter.commonTags, "service", "my-service")) | ||
assert.True(t, tagEquals(reporter.commonTags, "env", "test")) | ||
} | ||
|
||
func TestConfigMulti(t *testing.T) { | ||
c := Configuration{ | ||
HostPorts: []string{"127.0.0.1:9052", "127.0.0.1:9062"}, | ||
Service: "my-service", | ||
Env: "test", | ||
} | ||
r, err := c.NewReporter() | ||
require.NoError(t, err) | ||
|
||
reporter := r.(*reporter) | ||
_, ok := reporter.client.Transport.(*thriftudp.TMultiUDPTransport) | ||
assert.True(t, ok) | ||
assert.True(t, tagEquals(reporter.commonTags, "service", "my-service")) | ||
assert.True(t, tagEquals(reporter.commonTags, "env", "test")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// 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 OR COPYRIGHT HOLDERS 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. | ||
|
||
package customtransport | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/apache/thrift/lib/go/thrift" | ||
) | ||
|
||
// TBufferedReadTransport is a thrift.TTransport that reads from a buffer | ||
type TBufferedReadTransport struct { | ||
readBuf *bytes.Buffer | ||
} | ||
|
||
// NewTBufferedReadTransport creates a buffer backed TTransport | ||
func NewTBufferedReadTransport(readBuf *bytes.Buffer) (*TBufferedReadTransport, error) { | ||
return &TBufferedReadTransport{readBuf: readBuf}, nil | ||
} | ||
|
||
// IsOpen does nothing as transport is not maintaining the connection | ||
// Required to maintain thrift.TTransport interface | ||
func (p *TBufferedReadTransport) IsOpen() bool { | ||
return true | ||
} | ||
|
||
// Open does nothing as transport is not maintaining the connection | ||
// Required to maintain thrift.TTransport interface | ||
func (p *TBufferedReadTransport) Open() error { | ||
return nil | ||
} | ||
|
||
// Close does nothing as transport is not maintaining the connection | ||
// Required to maintain thrift.TTransport interface | ||
func (p *TBufferedReadTransport) Close() error { | ||
return nil | ||
} | ||
|
||
// Read reads bytes from the local buffer and puts them in the specified buf | ||
func (p *TBufferedReadTransport) Read(buf []byte) (int, error) { | ||
in, err := p.readBuf.Read(buf) | ||
return in, thrift.NewTTransportExceptionFromError(err) | ||
} | ||
|
||
// RemainingBytes returns the number of bytes left to be read from the readBuf | ||
func (p *TBufferedReadTransport) RemainingBytes() uint64 { | ||
return uint64(p.readBuf.Len()) | ||
} | ||
|
||
// Write writes bytes into the read buffer | ||
// Required to maintain thrift.TTransport interface | ||
func (p *TBufferedReadTransport) Write(buf []byte) (int, error) { | ||
p.readBuf = bytes.NewBuffer(buf) | ||
return len(buf), nil | ||
} | ||
|
||
// Flush does nothing as udp server does not write responses back | ||
// Required to maintain thrift.TTransport interface | ||
func (p *TBufferedReadTransport) Flush() error { | ||
return nil | ||
} |
Oops, something went wrong.