diff --git a/main.go b/main.go index a74c5e28a..6ce8aadfa 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,10 @@ func main() { log.Fatalf("Error loading configuration from %s: %v", *configFile, err) } - ts := metric.NewTieredStorage(5000, 5000, 100, time.Second*30, time.Second*1, time.Second*20, *metricsStoragePath) + ts, err := metric.NewTieredStorage(5000, 5000, 100, time.Second*30, time.Second*1, time.Second*20, *metricsStoragePath) + if err != nil { + log.Fatalf("Error opening storage: %s", err) + } go ts.Serve() go func() { notifier := make(chan os.Signal) diff --git a/rules/rules_test.go b/rules/rules_test.go index b89d865de..43e8ae554 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -214,7 +214,10 @@ func vectorComparisonString(expected []string, actual []string) string { func TestExpressions(t *testing.T) { temporaryDirectory := test.NewTemporaryDirectory("rule_expression_tests", t) defer temporaryDirectory.Close() - tieredStorage := metric.NewTieredStorage(5000, 5000, 100, time.Second*30, time.Second*1, time.Second*20, temporaryDirectory.Path()) + tieredStorage, err := metric.NewTieredStorage(5000, 5000, 100, time.Second*30, time.Second*1, time.Second*20, temporaryDirectory.Path()) + if err != nil { + t.Fatalf("Error opening storage: %s", err) + } go tieredStorage.Serve() ast.SetStorage(tieredStorage) diff --git a/storage/metric/tiered.go b/storage/metric/tiered.go index 17425386f..c8dc40d1e 100644 --- a/storage/metric/tiered.go +++ b/storage/metric/tiered.go @@ -73,13 +73,13 @@ type Storage interface { GetMetricForFingerprint(model.Fingerprint) (m *model.Metric, err error) } -func NewTieredStorage(appendToMemoryQueueDepth, appendToDiskQueueDepth, viewQueueDepth uint, flushMemoryInterval, writeMemoryInterval, memoryTTL time.Duration, root string) Storage { +func NewTieredStorage(appendToMemoryQueueDepth, appendToDiskQueueDepth, viewQueueDepth uint, flushMemoryInterval, writeMemoryInterval, memoryTTL time.Duration, root string) (storage Storage, err error) { diskStorage, err := NewLevelDBMetricPersistence(root) if err != nil { - panic(err) + return } - return &tieredStorage{ + storage = &tieredStorage{ appendToDiskQueue: make(chan model.Sample, appendToDiskQueueDepth), appendToMemoryQueue: make(chan model.Sample, appendToMemoryQueueDepth), diskStorage: diskStorage, @@ -90,6 +90,7 @@ func NewTieredStorage(appendToMemoryQueueDepth, appendToDiskQueueDepth, viewQueu viewQueue: make(chan viewJob, viewQueueDepth), writeMemoryInterval: writeMemoryInterval, } + return } func (t *tieredStorage) AppendSample(s model.Sample) (err error) { diff --git a/storage/metric/tiered_test.go b/storage/metric/tiered_test.go index b47e93bd2..ed01cab08 100644 --- a/storage/metric/tiered_test.go +++ b/storage/metric/tiered_test.go @@ -35,10 +35,14 @@ func (t testTieredStorageCloser) Close() { func newTestTieredStorage(t test.Tester) (storage Storage, closer test.Closer) { var directory test.TemporaryDirectory directory = test.NewTemporaryDirectory("test_tiered_storage", t) - storage = NewTieredStorage(5000000, 2500, 1000, 5*time.Second, 15*time.Second, 0*time.Second, directory.Path()) + storage, err := NewTieredStorage(5000000, 2500, 1000, 5*time.Second, 15*time.Second, 0*time.Second, directory.Path()) + + if err != nil { + t.Fatalf("Error creating storage: %s", err) + } if storage == nil { - t.Fatalf("%d. storage == nil") + t.Fatalf("storage == nil") } go storage.Serve()