Skip to content

Commit

Permalink
UCP #1753: add timeout config for query metrics from Prometheus (#2107)
Browse files Browse the repository at this point in the history
Signed-off-by: Qiannan Lyu <lvqiannan@gmail.com>

Co-authored-by: Qiannan Lyu <lvqiannan@gmail.com>
  • Loading branch information
sre-bot and hsqlu authored Apr 2, 2020
1 parent c4ce71b commit 02a0ee1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/autoscaler/autoscaler/calculate/calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
package calculate

import (
"context"
"encoding/json"
"fmt"
"math"
"net/http"
"strconv"
"time"

"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
promClient "github.com/prometheus/client_golang/api"
Expand All @@ -33,6 +35,7 @@ const (
queryPath = "/api/v1/query"

float64EqualityThreshold = 1e-9
httpRequestTimeout = 5
)

type SingleQuery struct {
Expand All @@ -46,7 +49,10 @@ type SingleQuery struct {
func queryMetricsFromPrometheus(tac *v1alpha1.TidbClusterAutoScaler, client promClient.Client, sq *SingleQuery, resp *Response) error {
query := sq.Quary
timestamp := sq.Timestamp
req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", sq.Endpoint, queryPath), nil)

ctx, cancel := context.WithTimeout(context.Background(), time.Second*httpRequestTimeout)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s%s", sq.Endpoint, queryPath), nil)
if err != nil {
return err
}
Expand Down

0 comments on commit 02a0ee1

Please sign in to comment.