From bee6864c14459d2597e1f2e4003318898d90c001 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Sun, 10 Dec 2017 13:19:34 -0600 Subject: [PATCH] Make the date returned by snapshot script friendly Fixes #3568 Signed-off-by: Goutham Veeramachaneni --- docs/querying/api.md | 4 ++-- web/api/v1/api.go | 6 ++++-- web/api/v2/api.go | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/querying/api.md b/docs/querying/api.md index 415ec1d30..f885b110b 100644 --- a/docs/querying/api.md +++ b/docs/querying/api.md @@ -400,12 +400,12 @@ $ curl -XPOST http://localhost:9090/api/v1/admin/tsdb/snapshot { "status": "success", "data": { - "name": "2017-11-30T15:31:59Z-2366f0a55106d6e1" + "name": "20171210T211224Z-2be650b6d019eb54" } } ``` -The snapshot now exists at `/snapshots/2017-11-30T15:31:59Z-2366f0a55106d6e1` +The snapshot now exists at `/snapshots/20171210T211224Z-2be650b6d019eb54` *New in v2.1* diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 56d0d37ed..545d18bd4 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -638,8 +638,10 @@ func (api *API) snapshot(r *http.Request) (interface{}, *apiError) { var ( snapdir = filepath.Join(db.Dir(), "snapshots") - name = fmt.Sprintf("%s-%x", time.Now().UTC().Format(time.RFC3339), rand.Int()) - dir = filepath.Join(snapdir, name) + name = fmt.Sprintf("%s-%x", + time.Now().UTC().Format("20060102T150405Z0700"), + rand.Int()) + dir = filepath.Join(snapdir, name) ) if err := os.MkdirAll(dir, 0777); err != nil { return nil, &apiError{errorInternal, fmt.Errorf("create snapshot directory: %s", err)} diff --git a/web/api/v2/api.go b/web/api/v2/api.go index 41c641de9..79c73831b 100644 --- a/web/api/v2/api.go +++ b/web/api/v2/api.go @@ -174,8 +174,10 @@ func (s *Admin) TSDBSnapshot(_ old_ctx.Context, _ *pb.TSDBSnapshotRequest) (*pb. } var ( snapdir = filepath.Join(db.Dir(), "snapshots") - name = fmt.Sprintf("%s-%x", time.Now().UTC().Format(time.RFC3339), rand.Int()) - dir = filepath.Join(snapdir, name) + name = fmt.Sprintf("%s-%x", + time.Now().UTC().Format("20060102T150405Z0700"), + rand.Int()) + dir = filepath.Join(snapdir, name) ) if err := os.MkdirAll(dir, 0777); err != nil { return nil, status.Errorf(codes.Internal, "created snapshot directory: %s", err)