Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools: Add CLI to create tombstones in obj store #3006

Closed
wants to merge 4 commits into from

Conversation

Harshitha1234
Copy link
Contributor

@Harshitha1234 Harshitha1234 commented Aug 8, 2020

Signed-off-by: Harshitha1234 [email protected]

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

  • Add thanos tools delete command tool to create tombstones in object storage

TODO

  • Refactor tombstone logic into its own package.
  • Write tests.

Verification

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good! 💪 Thanks!

Some suggestions! Can we Un-WIP this? It looks solid! Otherwise what is missing?

kingpin "gopkg.in/alecthomas/kingpin.v2"
)

type Tombstone struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we need Thanos tombstone package (:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

cmd/thanos/tools_delete.go Show resolved Hide resolved
@Harshitha1234 Harshitha1234 marked this pull request as ready for review August 16, 2020 20:01
Signed-off-by: Harshitha1234 <[email protected]>
@Harshitha1234
Copy link
Contributor Author

@bwplotka @metalmatze :)

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, some comments, but overall LGTM (:


ts := tombstone.NewTombstone(*matcher, minTime.PrometheusTimestamp(), maxTime.PrometheusTimestamp())

err = tombstone.UploadTombstone(ts, bkt, logger)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about... return tombstone.Upload.... (:

return err
}

ts := tombstone.NewTombstone(*matcher, minTime.PrometheusTimestamp(), maxTime.PrometheusTimestamp())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think single tombstones can have more than one matcher? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and we check the validity of the user input for the matchers using
_, err = parser.ParseMetricSelector(*matchers) and store them in the form of a string.

)

func registerDelete(m map[string]setupFunc, app *kingpin.CmdClause, pre string) {
cmd := app.Command("delete", "Delete series command")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth to mention

  • from where?
  • is this deleted immediately?
  • where are the detailed docs?


const (
// TombstoneDir is the name of directory to upload tombstones.
TombstoneDir = "tombstones"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe... thanos/tombstones? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated 👍


// Tombstone represents a tombstone.
type Tombstone struct {
Matcher string `json:"matcher"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need slice here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will be slicing the matchers during store API masking and while tombstone creation, we store it as a string. 🙂

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

err = objstore.UploadFile(ctx, logger, bkt, tsPath, path.Join(TombstoneDir, GenName(tombstone)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return?

Matcher: matcher,
MinTime: minTime,
MaxTime: maxTime,
CreationTime: timestamp.FromTime(time.Now()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to Alertmanager Silencers wonder if we can allow specifying human readable reason why like reason field
and author field where people can optionally specify author of deletion.. 🤔 Maybe too much (:

cc @metalmatze

Copy link
Contributor Author

@Harshitha1234 Harshitha1234 Aug 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the author and reason flags 👍


// GenName generates file name based on Matcher, MinTime and MaxTime of a tombstone.
func GenName(ts Tombstone) string {
hash := xxhash.Sum64([]byte(ts.Matcher + string(ts.MinTime) + string(ts.MaxTime)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting (: What's the purpose of this name? Was this logic part of the design? 🤔

The only problem is that it will cause weird errors when someone will try to delete same things. Maybe that's ok - we should at least note it in design or comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a same request is repeated in the future, this logic helps overwrite the previous tombstone file and avoids duplicate tombstones. Yeah sure, will add this to the design proposal. 🙂

return err
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

bkt := objstore.WithNoopInstr(objstore.NewInMemBucket())

{
SampleTombstone := NewTombstone("up{a=\"b\"}", 00, 9999999)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it has to be upper case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope :p


objStoreConfig := regCommonObjStoreFlags(cmd, "", true)

minTime := model.TimeOrDuration(cmd.Flag("min-time", "Start of time range limit to delete. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or 2h45m. Valid duration units are ms, s, m, h, d, w, y.").
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the deletion can be from -10d to -1d? That does not make much sense, right? (: I think we should be explicit in help that -1d will calculate the actual timestamp now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the flag help 👍

@stale
Copy link

stale bot commented Oct 24, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants