mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Remove MaxConcurrent from the PromQL engine opts (#6712)
Since we use ActiveQueryTracker to check for concurrency in
d992c36b3a
it does not make sense to keep
the MaxConcurrent value as an option of the PromQL engine.
This pull request removes it from the PromQL engine options, sets the
max concurrent metric to -1 if there is no active query tracker, and use
the value of the active query tracker otherwise.
It removes dead code and also will inform people who import the promql
package that we made that change, as it breaks the EngineOpts struct.
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
540dc7dfb0
commit
9adad8ad30
|
@ -357,7 +357,6 @@ func main() {
|
|||
opts = promql.EngineOpts{
|
||||
Logger: log.With(logger, "component", "query engine"),
|
||||
Reg: prometheus.DefaultRegisterer,
|
||||
MaxConcurrent: cfg.queryConcurrency,
|
||||
MaxSamples: cfg.queryMaxSamples,
|
||||
Timeout: time.Duration(cfg.queryTimeout),
|
||||
ActiveQueryTracker: promql.NewActiveQueryTracker(cfg.localStoragePath, cfg.queryConcurrency, log.With(logger, "component", "activeQueryTracker")),
|
||||
|
|
|
@ -31,7 +31,6 @@ func BenchmarkRangeQuery(b *testing.B) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 50000000,
|
||||
Timeout: 100 * time.Second,
|
||||
}
|
||||
|
|
|
@ -217,7 +217,6 @@ func contextErr(err error, env string) error {
|
|||
type EngineOpts struct {
|
||||
Logger log.Logger
|
||||
Reg prometheus.Registerer
|
||||
MaxConcurrent int
|
||||
MaxSamples int
|
||||
Timeout time.Duration
|
||||
ActiveQueryTracker *ActiveQueryTracker
|
||||
|
@ -299,7 +298,12 @@ func NewEngine(opts EngineOpts) *Engine {
|
|||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||
}),
|
||||
}
|
||||
metrics.maxConcurrentQueries.Set(float64(opts.MaxConcurrent))
|
||||
|
||||
if t := opts.ActiveQueryTracker; t != nil {
|
||||
metrics.maxConcurrentQueries.Set(float64(t.GetMaxConcurrent()))
|
||||
} else {
|
||||
metrics.maxConcurrentQueries.Set(-1)
|
||||
}
|
||||
|
||||
if opts.Reg != nil {
|
||||
opts.Reg.MustRegister(
|
||||
|
|
|
@ -41,7 +41,6 @@ func TestQueryConcurrency(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: maxConcurrency,
|
||||
MaxSamples: 10,
|
||||
Timeout: 100 * time.Second,
|
||||
ActiveQueryTracker: queryTracker,
|
||||
|
@ -60,7 +59,7 @@ func TestQueryConcurrency(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
for i := 0; i < opts.MaxConcurrent; i++ {
|
||||
for i := 0; i < maxConcurrency; i++ {
|
||||
q := engine.newTestQuery(f)
|
||||
go q.Exec(ctx)
|
||||
select {
|
||||
|
@ -92,7 +91,7 @@ func TestQueryConcurrency(t *testing.T) {
|
|||
}
|
||||
|
||||
// Terminate remaining queries.
|
||||
for i := 0; i < opts.MaxConcurrent; i++ {
|
||||
for i := 0; i < maxConcurrency; i++ {
|
||||
block <- struct{}{}
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +100,6 @@ func TestQueryTimeout(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 20,
|
||||
MaxSamples: 10,
|
||||
Timeout: 5 * time.Millisecond,
|
||||
}
|
||||
|
@ -129,7 +127,6 @@ func TestQueryCancel(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -200,7 +197,6 @@ func TestQueryError(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -263,7 +259,6 @@ func TestParamsSetCorrectly(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -468,7 +463,6 @@ func TestEngineShutdown(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -1151,7 +1145,6 @@ func TestQueryLogger_basic(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -1203,7 +1196,6 @@ func TestQueryLogger_fields(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -1233,7 +1225,6 @@ func TestQueryLogger_error(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ func TestDeriv(t *testing.T) {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10000,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ type ActiveQueryTracker struct {
|
|||
mmapedFile []byte
|
||||
getNextIndex chan int
|
||||
logger log.Logger
|
||||
maxConcurrent int
|
||||
}
|
||||
|
||||
type Entry struct {
|
||||
|
@ -102,13 +103,13 @@ func getMMapedFile(filename string, filesize int, logger log.Logger) ([]byte, er
|
|||
return fileAsBytes, err
|
||||
}
|
||||
|
||||
func NewActiveQueryTracker(localStoragePath string, maxQueries int, logger log.Logger) *ActiveQueryTracker {
|
||||
func NewActiveQueryTracker(localStoragePath string, maxConcurrent int, logger log.Logger) *ActiveQueryTracker {
|
||||
err := os.MkdirAll(localStoragePath, 0777)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to create directory for logging active queries")
|
||||
}
|
||||
|
||||
filename, filesize := filepath.Join(localStoragePath, "queries.active"), 1+maxQueries*entrySize
|
||||
filename, filesize := filepath.Join(localStoragePath, "queries.active"), 1+maxConcurrent*entrySize
|
||||
logUnfinishedQueries(filename, filesize, logger)
|
||||
|
||||
fileAsBytes, err := getMMapedFile(filename, filesize, logger)
|
||||
|
@ -119,11 +120,12 @@ func NewActiveQueryTracker(localStoragePath string, maxQueries int, logger log.L
|
|||
copy(fileAsBytes, "[")
|
||||
activeQueryTracker := ActiveQueryTracker{
|
||||
mmapedFile: fileAsBytes,
|
||||
getNextIndex: make(chan int, maxQueries),
|
||||
getNextIndex: make(chan int, maxConcurrent),
|
||||
logger: logger,
|
||||
maxConcurrent: maxConcurrent,
|
||||
}
|
||||
|
||||
activeQueryTracker.generateIndices(maxQueries)
|
||||
activeQueryTracker.generateIndices(maxConcurrent)
|
||||
|
||||
return &activeQueryTracker
|
||||
}
|
||||
|
@ -164,12 +166,16 @@ func newJSONEntry(query string, logger log.Logger) []byte {
|
|||
return jsonEntry
|
||||
}
|
||||
|
||||
func (tracker ActiveQueryTracker) generateIndices(maxQueries int) {
|
||||
for i := 0; i < maxQueries; i++ {
|
||||
func (tracker ActiveQueryTracker) generateIndices(maxConcurrent int) {
|
||||
for i := 0; i < maxConcurrent; i++ {
|
||||
tracker.getNextIndex <- 1 + (i * entrySize)
|
||||
}
|
||||
}
|
||||
|
||||
func (tracker ActiveQueryTracker) GetMaxConcurrent() int {
|
||||
return tracker.maxConcurrent
|
||||
}
|
||||
|
||||
func (tracker ActiveQueryTracker) Delete(insertIndex int) {
|
||||
copy(tracker.mmapedFile[insertIndex:], strings.Repeat("\x00", entrySize))
|
||||
tracker.getNextIndex <- insertIndex
|
||||
|
|
|
@ -518,7 +518,6 @@ func (t *Test) clear() {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 20,
|
||||
MaxSamples: 10000,
|
||||
Timeout: 100 * time.Second,
|
||||
}
|
||||
|
@ -632,7 +631,6 @@ func (ll *LazyLoader) clear() {
|
|||
opts := EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 20,
|
||||
MaxSamples: 10000,
|
||||
Timeout: 100 * time.Second,
|
||||
}
|
||||
|
|
|
@ -300,7 +300,6 @@ func TestAlertingRuleDuplicate(t *testing.T) {
|
|||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
|
|
@ -504,7 +504,6 @@ func TestStaleness(t *testing.T) {
|
|||
engineOpts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -691,7 +690,6 @@ func TestUpdate(t *testing.T) {
|
|||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -823,7 +821,6 @@ func TestNotify(t *testing.T) {
|
|||
engineOpts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -891,7 +888,6 @@ func TestMetricsUpdate(t *testing.T) {
|
|||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ func TestRuleEval(t *testing.T) {
|
|||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
@ -101,7 +100,6 @@ func TestRuleEvalDuplicate(t *testing.T) {
|
|||
opts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
|
|
@ -230,7 +230,6 @@ func (m rulesRetrieverMock) RuleGroups() []*rules.Group {
|
|||
engineOpts := promql.EngineOpts{
|
||||
Logger: nil,
|
||||
Reg: nil,
|
||||
MaxConcurrent: 10,
|
||||
MaxSamples: 10,
|
||||
Timeout: 100 * time.Second,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue