// NewConfig returns a new Config with defaults. func NewConfig() Config { return Config{ Enabled: true, CheckInterval: toml.Duration(DefaultCheckInterval), AdvancePeriod: toml.Duration(DefaultAdvancePeriod), } }
// NewConfig returns an instance of Config with defaults. func NewConfig() Config { return Config{ WriteTimeout: toml.Duration(DefaultWriteTimeout), ShardWriterTimeout: toml.Duration(DefaultShardWriterTimeout), ShardMapperTimeout: toml.Duration(DefaultShardMapperTimeout), QueryTimeout: toml.Duration(DefaultQueryTimeout), MaxRemoteWriteConnections: DefaultMaxRemoteWriteConnections, MaxConcurrentQueries: DefaultMaxConcurrentQueries, MaxSelectPointN: DefaultMaxSelectPointN, MaxSelectSeriesN: DefaultMaxSelectSeriesN, } }
// WithDefaults takes the given config and returns a new config with any required // default values set. func (c *Config) WithDefaults() *Config { d := *c if d.BindAddress == "" { d.BindAddress = DefaultBindAddress } if d.Database == "" { d.Database = DefaultDatabase } if d.Protocol == "" { d.Protocol = DefaultProtocol } if d.BatchSize == 0 { d.BatchSize = DefaultBatchSize } if d.BatchPending == 0 { d.BatchPending = DefaultBatchPending } if d.BatchTimeout == 0 { d.BatchTimeout = toml.Duration(DefaultBatchTimeout) } if d.ConsistencyLevel == "" { d.ConsistencyLevel = DefaultConsistencyLevel } if d.Separator == "" { d.Separator = DefaultSeparator } if d.UDPReadBuffer == 0 { d.UDPReadBuffer = DefaultUDPReadBuffer } return &d }
// NewConfig builds a new configuration with default values. func NewConfig() *Config { return &Config{ RetentionAutoCreate: true, LeaseDuration: toml.Duration(DefaultLeaseDuration), LoggingEnabled: DefaultLoggingEnabled, } }
// NewConfig returns an instance of Config with defaults. func NewConfig() Config { return Config{ StoreEnabled: true, StoreDatabase: DefaultStoreDatabase, StoreInterval: toml.Duration(DefaultStoreInterval), } }
// WithDefaults takes the given config and returns a new config with any required // default values set. func (c *Config) WithDefaults() *Config { d := *c if d.Database == "" { d.Database = DefaultDatabase } if d.BatchSize == 0 { d.BatchSize = DefaultBatchSize } if d.BatchPending == 0 { d.BatchPending = DefaultBatchPending } if d.BatchTimeout == 0 { d.BatchTimeout = toml.Duration(DefaultBatchTimeout) } if d.Precision == "" { d.Precision = DefaultPrecision } if d.ReadBuffer == 0 { d.ReadBuffer = DefaultReadBuffer } if d.UDPPayloadSize == 0 { d.UDPPayloadSize = DefaultUDPPayloadSize } return &d }
// NewConfig returns a new instance of Config with defaults. func NewConfig() Config { return Config{ LogEnabled: true, Enabled: true, RunInterval: toml.Duration(DefaultRunInterval), } }
// NewConfig returns the default configuration for tsdb. func NewConfig() Config { return Config{ Engine: DefaultEngine, WALLoggingEnabled: true, QueryLogEnabled: true, CacheMaxMemorySize: DefaultCacheMaxMemorySize, CacheSnapshotMemorySize: DefaultCacheSnapshotMemorySize, CacheSnapshotWriteColdDuration: toml.Duration(DefaultCacheSnapshotWriteColdDuration), CompactFullWriteColdDuration: toml.Duration(DefaultCompactFullWriteColdDuration), DataLoggingEnabled: true, } }
// NewConfig returns a new instance of Config with defaults. func NewConfig() Config { return Config{ BindAddress: DefaultBindAddress, Database: DefaultDatabase, RetentionPolicy: DefaultRetentionPolicy, BatchSize: DefaultBatchSize, BatchPending: DefaultBatchPending, BatchTimeout: toml.Duration(DefaultBatchTimeout), } }
// NewConfig returns a new instance of Config with defaults. func NewConfig() Config { return Config{ BindAddress: DefaultBindAddress, Database: DefaultDatabase, Protocol: DefaultProtocol, BatchSize: DefaultBatchSize, BatchPending: DefaultBatchPending, BatchTimeout: toml.Duration(DefaultBatchTimeout), ConsistencyLevel: DefaultConsistencyLevel, Separator: DefaultSeparator, } }
// NewConfig returns a new config for the service. func NewConfig() Config { return Config{ BindAddress: DefaultBindAddress, Database: DefaultDatabase, RetentionPolicy: DefaultRetentionPolicy, ConsistencyLevel: DefaultConsistencyLevel, TLSEnabled: false, Certificate: "/etc/ssl/influxdb.pem", BatchSize: DefaultBatchSize, BatchPending: DefaultBatchPending, BatchTimeout: toml.Duration(DefaultBatchTimeout), LogPointErrors: true, } }
// NewConfig returns the default config with temporary paths. func NewConfig() *run.Config { c := run.NewConfig() c.BindAddress = "127.0.0.1:0" c.ReportingDisabled = true c.Cluster.ShardWriterTimeout = toml.Duration(30 * time.Second) c.Cluster.WriteTimeout = toml.Duration(30 * time.Second) c.Meta.Dir = MustTempFile() if !testing.Verbose() { c.Meta.LoggingEnabled = false } c.Data.Dir = MustTempFile() c.Data.WALDir = MustTempFile() c.Data.WALLoggingEnabled = false c.HTTPD.Enabled = true c.HTTPD.BindAddress = "127.0.0.1:0" c.HTTPD.LogEnabled = testing.Verbose() c.Monitor.StoreEnabled = false return c }
func Test_ShardPrecreation(t *testing.T) { t.Parallel() now := time.Now().UTC() advancePeriod := 5 * time.Minute // A test metastaore which returns 2 shard groups, only 1 of which requires a successor. var wg sync.WaitGroup wg.Add(1) ms := metaClient{ PrecreateShardGroupsFn: func(v, u time.Time) error { wg.Done() if u != now.Add(advancePeriod) { t.Fatalf("precreation called with wrong time, got %s, exp %s", u, now) } return nil }, } srv, err := NewService(Config{ CheckInterval: toml.Duration(time.Minute), AdvancePeriod: toml.Duration(advancePeriod), }) if err != nil { t.Fatalf("failed to create shard precreation service: %s", err.Error()) } srv.MetaClient = ms err = srv.precreate(now) if err != nil { t.Fatalf("failed to precreate shards: %s", err.Error()) } wg.Wait() // Ensure metaClient test function is called. return }
func newTestService(batchSize int, batchDuration time.Duration) *testService { s := &testService{ Service: NewService(Config{ BindAddress: "127.0.0.1:0", Database: "collectd_test", BatchSize: batchSize, BatchDuration: toml.Duration(batchDuration), }), } s.Service.PointsWriter = &s.PointsWriter s.Service.MetaClient = &s.MetaClient // Set the collectd types using test string. if err := s.SetTypes(typesDBText); err != nil { panic(err) } if !testing.Verbose() { s.Logger = log.New(ioutil.Discard, "", log.LstdFlags) } return s }
func Test_ServerGraphiteUDP(t *testing.T) { t.Parallel() now := time.Now().UTC().Round(time.Second) config := graphite.Config{} config.Database = "graphitedb" config.BatchSize = 0 // No batching. config.BatchTimeout = toml.Duration(time.Second) config.BindAddress = ":10000" config.Protocol = "udp" service, err := graphite.NewService(config) if err != nil { t.Fatalf("failed to create Graphite service: %s", err.Error()) } // Allow test to wait until points are written. var wg sync.WaitGroup wg.Add(1) pointsWriter := PointsWriter{ WritePointsFn: func(database, retentionPolicy string, consistencyLevel models.ConsistencyLevel, points []models.Point) error { defer wg.Done() pt, _ := models.NewPoint( "cpu", map[string]string{}, map[string]interface{}{"value": 23.456}, time.Unix(now.Unix(), 0)) if database != "graphitedb" { t.Fatalf("unexpected database: %s", database) } else if retentionPolicy != "" { t.Fatalf("unexpected retention policy: %s", retentionPolicy) } else if points[0].String() != pt.String() { t.Fatalf("unexpected points: %#v", points[0].String()) } return nil }, } service.PointsWriter = &pointsWriter dbCreator := DatabaseCreator{} service.MetaClient = &dbCreator if err := service.Open(); err != nil { t.Fatalf("failed to open Graphite service: %s", err.Error()) } if !dbCreator.Created { t.Fatalf("failed to create target database") } // Connect to the graphite endpoint we just spun up _, port, _ := net.SplitHostPort(service.Addr().String()) conn, err := net.Dial("udp", "127.0.0.1:"+port) if err != nil { t.Fatal(err) } data := []byte(`cpu 23.456 `) data = append(data, []byte(fmt.Sprintf("%d", now.Unix()))...) data = append(data, '\n') _, err = conn.Write(data) if err != nil { t.Fatal(err) } wg.Wait() conn.Close() }
// NewConfig returns an instance of Config with defaults. func NewConfig() Config { return Config{Enabled: true, CheckInterval: toml.Duration(30 * time.Minute)} }