Removed the stats block from client configuration

This commit is contained in:
Diptanu Choudhury 2016-06-16 21:30:29 +01:00
parent ea5d11e628
commit 14747848f7
6 changed files with 32 additions and 101 deletions

View File

@ -360,9 +360,7 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) {
}
conf.ConsulConfig = a.config.Consul
conf.StatsCollectionInterval = a.config.Client.StatsConfig.collectionInterval
conf.StatsCollectionInterval = a.config.Telemetry.collectionInterval
return conf, nil
}

View File

@ -190,14 +190,6 @@ func (c *Command) readConfig() *Config {
}
config.Server.retryInterval = dur
// Parse the stats collection interval
dur, err = time.ParseDuration(config.Client.StatsConfig.CollectionInterval)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error parsing stats collection interval: %s", err))
return nil
}
config.Client.StatsConfig.collectionInterval = dur
// Check that the server is running in at least one mode.
if !(config.Server.Enabled || config.Client.Enabled) {
c.Ui.Error("Must specify either server, client or dev mode for the agent.")

View File

@ -69,6 +69,7 @@ telemetry {
statsite_address = "127.0.0.1:1234"
statsd_address = "127.0.0.1:2345"
disable_hostname = true
collection_interval = "3s"
}
leave_on_interrupt = true
leave_on_terminate = true

View File

@ -130,17 +130,6 @@ type AtlasConfig struct {
Endpoint string `mapstructure:"endpoint"`
}
// StatsConfig determines behavior of resource usage stats collections
type StatsConfig struct {
// DataPoints is the number of data points Nomad client stores in-memory
DataPoints int `mapstructure:"data_points"`
// CollectionInterval is the interval of resource usage stats collection
CollectionInterval string `mapstructure:"collection_interval"`
collectionInterval time.Duration `mapstructure:"_"`
}
// ClientConfig is configuration specific to the client mode
type ClientConfig struct {
// Enabled controls if we are a client
@ -188,10 +177,6 @@ type ClientConfig struct {
// be used to target a certain utilization or to prevent Nomad from using a
// particular set of ports.
Reserved *Resources `mapstructure:"reserved"`
// StatsConfig determines behavior of resource usage stats collection in
// Nomad client
StatsConfig *StatsConfig `mapstructure:"stats"`
}
// ServerConfig is configuration specific to the server mode
@ -255,9 +240,11 @@ type ServerConfig struct {
// Telemetry is the telemetry configuration for the server
type Telemetry struct {
StatsiteAddr string `mapstructure:"statsite_address"`
StatsdAddr string `mapstructure:"statsd_address"`
DisableHostname bool `mapstructure:"disable_hostname"`
StatsiteAddr string `mapstructure:"statsite_address"`
StatsdAddr string `mapstructure:"statsd_address"`
DisableHostname bool `mapstructure:"disable_hostname"`
CollectionInterval string `mapstructure:"collection_interval"`
collectionInterval time.Duration `mapstructure:"-"`
}
// Ports is used to encapsulate the various ports we bind to for network
@ -405,11 +392,6 @@ func DefaultConfig() *Config {
ClientMinPort: 14000,
ClientMaxPort: 14512,
Reserved: &Resources{},
StatsConfig: &StatsConfig{
DataPoints: 60,
CollectionInterval: "1s",
collectionInterval: 1 * time.Second,
},
},
Server: &ServerConfig{
Enabled: false,
@ -419,6 +401,10 @@ func DefaultConfig() *Config {
RetryMaxAttempts: 0,
},
SyslogFacility: "LOCAL0",
Telemetry: &Telemetry{
CollectionInterval: "1s",
collectionInterval: 1 * time.Second,
},
}
}
@ -655,9 +641,6 @@ func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig {
if b.Reserved != nil {
result.Reserved = result.Reserved.Merge(b.Reserved)
}
if b.StatsConfig != nil {
result.StatsConfig = result.StatsConfig.Merge(b.StatsConfig)
}
// Add the servers
result.Servers = append(result.Servers, b.Servers...)
@ -694,6 +677,12 @@ func (a *Telemetry) Merge(b *Telemetry) *Telemetry {
if b.DisableHostname {
result.DisableHostname = true
}
if b.CollectionInterval != "" {
result.CollectionInterval = b.CollectionInterval
}
if b.collectionInterval != 0 {
result.collectionInterval = b.collectionInterval
}
return &result
}
@ -787,18 +776,6 @@ func (r *Resources) Merge(b *Resources) *Resources {
return &result
}
func (s *StatsConfig) Merge(b *StatsConfig) *StatsConfig {
result := *s
if b.DataPoints != 0 {
result.DataPoints = b.DataPoints
}
if b.CollectionInterval != "" {
result.CollectionInterval = b.CollectionInterval
result.collectionInterval = b.collectionInterval
}
return &result
}
// LoadConfig loads the configuration at the given path, regardless if
// its a file or directory.
func LoadConfig(path string) (*Config, error) {

View File

@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"time"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/hcl"
@ -376,55 +377,10 @@ func parseClient(result **ClientConfig, list *ast.ObjectList) error {
}
}
// Parse stats config
if o := listVal.Filter("stats"); len(o.Items) > 0 {
if err := parseStats(&config.StatsConfig, o); err != nil {
return multierror.Prefix(err, "stats ->")
}
}
*result = &config
return nil
}
func parseStats(result **StatsConfig, list *ast.ObjectList) error {
list = list.Elem()
if len(list.Items) > 1 {
return fmt.Errorf("only one 'stats' block allowed")
}
// Get our stats object
obj := list.Items[0]
var listVal *ast.ObjectList
if ot, ok := obj.Val.(*ast.ObjectType); ok {
listVal = ot.List
} else {
return fmt.Errorf("client value: should be an object")
}
// check for invalid keys
valid := []string{
"data_points",
"collection_interval",
}
if err := checkHCLKeys(listVal, valid); err != nil {
return err
}
var m map[string]interface{}
if err := hcl.DecodeObject(&m, listVal); err != nil {
return err
}
var stats StatsConfig
if err := mapstructure.WeakDecode(m, &stats); err != nil {
return err
}
*result = &stats
return nil
}
func parseReserved(result **Resources, list *ast.ObjectList) error {
list = list.Elem()
if len(list.Items) > 1 {
@ -536,6 +492,7 @@ func parseTelemetry(result **Telemetry, list *ast.ObjectList) error {
"statsite_address",
"statsd_address",
"disable_hostname",
"collection_interval",
}
if err := checkHCLKeys(listVal, valid); err != nil {
return err
@ -550,6 +507,13 @@ func parseTelemetry(result **Telemetry, list *ast.ObjectList) error {
if err := mapstructure.WeakDecode(m, &telemetry); err != nil {
return err
}
if telemetry.CollectionInterval != "" {
if dur, err := time.ParseDuration(telemetry.CollectionInterval); err != nil {
return fmt.Errorf("error parsing value of %q: %v", "collection_interval", err)
} else {
telemetry.collectionInterval = dur
}
}
*result = &telemetry
return nil
}

View File

@ -4,6 +4,7 @@ import (
"path/filepath"
"reflect"
"testing"
"time"
"github.com/hashicorp/nomad/nomad/structs/config"
)
@ -65,10 +66,6 @@ func TestConfig_Parse(t *testing.T) {
ReservedPorts: "1,100,10-12",
ParsedReservedPorts: []int{1, 10, 11, 12, 100},
},
StatsConfig: &StatsConfig{
DataPoints: 35,
CollectionInterval: "5s",
},
},
Server: &ServerConfig{
Enabled: true,
@ -86,9 +83,11 @@ func TestConfig_Parse(t *testing.T) {
RetryMaxAttempts: 3,
},
Telemetry: &Telemetry{
StatsiteAddr: "127.0.0.1:1234",
StatsdAddr: "127.0.0.1:2345",
DisableHostname: true,
StatsiteAddr: "127.0.0.1:1234",
StatsdAddr: "127.0.0.1:2345",
DisableHostname: true,
CollectionInterval: "3s",
collectionInterval: 3 * time.Second,
},
LeaveOnInt: true,
LeaveOnTerm: true,