diff --git a/.gitignore b/.gitignore index 1eb58b3..87a8070 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ config.json migrateTimestamps.pl test_ccms_api.sh test_ccms_free_api.sh +test_ccms_write_api.sh +sample_alex.txt +sample_fritz.txt \ No newline at end of file diff --git a/internal/api/lineprotocol.go b/internal/api/lineprotocol.go index 75d2b20..e05ebbe 100644 --- a/internal/api/lineprotocol.go +++ b/internal/api/lineprotocol.go @@ -313,7 +313,20 @@ func decodeLine(dec *lineprotocol.Decoder, } if t, err = dec.Time(lineprotocol.Second, t); err != nil { - return fmt.Errorf("timestamp : %#v with error : %#v", lineprotocol.Second, err.Error()) + t = time.Now() + if t, err = dec.Time(lineprotocol.Millisecond, t); err != nil { + t = time.Now() + if t, err = dec.Time(lineprotocol.Microsecond, t); err != nil { + t = time.Now() + if t, err = dec.Time(lineprotocol.Nanosecond, t); err != nil { + return fmt.Errorf("timestamp : %#v with error : %#v", t, err.Error()) + } + } + } + } + + if err != nil { + return fmt.Errorf("timestamp : %#v with error : %#v", t, err.Error()) } if err := ms.WriteToLevel(lvl, selector, t.Unix(), []memorystore.Metric{metric}); err != nil { diff --git a/internal/memorystore/checkpoint.go b/internal/memorystore/checkpoint.go index 93585b6..c607c04 100644 --- a/internal/memorystore/checkpoint.go +++ b/internal/memorystore/checkpoint.go @@ -268,6 +268,15 @@ func (l *Level) toCheckpoint(dir string, from, to int64, m *MemoryStore) error { // This function can only be called once and before the very first write or read. // Different host's data is loaded to memory in parallel. func (m *MemoryStore) FromCheckpoint(dir string, from int64) (int, error) { + if _, err := os.Stat(dir); os.IsNotExist(err) { + // The directory does not exist, so create it using os.MkdirAll() + err := os.MkdirAll(dir, 0755) // 0755 sets the permissions for the directory + if err != nil { + log.Fatalf("Error creating directory: %#v\n", err) + } + fmt.Printf("%#v Directory created successfully.\n", dir) + } + var wg sync.WaitGroup work := make(chan [2]string, NumWorkers) n, errs := int32(0), int32(0)