fix http client error handling

This commit is contained in:
ytsuchiya 2022-11-21 09:00:18 +09:00
parent 3983758583
commit 925654a748
1 changed files with 9 additions and 4 deletions

View File

@ -7,7 +7,6 @@ import (
"sort"
"sync"
"github.com/pkg/errors"
prom "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"golang.org/x/sync/errgroup"
@ -24,13 +23,19 @@ func (m *merger) merge(ctx context.Context, w io.Writer) error {
g.Go(func() error {
resp, err := m.client.Get(source.url)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("get url: %s", source.url))
fmt.Printf("get url: %s", source.url)
return nil
}
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
}
}(resp.Body)
tp := new(expfmt.TextParser)
out, err := tp.TextToMetricFamilies(resp.Body)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("parse url: %s", source.url))
fmt.Printf("parse url: %s", source.url)
return nil
}
mu.Lock()
defer mu.Unlock()