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

Sidecar: use prometheus metrics for min timestamp #7820

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MichaHoffmann
Copy link
Contributor

This PR makes sidecar read "minT" from prometheus metrics instead of the shipper. This has the benefit that it also works for sidecar deployments that do not upload blocks, so that they can be pruned by time range too.

Read "minT" from prometheus metrics so that we also set it for sidecars
that are not uploading blocks.

Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
@MichaHoffmann MichaHoffmann force-pushed the mhoffmann/use-prometheus-tsdb-lowest-timestamp-for-mintime-in-sidecar branch from 51c58f7 to 6cff6e2 Compare October 13, 2024 16:56
Copy link
Contributor

@pedro-stanaka pedro-stanaka left a comment

Choose a reason for hiding this comment

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

LG - some typos though.

// and extracting the prometheus_tsdb_lowest_timestamp_seconds metric from it.
func (c *Client) LowestTimestamp(ctx context.Context, base *url.URL) (int64, error) {
u := *base
u.Path = path.Join(u.Path, "/metrics")
Copy link
Contributor

@pedro-stanaka pedro-stanaka Oct 14, 2024

Choose a reason for hiding this comment

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

Well, it sucks we can't get this from API. I was wondring if we could get those maybe with min(min_over_time(timestamp({__name__!=""}[30d]))), but I guess we would need to know the retention before hand (and it would't be cheap for Prometheus).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah the approach to read it from /metrics is a bit janky, but i cannot think of another one. That query would probably be prohibitively expensive

Copy link
Member

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

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

Why not http://localhost:9090/api/v1/status/tsdb? Should be much faster than gathering all metrics and then parsing them not to mention the overhead of the PromQL engine.

@MichaHoffmann
Copy link
Contributor Author

Why not http://localhost:9090/api/v1/status/tsdb? Should be much faster than gathering all metrics and then parsing them not to mention the overhead of the PromQL engine

It doesn't have this data for whole tsdb. Only for head

if err != nil {
return err
}

if mint < s.limitMinTime.PrometheusTimestamp() {
Copy link
Member

Choose a reason for hiding this comment

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

While going through this function we can probably update to use the min() builtin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, good point; ill update in a bit!

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.

3 participants