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

Support custom lookback delta from request for query api #5607

Merged
merged 16 commits into from
Aug 23, 2022

Conversation

oronsh
Copy link
Contributor

@oronsh oronsh commented Aug 18, 2022

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

Changes

  • Update prometheus version to v0.38.0.
  • Add support for lookback delta from request for query and grpc apis.
  • Replace engineFactory with lookbackDeltaFactory, getting rid of multiple engines.

As Thanos supports multi tenancy, we would like to have a custom lookback delta for requests per tenant.
As each tenant can have its own scrape interval and requirements.

Prometheus just added support for it recently:
prometheus/prometheus#9946

Verification

@oronsh oronsh changed the title Support lookback delta Support custom lookback delta from request for query api Aug 18, 2022
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.

Thanks for this! It's probably a good idea to also remove the creation of multiple engines in the same go because with only this change it would still be a bit awkward to change this parameter in multiple places. We could simply move the logic from that function to here. What do you think?

@oronsh
Copy link
Contributor Author

oronsh commented Aug 18, 2022

Yes so if I got it right, you suggest to calculate the "dynamic lookback delta" according to maxSourceResolutionMillis logic and pass the value to QueryOpts or override it in case we get it from request params?

@oronsh
Copy link
Contributor Author

oronsh commented Aug 18, 2022

@GiedriusS how do you feel about replacing engineFactory with something like this:

func LookbackDeltaFactory(
	eo promql.EngineOpts,
	dynamicLookbackDelta bool
) func(int64) time.Duration {
	resolutions := []int64{downsample.ResLevel0}
	if dynamicLookbackDelta {
		resolutions = []int64{downsample.ResLevel0, downsample.ResLevel1, downsample.ResLevel2}
	}
	var (
		lds = make([]time.Duration, len(resolutions))
		ld  = eo.LookbackDelta.Milliseconds()
	)

	lookbackDelta := eo.LookbackDelta
	for i, r := range resolutions {
		if ld < r {
			lookbackDelta = time.Duration(r) * time.Millisecond
		}

		lds[i] = lookbackDelta
	}
	return func(maxSourceResolutionMillis int64) time.Duration {
		for i := len(resolutions) - 1; i >= 1; i-- {
			left := resolutions[i-1]
			if resolutions[i-1] < ld {
				left = ld
			}
			if left < maxSourceResolutionMillis {
				return lds[i]
			}
		}
		return lds[0]
	}
}

so we can pass it to QueryApi

@@ -249,6 +250,20 @@ func (qapi *QueryAPI) parseStoreDebugMatchersParam(r *http.Request) (storeMatche
return storeMatchers, nil
}

func (qapi *QueryAPI) parseLookbackDeltaParam(r *http.Request) (time.Duration, *api.ApiError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we also add the same parameter to the gRPC query API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I'll add it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@GiedriusS
Copy link
Member

GiedriusS commented Aug 19, 2022

@GiedriusS how do you feel about replacing engineFactory with something like this:

func LookbackDeltaFactory(
	eo promql.EngineOpts,
	dynamicLookbackDelta bool
) func(int64) time.Duration {
	resolutions := []int64{downsample.ResLevel0}
	if dynamicLookbackDelta {
		resolutions = []int64{downsample.ResLevel0, downsample.ResLevel1, downsample.ResLevel2}
	}
	var (
		lds = make([]time.Duration, len(resolutions))
		ld  = eo.LookbackDelta.Milliseconds()
	)

	lookbackDelta := eo.LookbackDelta
	for i, r := range resolutions {
		if ld < r {
			lookbackDelta = time.Duration(r) * time.Millisecond
		}

		lds[i] = lookbackDelta
	}
	return func(maxSourceResolutionMillis int64) time.Duration {
		for i := len(resolutions) - 1; i >= 1; i-- {
			left := resolutions[i-1]
			if resolutions[i-1] < ld {
				left = ld
			}
			if left < maxSourceResolutionMillis {
				return lds[i]
			}
		}
		return lds[0]
	}
}

so we can pass it to QueryApi

Something like that should work 👍 could you please add unit tests for a such function to ensure that it works properly? Finally, we will be able to get rid of multiple engines. This also means that concurrency limits will finally be enforced properly because previously we had three engines so technically the actual limit was 3 times higher.

@oronsh
Copy link
Contributor Author

oronsh commented Aug 19, 2022

Sure @GiedriusS, I'll add the unit tests :)

@@ -60,6 +62,11 @@ func (g *GRPCAPI) Query(request *querypb.QueryRequest, server querypb.Query_Quer
maxResolution = g.defaultMaxResolutionSeconds.Milliseconds() / 1000
}

lookbackDelta := g.lookbackDeltaCreate(maxResolution)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't it be

lookbackDelta := g.lookbackDeltaCreate(maxResolution * 1000)

since it's lookbackDeltaCreate (and old queryEngine(..)) suppose to receive parameter in millis?

Copy link
Member

@GiedriusS GiedriusS Aug 22, 2022

Choose a reason for hiding this comment

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

That's probably correct but it's the caller's responsibility to pass the proper data and I think the gRPC is unused at the moment. So, I think we should multiply it by 1000. @fpetkovski maybe you know the answer?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I made a mistake to use seconds in the gRPC API when the HTTP one uses millis. Because of this, I also think we should multiply by 1000.

Copy link
Contributor Author

@oronsh oronsh Aug 22, 2022

Choose a reason for hiding this comment

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

@oronsh
Copy link
Contributor Author

oronsh commented Aug 19, 2022

@GiedriusS @fpetkovski I implemented the requests:

  1. Replacing engineFactory with lookbackDeltaFactory.
  2. Adding support for custom lookback delta in grpc

cmd/thanos/query.go Outdated Show resolved Hide resolved
cmd/thanos/query.go Outdated Show resolved Hide resolved
cmd/thanos/query.go Outdated Show resolved Hide resolved
cmd/thanos/query.go Outdated Show resolved Hide resolved
cmd/thanos/query.go Outdated Show resolved Hide resolved
@oronsh oronsh requested review from GiedriusS and fpetkovski and removed request for GiedriusS and fpetkovski August 19, 2022 14:41
@oronsh oronsh requested review from fpetkovski and GiedriusS and removed request for GiedriusS and fpetkovski August 20, 2022 10:49
GiedriusS
GiedriusS previously approved these changes Aug 22, 2022
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.

Solid work, just one unsolved conversation in the gRPC API. 💪

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Add custom lookback delta support in query grpc api

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
@GiedriusS
Copy link
Member

Please use merge commits in the future to update your branch instead of rebasing since the latter recreates commits with new commit IDs and then the reviewers have to look through everything again.

@GiedriusS GiedriusS merged commit 72e9156 into thanos-io:main Aug 23, 2022
@GiedriusS
Copy link
Member

Awesome work plus good cleanup! 💪 thank you.

yeya24 pushed a commit to yeya24/thanos that referenced this pull request Aug 23, 2022
Signed-off-by: Ben Ye <ben.ye@bytedance.com>
@yeya24 yeya24 mentioned this pull request Aug 23, 2022
2 tasks
yeya24 pushed a commit that referenced this pull request Aug 23, 2022
* cut 0.28.0-rc.0

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* address review comments

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* mention experimental/hidden features

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* include #5607 in changelog

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

Signed-off-by: Ben Ye <ben.ye@bytedance.com>
prajain12 pushed a commit to prajain12/thanos that referenced this pull request Sep 6, 2022
)

* Update prometheus version to v0.38.0

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Add custom lookbackDelta from request support for query api

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Add change to CHANGELOG

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Fix tests

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Fix lints

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Replace engineFactory with lookbackDeltaFactory
Add custom lookback delta support in query grpc api

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Replace TestEngineFactory with TestLookbackDeltaFactory test

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Run formatter

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Fix manager_test.go

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Remove engineFactory and adjust comment

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Go fmt query.go

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Fix test and lints

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Remove self-assignment of engineOpts.ActiveQueryTracker

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Fix query.proto backwards compatibility

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Fix comment indentation

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

* Multiply maxResolution by 1000 in grpc api

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>

Signed-off-by: Oron Sharabi <oron.sh@coralogix.com>
Signed-off-by: Prakul Jain <prakul.jain@udaan.com>
squat pushed a commit that referenced this pull request Oct 7, 2022
* Cut 0.28.0-rc.0 (#5632)

* cut 0.28.0-rc.0

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* address review comments

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* mention experimental/hidden features

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* include #5607 in changelog

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* cut v0.28.0 (#5647)

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* Cut 0.28.1 (#5757)

* Updates minio-go to v7.0.37 from v7.0.32 (#5702)

* Updates minio-go to v7.0.37 from v7.0.32

fixes #5701

Changelog: minio/minio-go@v7.0.32...v7.0.37

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>

* Adds changelog entry

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>
Signed-off-by: Ben Ye <benye@amazon.com>

* update changelog and version

Signed-off-by: Ben Ye <benye@amazon.com>

add line

Signed-off-by: Ben Ye <benye@amazon.com>

* update version to 0.28.1

Signed-off-by: Ben Ye <benye@amazon.com>

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>
Signed-off-by: Ben Ye <benye@amazon.com>
Co-authored-by: Sotiris Nanopoulos <sonanopo@microsoft.com>

Signed-off-by: Ben Ye <ben.ye@bytedance.com>
Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>
Signed-off-by: Ben Ye <benye@amazon.com>
Co-authored-by: Ben Ye <ben.ye@bytedance.com>
Co-authored-by: Sotiris Nanopoulos <sonanopo@microsoft.com>
utukJ pushed a commit to utukJ/thanos that referenced this pull request Oct 13, 2022
* Cut 0.28.0-rc.0 (thanos-io#5632)

* cut 0.28.0-rc.0

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* address review comments

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* mention experimental/hidden features

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* include thanos-io#5607 in changelog

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* cut v0.28.0 (thanos-io#5647)

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* Cut 0.28.1 (thanos-io#5757)

* Updates minio-go to v7.0.37 from v7.0.32 (thanos-io#5702)

* Updates minio-go to v7.0.37 from v7.0.32

fixes thanos-io#5701

Changelog: minio/minio-go@v7.0.32...v7.0.37

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>

* Adds changelog entry

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>
Signed-off-by: Ben Ye <benye@amazon.com>

* update changelog and version

Signed-off-by: Ben Ye <benye@amazon.com>

add line

Signed-off-by: Ben Ye <benye@amazon.com>

* update version to 0.28.1

Signed-off-by: Ben Ye <benye@amazon.com>

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>
Signed-off-by: Ben Ye <benye@amazon.com>
Co-authored-by: Sotiris Nanopoulos <sonanopo@microsoft.com>

Signed-off-by: Ben Ye <ben.ye@bytedance.com>
Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>
Signed-off-by: Ben Ye <benye@amazon.com>
Co-authored-by: Ben Ye <ben.ye@bytedance.com>
Co-authored-by: Sotiris Nanopoulos <sonanopo@microsoft.com>
Signed-off-by: utukj <utukphd@gmail.com>
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