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

collector: add more retry when collect metrics #455

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions collector/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,18 @@ func (c *MetricCollectOptions) Prepare(m *Manager, topo *models.TiDBCluster) (ma
for _, prom := range c.monitors {
promAddr = prom
client := &http.Client{Timeout: time.Second * time.Duration(c.opt.APITimeout)}
c.metrics, queryErr = getMetricList(client, promAddr, c.customHeader)
if queryErr == nil {

if err := tiuputils.Retry(
func() error {
c.metrics, queryErr = getMetricList(client, promAddr, c.customHeader)
return queryErr
},
tiuputils.RetryOption{
Attempts: 3,
Delay: time.Microsecond * 300,
Timeout: client.Timeout + 5*time.Second, //make sure the retry timeout is longer than the api timeout
},
); err == nil {
break
}
}
Expand Down Expand Up @@ -424,11 +434,24 @@ func collectMetric(
) {
query := generateQueryWitLabel(mtc, label)
l.Debugf("Querying series of %s...", mtc)
series, err := getSeriesNum(c, promAddr, query, customHeader)
if err != nil {

var series int
if err := tiuputils.Retry(
func() error {
seriesNum, err := getSeriesNum(c, promAddr, query, customHeader)
series = seriesNum
return err
},
tiuputils.RetryOption{
Attempts: 3,
Delay: time.Microsecond * 300,
Timeout: c.Timeout + 5*time.Second, //make sure the retry timeout is longer than the api timeout
},
); err != nil {
l.Errorf("%s", err)
return
}

if series <= 0 {
l.Debugf("metric %s has %d series, ignore", mtc, series)
return
Expand Down Expand Up @@ -513,7 +536,7 @@ func collectMetric(
tiuputils.RetryOption{
Attempts: 3,
Delay: time.Microsecond * 300,
Timeout: time.Second * 120,
Timeout: c.Timeout + 5*time.Second, //make sure the retry timeout is longer than the api timeout
},
); err != nil {
l.Errorf("Error quering metrics %s: %s", mtc, err)
Expand Down
Loading