From 07299cec17e69e6e967dc1d858e05af1adb09621 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 8 Mar 2018 10:49:35 +0100 Subject: [PATCH 1/2] vendor: update tsdb --- vendor/github.com/prometheus/tsdb/compact.go | 7 +++++++ vendor/github.com/prometheus/tsdb/db.go | 10 +++++++--- vendor/github.com/prometheus/tsdb/head.go | 8 ++------ vendor/vendor.json | 6 +++--- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/vendor/github.com/prometheus/tsdb/compact.go b/vendor/github.com/prometheus/tsdb/compact.go index 8ed922946..3668f0831 100644 --- a/vendor/github.com/prometheus/tsdb/compact.go +++ b/vendor/github.com/prometheus/tsdb/compact.go @@ -151,6 +151,13 @@ func (c *LeveledCompactor) Plan(dir string) ([]string, error) { if err != nil { return nil, err } + // We do not include the most recently created block. This gives users a window + // of a full block size to piece-wise backup new data without having to care + // about data overlap. + if len(dirs) < 1 { + return nil, nil + } + dirs = dirs[:len(dirs)-1] var dms []dirMeta diff --git a/vendor/github.com/prometheus/tsdb/db.go b/vendor/github.com/prometheus/tsdb/db.go index 1ac2d425f..489f3a12e 100644 --- a/vendor/github.com/prometheus/tsdb/db.go +++ b/vendor/github.com/prometheus/tsdb/db.go @@ -42,7 +42,7 @@ import ( ) // DefaultOptions used for the DB. They are sane for setups using -// millisecond precision timestampdb. +// millisecond precision timestamps. var DefaultOptions = &Options{ WALFlushInterval: 5 * time.Second, RetentionDuration: 15 * 24 * 60 * 60 * 1000, // 15 days in milliseconds @@ -633,8 +633,9 @@ func (db *DB) EnableCompactions() { level.Info(db.logger).Log("msg", "compactions enabled") } -// Snapshot writes the current data to the directory. -func (db *DB) Snapshot(dir string) error { +// Snapshot writes the current data to the directory. If withHead is set to true it +// will create a new block containing all data that's currently in the memory buffer/WAL. +func (db *DB) Snapshot(dir string, withHead bool) error { if dir == db.dir { return errors.Errorf("cannot snapshot into base directory") } @@ -655,6 +656,9 @@ func (db *DB) Snapshot(dir string) error { return errors.Wrapf(err, "error snapshotting block: %s", b.Dir()) } } + if !withHead { + return nil + } _, err := db.compactor.Write(dir, db.head, db.head.MinTime(), db.head.MaxTime()) return errors.Wrap(err, "snapshot head block") } diff --git a/vendor/github.com/prometheus/tsdb/head.go b/vendor/github.com/prometheus/tsdb/head.go index 4e1bea957..c76c139d5 100644 --- a/vendor/github.com/prometheus/tsdb/head.go +++ b/vendor/github.com/prometheus/tsdb/head.go @@ -265,7 +265,7 @@ func (h *Head) ReadWAL() error { // TODO(fabxc): series entries spread between samples can starve the sample workers. // Even with bufferd channels, this can impact startup time with lots of series churn. - // We must not pralellize series creation itself but could make the indexing asynchronous. + // We must not paralellize series creation itself but could make the indexing asynchronous. seriesFunc := func(series []RefSeries) { for _, s := range series { h.getOrCreateWithID(s.Ref, s.Labels.Hash(), s.Labels) @@ -762,10 +762,6 @@ func (c *safeChunk) Iterator() chunkenc.Iterator { return it } -// func (c *safeChunk) Appender() (chunks.Appender, error) { panic("illegal") } -// func (c *safeChunk) Bytes() []byte { panic("illegal") } -// func (c *safeChunk) Encoding() chunks.Encoding { panic("illegal") } - type headIndexReader struct { head *Head mint, maxt int64 @@ -1259,7 +1255,7 @@ func (s *memSeries) iterator(id int) chunkenc.Iterator { if id-s.firstChunkID < len(s.chunks)-1 { return c.chunk.Iterator() } - // Serve the last 4 samples for the last chunk from the series buffer + // Serve the last 4 samples for the last chunk from the sample buffer // as their compressed bytes may be mutated by added samples. it := &memSafeIterator{ Iterator: c.chunk.Iterator(), diff --git a/vendor/vendor.json b/vendor/vendor.json index 5a7d4afc3..14fa760dc 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -800,10 +800,10 @@ "revisionTime": "2016-04-11T19:08:41Z" }, { - "checksumSHA1": "CeD8QwiLL5CBkWMOfbaJxs4AFuM=", + "checksumSHA1": "zVgXlbZ1J8GhBN7tZji7M/SuiAU=", "path": "github.com/prometheus/tsdb", - "revision": "494acd307058387ced7646f9996b0f7372eaa558", - "revisionTime": "2018-02-15T11:29:47Z" + "revision": "16b2bf1b45ce3e3536c78ebec5116ea09a69786e", + "revisionTime": "2018-03-02T11:51:49Z" }, { "checksumSHA1": "S7F4yWxVLhxQNHMdgoOo6plmOOs=", From 3e6c890aea06a38773e33a309fc373714281cb73 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 8 Mar 2018 11:43:41 +0100 Subject: [PATCH 2/2] api: add flag to skip head on snapshots --- docs/querying/api.md | 3 +- prompb/rpc.pb.go | 93 ++++++++++++++++++++++++++++++-------------- prompb/rpc.pb.gw.go | 20 ++++++---- prompb/rpc.proto | 1 + web/api/v1/api.go | 4 +- web/api/v2/api.go | 4 +- 6 files changed, 85 insertions(+), 40 deletions(-) diff --git a/docs/querying/api.md b/docs/querying/api.md index f53027a56..7f23ec778 100644 --- a/docs/querying/api.md +++ b/docs/querying/api.md @@ -452,9 +452,10 @@ We also expose a gRPC API whose definition can be found [here](https://github.co ### Snapshot Snapshot creates a snapshot of all current data into `snapshots/-` under the TSDB's data directory and returns the directory as response. +It will optionally skip snapshotting data that is only present in the head block, and which has not yet been compacted to disk. ``` -POST /api/v1/admin/tsdb/snapshot +POST /api/v1/admin/tsdb/snapshot?skip_head= ``` ```json diff --git a/prompb/rpc.pb.go b/prompb/rpc.pb.go index ffa2f66df..e8ad8981c 100644 --- a/prompb/rpc.pb.go +++ b/prompb/rpc.pb.go @@ -26,6 +26,7 @@ var _ = math.Inf var _ = time.Kitchen type TSDBSnapshotRequest struct { + SkipHead bool `protobuf:"varint,1,opt,name=skip_head,json=skipHead,proto3" json:"skip_head,omitempty"` } func (m *TSDBSnapshotRequest) Reset() { *m = TSDBSnapshotRequest{} } @@ -245,6 +246,16 @@ func (m *TSDBSnapshotRequest) MarshalTo(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.SkipHead { + dAtA[i] = 0x8 + i++ + if m.SkipHead { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } return i, nil } @@ -388,6 +399,9 @@ func encodeVarintRpc(dAtA []byte, offset int, v uint64) int { func (m *TSDBSnapshotRequest) Size() (n int) { var l int _ = l + if m.SkipHead { + n += 2 + } return n } @@ -481,6 +495,26 @@ func (m *TSDBSnapshotRequest) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: TSDBSnapshotRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SkipHead", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRpc + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.SkipHead = bool(v != 0) default: iNdEx = preIndex skippy, err := skipRpc(dAtA[iNdEx:]) @@ -986,34 +1020,35 @@ var ( func init() { proto.RegisterFile("rpc.proto", fileDescriptorRpc) } var fileDescriptorRpc = []byte{ - // 451 bytes of a gzipped FileDescriptorProto + // 471 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x3d, 0x8f, 0xd3, 0x40, - 0x10, 0xbd, 0xbd, 0x84, 0x83, 0xdb, 0x5c, 0xe5, 0x0b, 0x10, 0x4c, 0x88, 0x83, 0x0b, 0xee, 0x74, - 0x85, 0x57, 0x0a, 0xdd, 0x51, 0x11, 0xae, 0x84, 0x26, 0x49, 0x45, 0x13, 0xad, 0x93, 0xc1, 0xb1, - 0xe4, 0xfd, 0xc0, 0xbb, 0x41, 0x07, 0x25, 0x1d, 0x15, 0x48, 0xfc, 0xa9, 0x48, 0x34, 0x48, 0xf4, - 0x7c, 0x44, 0xfc, 0x10, 0xb4, 0xbb, 0xf6, 0x5d, 0x6c, 0x19, 0x41, 0x37, 0x1e, 0xbf, 0x37, 0x6f, - 0xde, 0x9b, 0xc5, 0x87, 0xb9, 0x5c, 0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0xab, 0xa5, 0xeb, 0x57, 0xe8, + 0x9e, 0xfc, 0x17, 0x57, 0x74, 0x72, 0x62, 0x3a, 0x79, 0xe0, 0x7b, 0x95, 0x4e, 0x66, 0x1a, 0x3f, + 0x55, 0xd7, 0xca, 0xef, 0xf1, 0xa1, 0x75, 0xc8, 0xba, 0xb5, 0xeb, 0x42, 0xcd, 0x39, 0xec, 0xba, + 0x50, 0x67, 0xf1, 0x95, 0x76, 0xbf, 0xa2, 0x9d, 0x1a, 0xd8, 0x54, 0x1a, 0xce, 0x39, 0x3a, 0x1b, + 0xf5, 0xd6, 0xbf, 0x07, 0x7b, 0xeb, 0xcd, 0x00, 0x7d, 0xdb, 0x0c, 0xd0, 0xaf, 0xcd, 0x00, 0xbd, + 0x3c, 0xd0, 0xb5, 0x45, 0x92, 0x1c, 0x98, 0xe3, 0x78, 0xf4, 0x37, 0x00, 0x00, 0xff, 0xff, 0x8b, + 0x21, 0x42, 0x5d, 0xaa, 0x03, 0x00, 0x00, } diff --git a/prompb/rpc.pb.gw.go b/prompb/rpc.pb.gw.go index 71ce638e3..6a4304732 100644 --- a/prompb/rpc.pb.gw.go +++ b/prompb/rpc.pb.gw.go @@ -28,10 +28,18 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray +var ( + filter_Admin_TSDBSnapshot_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + func request_Admin_TSDBSnapshot_0(ctx context.Context, marshaler runtime.Marshaler, client AdminClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq TSDBSnapshotRequest var metadata runtime.ServerMetadata + if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Admin_TSDBSnapshot_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.TSDBSnapshot(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -50,10 +58,8 @@ func request_Admin_DeleteSeries_0(ctx context.Context, marshaler runtime.Marshal var protoReq SeriesDeleteRequest var metadata runtime.ServerMetadata - if req.ContentLength > 0 { - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } msg, err := client.DeleteSeries(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) @@ -100,7 +106,7 @@ func RegisterAdminHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc func RegisterAdminHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AdminClient) error { mux.Handle("POST", pattern_Admin_TSDBSnapshot_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + ctx, cancel := context.WithCancel(ctx) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -129,7 +135,7 @@ func RegisterAdminHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) mux.Handle("POST", pattern_Admin_TSDBCleanTombstones_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + ctx, cancel := context.WithCancel(ctx) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { @@ -158,7 +164,7 @@ func RegisterAdminHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) mux.Handle("POST", pattern_Admin_DeleteSeries_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) + ctx, cancel := context.WithCancel(ctx) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { go func(done <-chan struct{}, closed <-chan bool) { diff --git a/prompb/rpc.proto b/prompb/rpc.proto index a6463fbfb..0c1a52f5a 100644 --- a/prompb/rpc.proto +++ b/prompb/rpc.proto @@ -53,6 +53,7 @@ service Admin { message TSDBSnapshotRequest { + bool skip_head = 1; } message TSDBSnapshotResponse { diff --git a/web/api/v1/api.go b/web/api/v1/api.go index ea48ea47c..50f4ed505 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -657,6 +657,8 @@ func (api *API) snapshot(r *http.Request) (interface{}, *apiError) { if !api.enableAdmin { return nil, &apiError{errorUnavailable, errors.New("Admin APIs disabled")} } + skipHead, _ := strconv.ParseBool(r.FormValue("skip_head")) + db := api.db() if db == nil { return nil, &apiError{errorUnavailable, errors.New("TSDB not ready")} @@ -672,7 +674,7 @@ func (api *API) snapshot(r *http.Request) (interface{}, *apiError) { if err := os.MkdirAll(dir, 0777); err != nil { return nil, &apiError{errorInternal, fmt.Errorf("create snapshot directory: %s", err)} } - if err := db.Snapshot(dir); err != nil { + if err := db.Snapshot(dir, !skipHead); err != nil { return nil, &apiError{errorInternal, fmt.Errorf("create snapshot: %s", err)} } diff --git a/web/api/v2/api.go b/web/api/v2/api.go index ff97661d9..1f0ea1539 100644 --- a/web/api/v2/api.go +++ b/web/api/v2/api.go @@ -167,7 +167,7 @@ func NewAdmin(db func() *tsdb.DB) *Admin { } // TSDBSnapshot implements pb.AdminServer. -func (s *Admin) TSDBSnapshot(_ old_ctx.Context, _ *pb.TSDBSnapshotRequest) (*pb.TSDBSnapshotResponse, error) { +func (s *Admin) TSDBSnapshot(_ old_ctx.Context, req *pb.TSDBSnapshotRequest) (*pb.TSDBSnapshotResponse, error) { db := s.db() if db == nil { return nil, status.Errorf(codes.Unavailable, "TSDB not ready") @@ -182,7 +182,7 @@ func (s *Admin) TSDBSnapshot(_ old_ctx.Context, _ *pb.TSDBSnapshotRequest) (*pb. if err := os.MkdirAll(dir, 0777); err != nil { return nil, status.Errorf(codes.Internal, "created snapshot directory: %s", err) } - if err := db.Snapshot(dir); err != nil { + if err := db.Snapshot(dir, !req.SkipHead); err != nil { return nil, status.Errorf(codes.Internal, "create snapshot: %s", err) } return &pb.TSDBSnapshotResponse{Name: name}, nil