Пример #1
0
func TestConfigLoad(t *testing.T) {
	c1 := Config{}
	c2 := config.ForwardTo{}
	aOne := uint32(1)
	c2.BufferSize = &aOne
	c2.BufferSize = &aOne
	c2.BufferSize = &aOne
	c2.DrainingThreads = &aOne
	c2.MaxDrainSize = &aOne

	c1.FromConfig(&c2)

	assert.Equal(t, int64(2), c1.BufferSize)
	assert.Equal(t, int64(1), c1.MaxDrainSize)
}
// ForwarderLoader1 is a more strictly typed version of ForwarderLoader
func ForwarderLoader1(ctx context.Context, forwardTo *config.ForwardTo) (protocol.Forwarder, *Forwarder, error) {
	proxyVersion, ok := ctx.Value("version").(string)
	if !ok || proxyVersion == "" {
		proxyVersion = "UNKNOWN_VERSION"
	}
	if forwardTo.FormatVersion == nil {
		forwardTo.FormatVersion = workarounds.GolangDoesnotAllowPointerToUintLiteral(3)
	}
	if *forwardTo.FormatVersion == 1 {
		log.WithField("forwardTo", forwardTo).Warn("Old formats not supported in signalfxforwarder.  Using newer format.  Please update config to use format version 2 or 3")
	}
	structdefaults.FillDefaultFrom(forwardTo, defaultConfigV2)
	log.WithField("forwardTo", forwardTo).Info("Creating signalfx forwarder using final config")
	fwd := NewSignalfxJSONForwarder(*forwardTo.URL, *forwardTo.TimeoutDuration,
		*forwardTo.DefaultAuthToken, *forwardTo.DrainingThreads,
		*forwardTo.DefaultSource, *forwardTo.SourceDimensions, proxyVersion)
	fwd.eventURL = *forwardTo.EventURL
	counter := &dpsink.Counter{}
	dims := protocol.ForwarderDims(*forwardTo.Name, "sfx_protobuf_v2")
	buffer := dpbuffered.NewBufferedForwarder(ctx, *(&dpbuffered.Config{}).FromConfig(forwardTo), fwd)
	return &protocol.CompositeForwarder{
		Sink:   dpsink.FromChain(buffer, dpsink.NextWrap(counter)),
		Keeper: stats.ToKeeperMany(dims, counter, buffer),
		Closer: protocol.CompositeCloser(protocol.OkCloser(buffer.Close)),
	}, fwd, nil
}