Skip to content

Commit

Permalink
re-use http client from driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Gonzalez Labrador committed Jan 19, 2021
1 parent 0bb2971 commit 30f1996
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/metrics/driver/xcloud/xcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,10 @@ type CloudDriver struct {
pullInterval int
CloudData *CloudData
sync.Mutex
client *http.Client
}

func (d *CloudDriver) refresh() error {
// TODO(labkode): spawn goroutines to fetch metrics and update the register service

// get configuration from internal_metrics endpoint exposed
// by the sciencemesh app
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}

// endpoint example: https://mybox.com or https://mybox.com/owncloud
endpoint := fmt.Sprintf("%s/index.php/apps/sciencemesh/internal_metrics", d.instance)
Expand All @@ -78,7 +71,7 @@ func (d *CloudDriver) refresh() error {
return err
}

resp, err := client.Do(req)
resp, err := d.client.Do(req)
if err != nil {
log.Err(err).Msgf("xcloud: error getting internal metrics from %s", d.instance)
return err
Expand Down Expand Up @@ -146,7 +139,7 @@ func (d *CloudDriver) refresh() error {
return err
}

resp, err = client.Do(req)
resp, err = d.client.Do(req)
if err != nil {
log.Err(err).Msgf("xcloud: error registering catalog info to: %s with info: %s", d.catalog, string(j))
return err
Expand Down Expand Up @@ -180,6 +173,14 @@ func (d *CloudDriver) Configure(c *config.Config) error {
d.pullInterval = c.XcloudPullInterval
d.catalog = c.XcloudCatalog

// TODO(labkode): make it configurable once site adopted are prod-ready
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}

d.client = client

ticker := time.NewTicker(time.Duration(d.pullInterval) * time.Second)
quit := make(chan struct{})
go func() {
Expand Down

0 comments on commit 30f1996

Please sign in to comment.