-
Notifications
You must be signed in to change notification settings - Fork 18
/
clients.go
43 lines (36 loc) · 1.09 KB
/
clients.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package pusher
import (
"fmt"
"net/url"
"time"
"github.com/grafana/synthetic-monitoring-agent/internal/pkg/prom"
"github.com/grafana/synthetic-monitoring-agent/internal/version"
sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring"
)
func ClientFromRemoteInfo(remote *sm.RemoteInfo) (*prom.ClientConfig, error) {
// TODO(mem): this is hacky.
//
// it's trying to deal with the fact that the URL shown to users
// is not the push URL but the base for the API endpoints
u, err := url.Parse(remote.Url + "/push")
if err != nil {
// XXX(mem): do we really return an error here?
return nil, fmt.Errorf("parsing URL: %w", err)
}
clientCfg := prom.ClientConfig{
URL: u,
Timeout: 5 * time.Second,
UserAgent: version.UserAgent(),
}
if remote.Username != "" {
clientCfg.HTTPClientConfig.BasicAuth = &prom.BasicAuth{
Username: remote.Username,
Password: remote.Password,
}
}
if clientCfg.Headers == nil {
clientCfg.Headers = make(map[string]string)
}
clientCfg.Headers["X-Prometheus-Remote-Write-Version"] = "0.1.0"
return &clientCfg, nil
}