Exemplo n.º 1
0
func TestCarbonInvalidCarbonDeconstructorListenerLoader(t *testing.T) {
	listenFrom := &config.ListenFrom{
		ListenAddr:          workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:12247"),
		MetricDeconstructor: workarounds.GolangDoesnotAllowPointerToStringLiteral("UNKNOWN"),
	}
	ctx := context.Background()
	forwardTo := dptest.NewBasicSink()
	_, err := ListenerLoader(ctx, forwardTo, listenFrom)
	assert.NotEqual(t, nil, err, "Should get an error making")
}
Exemplo n.º 2
0
func TestListenerLoader(t *testing.T) {
	listenFrom := &config.ListenFrom{
		ListenAddr:           workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0"),
		ServerAcceptDeadline: workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Millisecond),
	}
	ctx := context.Background()
	forwardTo := dptest.NewBasicSink()
	listener, err := ListenerLoader(ctx, forwardTo, listenFrom)
	defer listener.Close()
	assert.Equal(t, nil, err, "Should be ok to make")
	defer listener.Close()
	listeningDialAddress := fmt.Sprintf("127.0.0.1:%d", nettest.TCPPort(listener.psocket))
	assert.Equal(t, numStats, len(listener.Stats()), "Should have no stats")
	assert.NoError(t, err, "Should be ok to make")

	conn, err := net.Dial("tcp", listeningDialAddress)
	assert.NoError(t, err, "Should be ok to make")
	assert.Equal(t, int64(0), listener.stats.invalidDatapoints)
	var buf bytes.Buffer
	fmt.Fprintf(&buf, "%s %d %d\n\nINVALIDLINE", "ametric", 2, 2)
	_, err = buf.WriteTo(conn)
	conn.Close()
	assert.Equal(t, nil, err, "Should be ok to write")
	dp := forwardTo.Next()
	assert.Equal(t, "ametric", dp.Metric, "Should be metric")
	i := dp.Value.(datapoint.IntValue).Int()
	assert.Equal(t, int64(2), i, "Should get 2")

	for atomic.LoadInt64(&listener.stats.retriedListenErrors) == 0 {
		time.Sleep(time.Millisecond)
	}
	assert.Equal(t, int64(1), atomic.LoadInt64(&listener.stats.invalidDatapoints))
}
Exemplo n.º 3
0
func TestCarbonHandleConnection(t *testing.T) {
	log.Info("START TestCarbonHandleConnection")
	defer log.Info("END   TestCarbonHandleConnection")
	listenFrom := &config.ListenFrom{
		ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("localhost:0"),
	}

	ctx := context.Background()
	forwardTo := dptest.NewBasicSink()
	listener, err := ListenerLoader(ctx, forwardTo, listenFrom)
	defer listener.Close()

	listeningDialAddress := fmt.Sprintf("localhost:%d", nettest.TCPPort(listener.psocket))

	conn, err := net.Dial("tcp", listeningDialAddress)
	assert.NoError(t, err)
	conn.Close()
	assert.Error(t, listener.handleConnection(conn))

	conn, err = net.Dial("tcp", listeningDialAddress)
	assert.NoError(t, err)
	waitChan := make(chan struct{})
	go func() {
		time.Sleep(time.Millisecond * 10)
		assert.NoError(t, conn.Close())
		close(waitChan)
	}()
	<-waitChan

	for atomic.LoadInt64(&listener.stats.totalEOFCloses) == 0 {
		time.Sleep(time.Millisecond)
	}
}
Exemplo n.º 4
0
func TestInvalidPort(t *testing.T) {

	ft := config.ForwardTo{
		Host: workarounds.GolangDoesnotAllowPointerToStringLiteral("zzfbdsaj_)__@#$%.zzzzzzzzzzz"),
		Port: workarounds.GolangDoesnotAllowPointerToUint16Literal(1),
	}
	_, err := ForwarderLoader(context.Background(), &ft)
	assert.NotEqual(t, nil, err, "Expect an error")
}
Exemplo n.º 5
0
func TestInvalidListen(t *testing.T) {
	listenFrom := &config.ListenFrom{
		ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:999999"),
	}
	sendTo := dptest.NewBasicSink()
	ctx := context.Background()
	_, err := ListenerLoader(ctx, sendTo, listenFrom)
	assert.Error(t, err)
}
func TestForwarderLoaderOldVersion(t *testing.T) {
	forwardTo := config.ForwardTo{
		FormatVersion:    workarounds.GolangDoesnotAllowPointerToUintLiteral(1),
		DefaultAuthToken: workarounds.GolangDoesnotAllowPointerToStringLiteral("AUTH_TOKEN"),
	}
	ctx := context.Background()
	_, err := ForwarderLoader(ctx, &forwardTo)
	assert.NoError(t, err)
}
Exemplo n.º 7
0
func TestCarbonInvalidListenerLoader(t *testing.T) {
	ctx := context.Background()
	listenFrom := &config.ListenFrom{
		ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:999999"),
	}
	sendTo := dptest.NewBasicSink()
	_, err := ListenerLoader(ctx, sendTo, listenFrom)
	assert.NotEqual(t, nil, err, "Should get an error making")
}
Exemplo n.º 8
0
func TestNewProtobufDataPoint(t *testing.T) {
	protoDatapoint := &com_signalfx_metrics_protobuf.DataPoint{
		Source: workarounds.GolangDoesnotAllowPointerToStringLiteral("asource"),
		Metric: workarounds.GolangDoesnotAllowPointerToStringLiteral("ametric"),
		Value:  &com_signalfx_metrics_protobuf.Datum{IntValue: workarounds.GolangDoesnotAllowPointerToIntLiteral(2)},
		Dimensions: []*com_signalfx_metrics_protobuf.Dimension{{
			Key:   workarounds.GolangDoesnotAllowPointerToStringLiteral("key"),
			Value: workarounds.GolangDoesnotAllowPointerToStringLiteral("value"),
		}},
	}
	dp, err := NewProtobufDataPointWithType(protoDatapoint, com_signalfx_metrics_protobuf.MetricType_COUNTER)
	assert.Equal(t, "asource", dp.Dimensions["sf_source"], "Line should be invalid")
	assert.NoError(t, err)
	assert.Equal(t, datapoint.Count, dp.MetricType, "Line should be invalid")

	v := com_signalfx_metrics_protobuf.MetricType_CUMULATIVE_COUNTER
	protoDatapoint.MetricType = &v
	dp, err = NewProtobufDataPointWithType(protoDatapoint, com_signalfx_metrics_protobuf.MetricType_COUNTER)
	assert.NoError(t, err)
	assert.Equal(t, datapoint.Counter, dp.MetricType, "Line should be invalid")

	item := &BodySendFormatV2{
		Metric: "ametric",
		Value:  3.0,
	}
	assert.Contains(t, item.String(), "ametric", "Should get metric name back")
	f, _ := ValueToValue(item.Value)
	assert.Equal(t, datapoint.NewFloatValue(3.0), f, "Should get value 3 back")

	item.Value = 3
	i, _ := ValueToValue(item.Value)
	assert.Equal(t, datapoint.NewIntValue(3), i, "Should get value 3 back")

	item.Value = int64(3)
	ValueToValue(item.Value)

	item.Value = "abc"
	s, _ := ValueToValue(item.Value)
	assert.Equal(t, datapoint.NewStringValue("abc"), s, "Should get value abc back")

	item.Value = struct{}{}
	_, err = ValueToValue(item.Value)
	assert.Error(t, err)
}
func TestForwarderLoaderDefaults(t *testing.T) {
	forwardTo := config.ForwardTo{
		FormatVersion:    workarounds.GolangDoesnotAllowPointerToUintLiteral(2),
		DefaultAuthToken: workarounds.GolangDoesnotAllowPointerToStringLiteral("AUTH_TOKEN"),
	}
	ctx := context.Background()
	forwarder, err := ForwarderLoader(ctx, &forwardTo)
	assert.Nil(t, err)
	defer forwarder.Close()
}
Exemplo n.º 10
0
func TestLoader(t *testing.T) {
	listenFrom := config.ListenFrom{}
	listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
	ctx := context.Background()
	forwardTo := dptest.NewBasicSink()
	l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
	port := nettest.TCPPort(l.psocket)

	ft := config.ForwardTo{
		Host: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1"),
		Port: workarounds.GolangDoesnotAllowPointerToUint16Literal(port),
	}
	f, err := ForwarderLoader(context.Background(), &ft)
	assert.NoError(t, err)
	dpSent := dptest.DP()
	dpSent.Dimensions = map[string]string{}
	assert.NoError(t, f.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent}))
	dpSeen := forwardTo.Next()
	assert.Equal(t, dpSent.Metric, dpSeen.Metric)
	assert.Equal(t, numStats+1, len(f.Stats()))
}
Exemplo n.º 11
0
func TestFilenameForwarderBadWrite(t *testing.T) {
	ctx := context.Background()
	fileObj, _ := ioutil.TempFile("", "gotest")
	defer os.Remove(fileObj.Name())
	conf := &config.ForwardTo{
		Filename: workarounds.GolangDoesnotAllowPointerToStringLiteral(fileObj.Name()),
	}
	f, _ := ForwarderLoader(conf)
	f.writeString = func(f *os.File, s string) (ret int, err error) {
		return 0, errors.New("nope")
	}
	assert.Error(t, f.AddDatapoints(ctx, []*datapoint.Datapoint{dptest.DP()}))
	assert.Error(t, f.AddEvents(ctx, []*event.Event{dptest.E()}))
}
Exemplo n.º 12
0
func TestFilenameForwarder(t *testing.T) {
	ctx := context.Background()
	fileObj, _ := ioutil.TempFile("", "gotest")
	filename := fileObj.Name()
	defer os.Remove(filename)
	conf := &config.ForwardTo{
		Filename: workarounds.GolangDoesnotAllowPointerToStringLiteral(fileObj.Name()),
	}
	f, err := ForwarderLoader(conf)
	defer f.Close()
	assert.NoError(t, err)
	assert.NoError(t, f.AddDatapoints(ctx, []*datapoint.Datapoint{dptest.DP()}))
	assert.NoError(t, f.AddEvents(ctx, []*event.Event{dptest.E()}))
	assert.Equal(t, 0, len(f.Stats()))
}
Exemplo n.º 13
0
func setupServerForwarder(t *testing.T) (*dptest.BasicSink, *ListenerServer, *Forwarder) {
	// TODO: Break this out into smaller tests
	listenFromSignalfx := config.ListenFrom{}
	listenFromSignalfx.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")

	finalDatapointDestination := dptest.NewBasicSink()
	ctx := context.Background()
	l, err := ListenerLoader(ctx, finalDatapointDestination, &listenFromSignalfx)
	assert.Equal(t, nil, err, "Expect no error")

	port := nettest.TCPPort(l.listener)

	forwardTo := config.ForwardTo{
		URL:              workarounds.GolangDoesnotAllowPointerToStringLiteral(fmt.Sprintf("http://127.0.0.1:%d/v2/datapoint", port)),
		TimeoutDuration:  workarounds.GolangDoesnotAllowPointerToDurationLiteral(time.Second * 1),
		DefaultAuthToken: workarounds.GolangDoesnotAllowPointerToStringLiteral("AUTH_TOKEN"),
		DefaultSource:    workarounds.GolangDoesnotAllowPointerToStringLiteral("proxy-source"),
		SourceDimensions: workarounds.GolangDoesnotAllowPointerToStringLiteral("username,ignored,hostname"),
	}

	_, forwarder, err := ForwarderLoader1(ctx, &forwardTo)
	assert.NoError(t, err, "Expect no error")
	return finalDatapointDestination, l, forwarder
}
Exemplo n.º 14
0
func TestCreation(t *testing.T) {
	listenFrom := config.ListenFrom{}
	listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
	forwardTo := dptest.NewBasicSink()
	ctx := context.Background()
	l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
	defer l.Close()
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, numStats, len(l.Stats()), "Expect no stats")
	forwarder, err := NewForwarder("127.0.0.1", nettest.TCPPort(l.psocket), time.Second, []string{"zzfirst"}, 10)
	defer forwarder.Close()
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, 1, len(forwarder.pool.conns))
	timeToSend := time.Now().Round(time.Second)
	dpSent := dptest.DP()
	dpSent.Timestamp = timeToSend
	log.Info("Sending a dp")
	forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent})
	log.Info("Looking for DP back")
	dpSeen := forwardTo.Next()

	assert.Equal(t, "randtest."+dpSent.Metric, dpSeen.Metric, "Expect metric back")
	assert.Equal(t, dpSent.Timestamp, dpSeen.Timestamp, "Expect metric back")

	// Test creating a new connection if pool is empty
	for forwarder.pool.Get() != nil {
	}

	forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent})
	dpSeen = forwardTo.Next()
	assert.Equal(t, "randtest."+dpSent.Metric, dpSeen.Metric, "Expect metric back")
	assert.Equal(t, dpSent.Timestamp, dpSeen.Timestamp, "Expect metric back")
	//
	// Test creation error if pool is empty
	for forwarder.pool.Get() != nil {
	}

	forwarder.dialer = func(network, address string, timeout time.Duration) (net.Conn, error) {
		return nil, errors.New("nope")
	}
	assert.Error(t, forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSeen}))

	forwarder.dialer = net.DialTimeout
	assert.NoError(t, forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSeen}), "Should get the conn back")

}
Exemplo n.º 15
0
func TestCarbonNoWriteEvents(t *testing.T) {
	listenFrom := config.ListenFrom{}
	listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
	forwardTo := dptest.NewBasicSink()
	ctx := context.Background()
	l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
	defer l.Close()
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, numStats, len(l.Stats()), "Expect no stats")
	forwarder, err := NewForwarder("127.0.0.1", nettest.TCPPort(l.psocket), time.Second, []string{"zzfirst"}, 10)
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, 1, len(forwarder.pool.conns))
	timeToSend := time.Now().Round(time.Second)
	eSent := dptest.E()
	eSent.Timestamp = timeToSend
	eSent.Meta["blarg"] = "abcd 123 123"
	log.Info("Sending a e")
	forwarder.AddEvents(ctx, []*event.Event{eSent})
	assert.Equal(t, 0, len(forwardTo.EventsChan))

}
Exemplo n.º 16
0
func TestWriteError(t *testing.T) {
	listenFrom := config.ListenFrom{}
	listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")

	forwardTo := dptest.NewBasicSink()
	ctx := context.Background()
	l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
	defer l.Close()
	forwarder, err := NewForwarder("127.0.0.1", nettest.TCPPort(l.psocket), time.Second, []string{}, 10)
	assert.Equal(t, nil, err, "Expect no error")

	forwarder.dialer = func(network, address string, timeout time.Duration) (net.Conn, error) {
		mockConn := mockConn{}
		mockConn.writeReturn = errors.New("deadline error")
		return &mockConn, nil
	}

	for forwarder.pool.Get() != nil {
	}

	dpSent := dptest.DP()
	assert.Error(t, forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent}))
}
Exemplo n.º 17
0
func TestCarbonWrite(t *testing.T) {
	listenFrom := config.ListenFrom{}
	listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
	forwardTo := dptest.NewBasicSink()
	ctx := context.Background()
	l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
	defer l.Close()
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, numStats, len(l.Stats()), "Expect no stats")
	forwarder, err := NewForwarder("127.0.0.1", nettest.TCPPort(l.psocket), time.Second, []string{"zzfirst"}, 10)
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, 1, len(forwarder.pool.conns))
	timeToSend := time.Now().Round(time.Second)
	dpSent := dptest.DP()
	dpSent.Timestamp = timeToSend
	dpSent.Meta[carbonNative] = "abcd 123 123"
	log.Info("Sending a dp")
	forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent})
	log.Info("Looking for DP back")
	dpSeen := forwardTo.Next()

	assert.Equal(t, "abcd", dpSeen.Metric, "Expect metric back")
}
Exemplo n.º 18
0
		connectionAddress: connectionAddress,
		dialer:            net.DialTimeout,
		pool: connPool{
			conns: make([]net.Conn, 0, drainingThreads),
		},
	}
	ret.pool.Return(conn)
	return ret, nil
}

