-
Notifications
You must be signed in to change notification settings - Fork 485
/
gce.go
65 lines (56 loc) · 1.93 KB
/
gce.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
62
63
64
65
// Package gce implements the discovery.gce component.
package gce
import (
"time"
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/discovery"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery/gce"
)
func init() {
component.Register(component.Registration{
Name: "discovery.gce",
Args: Arguments{},
Exports: discovery.Exports{},
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
return New(opts, args.(Arguments))
},
})
}
// Arguments configures the discovery.gce component.
type Arguments struct {
Project string `river:"project,attr"`
Zone string `river:"zone,attr"`
Filter string `river:"filter,attr,optional"`
RefreshInterval time.Duration `river:"refresh_interval,attr,optional"`
Port int `river:"port,attr,optional"`
TagSeparator string `river:"tag_separator,attr,optional"`
}
// DefaultArguments holds default values for Arguments.
var DefaultArguments = Arguments{
Port: 80,
TagSeparator: ",",
RefreshInterval: 60 * time.Second,
}
// SetToDefault implements river.Defaulter.
func (args *Arguments) SetToDefault() {
*args = DefaultArguments
}
// Convert converts Arguments to the upstream Prometheus SD type.
func (args Arguments) Convert() gce.SDConfig {
return gce.SDConfig{
Project: args.Project,
Zone: args.Zone,
Filter: args.Filter,
RefreshInterval: model.Duration(args.RefreshInterval),
Port: args.Port,
TagSeparator: args.TagSeparator,
}
}
// New returns a new instance of a discovery.gce component.
func New(opts component.Options, args Arguments) (*discovery.Component, error) {
return discovery.New(opts, args, func(args component.Arguments) (discovery.Discoverer, error) {
conf := args.(Arguments).Convert()
return gce.NewDiscovery(conf, opts.Logger)
})
}