Exemple #1
0
func TestGetFloat(t *testing.T) {
	assert := assert.New(t)

	val := config.GetAsFloat("10", 123)
	assert.Equal(val, 10.0)

	val = config.GetAsFloat("10.21", 123)
	assert.Equal(val, 10.21)

	val = config.GetAsFloat("notanint", 123)
	assert.Equal(val, 123.0)

	val = config.GetAsFloat(12.123, 123)
	assert.Equal(val, 12.123)
}
Exemple #2
0
// Configure accepts the different configuration options for the signalfx handler
func (s *SignalFx) Configure(configMap map[string]interface{}) {
	if authToken, exists := configMap["authToken"]; exists == true {
		s.authToken = authToken.(string)
	} else {
		s.log.Error("There was no auth key specified for the SignalFx Handler, there won't be any emissions")
	}
	if endpoint, exists := configMap["endpoint"]; exists == true {
		s.endpoint = endpoint.(string)
	} else {
		s.log.Error("There was no endpoint specified for the SignalFx Handler, there won't be any emissions")
	}
	if timeout, exists := configMap["timeout"]; exists == true {
		val, err := config.GetAsFloat(timeout)
		if err != nil {
			s.log.Error("Failed to parse the value", timeout, "into a float")
		} else {
			s.timeout = time.Duration(val) * time.Second
		}
	}
	if bufferSize, exists := configMap["max_buffer_size"]; exists == true {
		val, err := config.GetAsInt(bufferSize)
		if err != nil {
			s.log.Error("Failed to parse the value", bufferSize, "into an int")
		} else {
			s.maxBufferSize = val
		}
	}
}
Exemple #3
0
// configureCommonParams will extract the common parameters that are used and set them in the handler
func (base *BaseHandler) configureCommonParams(configMap map[string]interface{}) {
	if asInterface, exists := configMap["timeout"]; exists {
		timeout := config.GetAsFloat(asInterface, DefaultTimeoutSec)
		base.timeout = time.Duration(timeout) * time.Second
	}

	if asInterface, exists := configMap["max_buffer_size"]; exists {
		base.maxBufferSize = config.GetAsInt(asInterface, DefaultBufferSize)
	}

	if asInterface, exists := configMap["interval"]; exists {
		base.interval = config.GetAsInt(asInterface, DefaultInterval)
	}

	// Default dimensions can be extended or overridden on a per handler basis.
	if asInterface, exists := configMap["defaultDimensions"]; exists {
		handlerLevelDimensions := config.GetAsMap(asInterface)
		base.SetDefaultDimensions(handlerLevelDimensions)
	}

	if asInterface, exists := configMap["keepAliveInterval"]; exists {
		keepAliveInterval := config.GetAsInt(asInterface, DefaultKeepAliveInterval)
		base.SetKeepAliveInterval(keepAliveInterval)
	}

	if asInterface, exists := configMap["maxIdleConnectionsPerHost"]; exists {
		maxIdleConnectionsPerHost := config.GetAsInt(asInterface,
			DefaultMaxIdleConnectionsPerHost)
		base.SetMaxIdleConnectionsPerHost(maxIdleConnectionsPerHost)
	}
}