var defaultForwarderConfig = &config.ForwardTo{
	TimeoutDuration: workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Second * 30),
	BufferSize:      workarounds.GolangDoesnotAllowPointerToUintLiteral(uint32(10000)),
	Port:            workarounds.GolangDoesnotAllowPointerToUint16Literal(2003),
	DrainingThreads: workarounds.GolangDoesnotAllowPointerToUintLiteral(uint32(5)),
	Name:            workarounds.GolangDoesnotAllowPointerToStringLiteral("carbonforwarder"),
	MaxDrainSize:    workarounds.GolangDoesnotAllowPointerToUintLiteral(uint32(1000)),
	DimensionsOrder: []string{},
}

var errRequiredHost = errors.New("carbon forwarder requires host config")

// ForwarderLoader loads a carbon forwarder that is buffered
func ForwarderLoader(ctx context.Context, forwardTo *config.ForwardTo) (protocol.Forwarder, error) {
	structdefaults.FillDefaultFrom(forwardTo, defaultForwarderConfig)
	if forwardTo.Host == nil {
		return nil, errRequiredHost
	}
	fwd, err := NewForwarder(*forwardTo.Host, *forwardTo.Port, *forwardTo.TimeoutDuration, forwardTo.DimensionsOrder, *forwardTo.DrainingThreads)
	if err != nil {
		return nil, err
Exemplo n.º 19
0
	"sync"

	log "github.com/Sirupsen/logrus"
	"github.com/cep21/gohelpers/structdefaults"
	"github.com/cep21/gohelpers/workarounds"
	"github.com/signalfx/golib/datapoint"
	"github.com/signalfx/golib/event"
	"github.com/signalfx/metricproxy/config"
	"github.com/signalfx/metricproxy/dp/dpsink"
	"github.com/signalfx/metricproxy/protocol"
	"golang.org/x/net/context"
)

var csvDefaultConfig = &config.ForwardTo{
	Filename: workarounds.GolangDoesnotAllowPointerToStringLiteral("datapoints.csv"),
	Name:     workarounds.GolangDoesnotAllowPointerToStringLiteral("filename-drainer"),
}

// ForwarderLoader loads a CSV forwarder forwarding points from proxy to a file
func ForwarderLoader(forwardTo *config.ForwardTo) (*FilenameForwarder, error) {
	structdefaults.FillDefaultFrom(forwardTo, csvDefaultConfig)
	log.WithField("forwardTo", forwardTo).Info("Creating CSV using final config")
	return NewForwarder(*forwardTo.Name, *forwardTo.Filename)
}

var _ protocol.Forwarder = &FilenameForwarder{}

// FilenameForwarder prints datapoints to a file
type FilenameForwarder struct {
	writeLock   sync.Mutex
	url                   string
	eventURL              string
	defaultAuthToken      string
	tr                    *http.Transport
	client                *http.Client
	userAgent             string
	defaultSource         string
	dimensionSources      []string
	emptyMetricNameFilter dpsink.EmptyMetricFilter

	protoMarshal func(pb proto.Message) ([]byte, error)
	jsonMarshal  func(v interface{}) ([]byte, error)
}

var defaultConfigV2 = &config.ForwardTo{
	URL:               workarounds.GolangDoesnotAllowPointerToStringLiteral("https://ingest.signalfx.com/v2/datapoint"),
	EventURL:          workarounds.GolangDoesnotAllowPointerToStringLiteral("https://api.signalfx.com/v1/event"),
	DefaultSource:     workarounds.GolangDoesnotAllowPointerToStringLiteral(""),
	MetricCreationURL: workarounds.GolangDoesnotAllowPointerToStringLiteral(""), // Not used
	TimeoutDuration:   workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Second * 60),
	BufferSize:        workarounds.GolangDoesnotAllowPointerToUintLiteral(uint32(1000000)),
	DrainingThreads:   workarounds.GolangDoesnotAllowPointerToUintLiteral(uint32(10)),
	Name:              workarounds.GolangDoesnotAllowPointerToStringLiteral("signalfx-forwarder"),
	MaxDrainSize:      workarounds.GolangDoesnotAllowPointerToUintLiteral(uint32(3000)),
	SourceDimensions:  workarounds.GolangDoesnotAllowPointerToStringLiteral(""),
	FormatVersion:     workarounds.GolangDoesnotAllowPointerToUintLiteral(uint32(3)),
}

