Skip to content

Commit

Permalink
Added tools bucket marker flag handling for no-downsample.json
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Singh <rohitkochhar@bitgo.com>
  • Loading branch information
Rohit Singh committed Dec 7, 2022
1 parent e6f0b6e commit c9f4934
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cmd/thanos/tools_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (tbc *bucketDownsampleConfig) registerBucketDownsampleFlag(cmd extkingpin.F

func (tbc *bucketMarkBlockConfig) registerBucketMarkBlockFlag(cmd extkingpin.FlagClause) *bucketMarkBlockConfig {
cmd.Flag("id", "ID (ULID) of the blocks to be marked for deletion (repeated flag)").Required().StringsVar(&tbc.blockIDs)
cmd.Flag("marker", "Marker to be put.").Required().EnumVar(&tbc.marker, metadata.DeletionMarkFilename, metadata.NoCompactMarkFilename)
cmd.Flag("marker", "Marker to be put.").Required().EnumVar(&tbc.marker, metadata.DeletionMarkFilename, metadata.NoCompactMarkFilename, metadata.NoDownsampleMarkFilename)
cmd.Flag("details", "Human readable details to be put into marker.").Required().StringVar(&tbc.details)

return tbc
Expand Down Expand Up @@ -1059,6 +1059,10 @@ func registerBucketMarkBlock(app extkingpin.AppClause, objStoreConfig *extflag.P
if err := block.MarkForNoCompact(ctx, logger, bkt, id, metadata.ManualNoCompactReason, tbc.details, promauto.With(nil).NewCounter(prometheus.CounterOpts{})); err != nil {
return errors.Wrapf(err, "mark %v for %v", id, tbc.marker)
}
case metadata.NoDownsampleMarkFilename:
if err := block.MarkForNoDownsample(ctx, logger, bkt, id, metadata.ManualNoDownsampleReason, tbc.details, promauto.With(nil).NewCounter(prometheus.CounterOpts{})); err != nil {
return errors.Wrapf(err, "mark %v for %v", id, tbc.marker)
}
default:
return errors.Errorf("not supported marker %v", tbc.marker)
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,34 @@ func MarkForNoCompact(ctx context.Context, logger log.Logger, bkt objstore.Bucke
level.Info(logger).Log("msg", "block has been marked for no compaction", "block", id)
return nil
}

// MarkForNoDownsample creates a file which marks block to be not downsampled
func MarkForNoDownsample(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid.ULID, reason metadata.NoDownsampleReason, details string, markedForNoDownsample prometheus.Counter) error {
m := path.Join(id.String(), metadata.NoDownsampleMarkFilename)
noDownsampleMarkExists, err := bkt.Exists(ctx, m)
if err != nil {
return errors.Wrapf(err, "check exists %s in bucket", m)
}
if noDownsampleMarkExists {
level.Warn(logger).Log("msg", "requested to mark for no deletion, but file already exists; this should not happen; investigate", "err", errors.Errorf("file %s already exists in bucket", m))
return nil
}
noDownsampleMark, err := json.Marshal(metadata.NoDownsampleMark{
ID: id,
Version: metadata.NoCompactMarkVersion1,

NoDownsampleTime: time.Now().Unix(),
Reason: reason,
Details: details,
})
if err != nil {
return errors.Wrap(err, "json encode no downsample mark")
}

if err := bkt.Upload(ctx, m, bytes.NewBuffer(noDownsampleMark)); err != nil {
return errors.Wrapf(err, "upload file %s to bucket", m)
}
markedForNoDownsample.Inc()
level.Info(logger).Log("msg", "block has been marked for no downsample", "block", id)
return nil
}
23 changes: 22 additions & 1 deletion pkg/block/metadata/markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const (
// NoCompactMarkFilename is the known json filename for optional file storing details about why block has to be excluded from compaction.
// If such file is present in block dir, it means the block has to excluded from compaction (both vertical and horizontal) or rewrite (e.g deletions).
NoCompactMarkFilename = "no-compact-mark.json"

// NoDownsampleMarkFilename is the known json filenanme for optional file storing details about why block has to be excluded from downsampling.
// If such file is present in block dir, it means the block has to be excluded from downsampling.
NoDownsampleMarkFilename = "no-downsample-mark.json"
// DeletionMarkVersion1 is the version of deletion-mark file supported by Thanos.
DeletionMarkVersion1 = 1
// NoCompactMarkVersion1 is the version of no-compact-mark file supported by Thanos.
Expand Down Expand Up @@ -62,9 +64,14 @@ func (m *DeletionMark) markerFilename() string { return DeletionMarkFilename }
// NoCompactReason is a reason for a block to be excluded from compaction.
type NoCompactReason string

// NoDownsampleReason is a reason for a block to be excluded from downsample.
type NoDownsampleReason string

const (
// ManualNoCompactReason is a custom reason of excluding from compaction that should be added when no-compact mark is added for unknown/user specified reason.
ManualNoCompactReason NoCompactReason = "manual"
// ManualNoDownsampleReason is a custom reason of excluding from downsample that should be added when no-downsample mark is added for unknown/user specified reason.
ManualNoDownsampleReason NoDownsampleReason = "manual"
// IndexSizeExceedingNoCompactReason is a reason of index being too big (for example exceeding 64GB limit: https://github.com/thanos-io/thanos/issues/1424)
// This reason can be ignored when vertical block sharding will be implemented.
IndexSizeExceedingNoCompactReason = "index-size-exceeding"
Expand All @@ -86,6 +93,20 @@ type NoCompactMark struct {
Reason NoCompactReason `json:"reason"`
}

// NoDownsampleMark marker stores reason of block being excluded from downsample if needed
type NoDownsampleMark struct {
// ID of the tsdb block.
ID ulid.ULID `json:"id"`
// Version of the file.
Version int `json:"version"`
// Details is a human readable string giving details of reason.
Details string `json:"details,omitempty"`

// NoDownsampleTime is a unix timestamp of when the block was marked for no downsample.
NoDownsampleTime int64 `json:"no_downsample_time"`
Reason NoDownsampleReason `json:"reason"`
}

func (n *NoCompactMark) markerFilename() string { return NoCompactMarkFilename }

// ReadMarker reads the given mark file from <dir>/<marker filename>.json in bucket.
Expand Down

0 comments on commit c9f4934

Please sign in to comment.