-
Notifications
You must be signed in to change notification settings - Fork 482
/
http.go
61 lines (51 loc) · 1.66 KB
/
http.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package http
import (
"time"
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/common/config"
"github.com/grafana/agent/component/discovery"
promcfg "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery/http"
)
func init() {
component.Register(component.Registration{
Name: "discovery.http",
Args: Arguments{},
Exports: discovery.Exports{},
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
},
})
}
type Arguments struct {
HTTPClientConfig config.HTTPClientConfig `river:",squash"`
RefreshInterval time.Duration `river:"refresh_interval,attr,optional"`
URL config.URL `river:"url,attr"`
}
var DefaultArguments = Arguments{
RefreshInterval: 60 * time.Second,
HTTPClientConfig: config.DefaultHTTPClientConfig,
}
func (args *Arguments) UnmarshalRiver(f func(interface{}) error) error {
*args = DefaultArguments
type arguments Arguments
if err := f((*arguments)(args)); err != nil {
return err
}
return nil
}
func (args Arguments) Convert() *http.SDConfig {
cfg := &http.SDConfig{
HTTPClientConfig: *args.HTTPClientConfig.Convert(),
URL: args.URL.String(),
RefreshInterval: model.Duration(args.RefreshInterval),
}
return cfg
}
func New(opts component.Options, args Arguments) (component.Component, error) {
return discovery.New(opts, args, func(args component.Arguments) (discovery.Discoverer, error) {
conf := args.(Arguments).Convert()
return http.NewDiscovery(conf, opts.Logger, []promcfg.HTTPClientOption{})
})
}