// ForwarderLoader loads a json forwarder forwarding points from proxy to SignalFx
func ForwarderLoader(ctx context.Context, forwardTo *config.ForwardTo) (protocol.Forwarder, error) {
	f, _, err := ForwarderLoader1(ctx, forwardTo)
Exemplo n.º 21
0
func TestMetricTypeFromDsType(t *testing.T) {
	assert.Equal(t, datapoint.Gauge, metricTypeFromDsType(workarounds.GolangDoesnotAllowPointerToStringLiteral("gauge")), "Types don't match expectation")
	assert.Equal(t, datapoint.Gauge, metricTypeFromDsType(nil), "Types don't match expectation")
	assert.Equal(t, datapoint.Gauge, metricTypeFromDsType(workarounds.GolangDoesnotAllowPointerToStringLiteral("unknown")), "Types don't match expectation")
	assert.Equal(t, datapoint.Counter, metricTypeFromDsType(workarounds.GolangDoesnotAllowPointerToStringLiteral("derive")), "Types don't match expectation")
}
			defaultDims[key] = value
		}
	}
	return defaultDims
}

// Stats about this decoder, including how many datapoints it decoded
func (decoder *JSONDecoder) Stats(dimensions map[string]string) []*datapoint.Datapoint {
	return []*datapoint.Datapoint{
		datapoint.New("total_blank_dims", dimensions, datapoint.NewIntValue(decoder.TotalBlankDims), datapoint.Counter, time.Now()),
		datapoint.New("invalid_collectd_json", dimensions, datapoint.NewIntValue(decoder.TotalErrors), datapoint.Counter, time.Now()),
	}
}

