promtool: support matchers when querying label values (#10727)

* promtool: support matchers when querying label values

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

* address review comment

Signed-off-by: Ben Ye <ben.ye@bytedance.com>
pull/10746/head
Ben Ye 3 years ago committed by GitHub
parent d3c9c4f574
commit af5ea213f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -151,6 +151,7 @@ func main() {
queryLabelsName := queryLabelsCmd.Arg("name", "Label name to provide label values for.").Required().String() queryLabelsName := queryLabelsCmd.Arg("name", "Label name to provide label values for.").Required().String()
queryLabelsBegin := queryLabelsCmd.Flag("start", "Start time (RFC3339 or Unix timestamp).").String() queryLabelsBegin := queryLabelsCmd.Flag("start", "Start time (RFC3339 or Unix timestamp).").String()
queryLabelsEnd := queryLabelsCmd.Flag("end", "End time (RFC3339 or Unix timestamp).").String() queryLabelsEnd := queryLabelsCmd.Flag("end", "End time (RFC3339 or Unix timestamp).").String()
queryLabelsMatch := queryLabelsCmd.Flag("match", "Series selector. Can be specified multiple times.").Strings()
testCmd := app.Command("test", "Unit testing.") testCmd := app.Command("test", "Unit testing.")
testRulesCmd := testCmd.Command("rules", "Unit tests for rules.") testRulesCmd := testCmd.Command("rules", "Unit tests for rules.")
@ -265,7 +266,7 @@ func main() {
os.Exit(debugAll(*debugAllServer)) os.Exit(debugAll(*debugAllServer))
case queryLabelsCmd.FullCommand(): case queryLabelsCmd.FullCommand():
os.Exit(QueryLabels(*queryLabelsServer, *queryLabelsName, *queryLabelsBegin, *queryLabelsEnd, p)) os.Exit(QueryLabels(*queryLabelsServer, *queryLabelsMatch, *queryLabelsName, *queryLabelsBegin, *queryLabelsEnd, p))
case testRulesCmd.FullCommand(): case testRulesCmd.FullCommand():
os.Exit(RulesUnitTest( os.Exit(RulesUnitTest(
@ -929,7 +930,7 @@ func QuerySeries(url *url.URL, matchers []string, start, end string, p printer)
} }
// QueryLabels queries for label values against a Prometheus server. // QueryLabels queries for label values against a Prometheus server.
func QueryLabels(url *url.URL, name, start, end string, p printer) int { func QueryLabels(url *url.URL, matchers []string, name, start, end string, p printer) int {
if url.Scheme == "" { if url.Scheme == "" {
url.Scheme = "http" url.Scheme = "http"
} }
@ -953,7 +954,7 @@ func QueryLabels(url *url.URL, name, start, end string, p printer) int {
// Run query against client. // Run query against client.
api := v1.NewAPI(c) api := v1.NewAPI(c)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
val, warn, err := api.LabelValues(ctx, name, []string{}, stime, etime) val, warn, err := api.LabelValues(ctx, name, matchers, stime, etime)
cancel() cancel()
for _, v := range warn { for _, v := range warn {

Loading…
Cancel
Save