-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
store: add ability to limit max samples / conc. queries
- Loading branch information
Showing
7 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package store | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/prometheus/pkg/gate" | ||
) | ||
|
||
// Gate wraps the Prometheus gate with extra metrics. | ||
type Gate struct { | ||
g *gate.Gate | ||
currentQueries prometheus.Gauge | ||
} | ||
|
||
// NewGate returns a new gate. | ||
func NewGate(maxConcurrent int, reg prometheus.Registerer) *Gate { | ||
g := &Gate{ | ||
g: gate.New(maxConcurrent), | ||
} | ||
g.currentQueries = prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Name: "thanos_bucket_store_queries_total", | ||
Help: "Total number of currently executing queries.", | ||
}) | ||
|
||
if reg != nil { | ||
reg.MustRegister(g.currentQueries) | ||
} | ||
|
||
return g | ||
} | ||
|
||
// Start iniates a new query. | ||
func (g *Gate) Start(ctx context.Context) error { | ||
g.currentQueries.Inc() | ||
return g.g.Start(ctx) | ||
} | ||
|
||
// Done finishes a query. | ||
func (g *Gate) Done() { | ||
g.currentQueries.Dec() | ||
g.g.Done() | ||
} |