var defaultCollectdConfig = &config.ListenFrom{
	ListenAddr:      workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:8081"),
	TimeoutDuration: workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Second * 30),
	ListenPath:      workarounds.GolangDoesnotAllowPointerToStringLiteral("/post-collectd"),
	Name:            workarounds.GolangDoesnotAllowPointerToStringLiteral("collectd"),
	JSONEngine:      workarounds.GolangDoesnotAllowPointerToStringLiteral("native"),
}

// ListenerLoader loads a listener for collectd write_http protocol
func ListenerLoader(ctx context.Context, sink dpsink.Sink, listenFrom *config.ListenFrom) (*ListenerServer, error) {
	structdefaults.FillDefaultFrom(listenFrom, defaultCollectdConfig)
	log.WithField("listenFrom", listenFrom).Info("Creating listener using final config")
	return StartListeningCollectDHTTPOnPort(ctx, sink, *listenFrom.ListenAddr, *listenFrom.ListenPath, *listenFrom.TimeoutDuration, *listenFrom.Name)
}

// StartListeningCollectDHTTPOnPort servers http collectd requests
func StartListeningCollectDHTTPOnPort(ctx context.Context, sink dpsink.Sink,
Exemplo n.º 23
0
		}
		for _, jsonDatapoint := range datapoints {
			v, err := ValueToValue(jsonDatapoint.Value)
			if err != nil {
				log.WithField("err", err).Warn("Unable to get value for datapoint")
			} else {
				dp := datapoint.New(jsonDatapoint.Metric, jsonDatapoint.Dimensions, v, fromMT(com_signalfx_metrics_protobuf.MetricType(mt)), fromTs(jsonDatapoint.Timestamp))
				dps = append(dps, dp)
			}
		}
	}
	return decoder.Sink.AddDatapoints(ctx, dps)
}

var defaultConfig = &config.ListenFrom{
	ListenAddr:      workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:12345"),
	TimeoutDuration: workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Second * 30),
	Name:            workarounds.GolangDoesnotAllowPointerToStringLiteral("signalfxlistener"),
	JSONEngine:      workarounds.GolangDoesnotAllowPointerToStringLiteral("native"),
}

// ListenerLoader loads a listener for signalfx protocol from config
func ListenerLoader(ctx context.Context, sink dpsink.Sink, listenFrom *config.ListenFrom) (*ListenerServer, error) {
	structdefaults.FillDefaultFrom(listenFrom, defaultConfig)

	log.WithField("listenFrom", listenFrom).Info("Creating signalfx listener using final config")
	return StartServingHTTPOnPort(ctx, sink, *listenFrom.ListenAddr, *listenFrom.TimeoutDuration, *listenFrom.Name)
}

type jsonMarshalStub func(v interface{}) ([]byte, error)
Exemplo n.º 24
0
			if netErr, ok := err.(net.Error); ok {
				if netErr.Timeout() || netErr.Temporary() {
					atomic.AddInt64(&listener.stats.retriedListenErrors, 1)
					log.Debug("Timeout (or temp) waiting for connection.  Expected, will continue")
					continue
				}
			}
			log.WithField("err", err).Info("Unable to accept a socket connection")
			return
		}
		go listener.handleConnection(conn)
	}
}

var defaultListenerConfig = &config.ListenFrom{
	ListenAddr:                 workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:2003"),
	Name:                       workarounds.GolangDoesnotAllowPointerToStringLiteral("carbonlistener"),
	TimeoutDuration:            workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Second * 30),
	MetricDeconstructor:        workarounds.GolangDoesnotAllowPointerToStringLiteral(""),
	MetricDeconstructorOptions: workarounds.GolangDoesnotAllowPointerToStringLiteral(""),
	ServerAcceptDeadline:       workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Second),
}

// ListenerLoader loads a listener for the carbon/graphite protocol from config
func ListenerLoader(ctx context.Context, sink dpsink.Sink, listenFrom *config.ListenFrom) (*Listener, error) {
	structdefaults.FillDefaultFrom(listenFrom, defaultListenerConfig)
	conf := listenerConfig{
		serverAcceptDeadline: *listenFrom.ServerAcceptDeadline,
		connectionTimeout:    *listenFrom.TimeoutDuration,
		name:                 *listenFrom.Name,
	}