Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/discovery/gce/gce.go
4096 views
1
// Package gce implements the discovery.gce component.
2
package gce
3
4
import (
5
"time"
6
7
"github.com/grafana/agent/component"
8
"github.com/grafana/agent/component/discovery"
9
"github.com/grafana/agent/pkg/river"
10
"github.com/prometheus/common/model"
11
"github.com/prometheus/prometheus/discovery/gce"
12
)
13
14
func init() {
15
component.Register(component.Registration{
16
Name: "discovery.gce",
17
Args: Arguments{},
18
Exports: discovery.Exports{},
19
20
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
21
return New(opts, args.(Arguments))
22
},
23
})
24
}
25
26
// Arguments configures the discovery.gce component.
27
type Arguments struct {
28
Project string `river:"project,attr"`
29
Zone string `river:"zone,attr"`
30
Filter string `river:"filter,attr,optional"`
31
RefreshInterval time.Duration `river:"refresh_interval,attr,optional"`
32
Port int `river:"port,attr,optional"`
33
TagSeparator string `river:"tag_separator,attr,optional"`
34
}
35
36
// DefaultArguments holds default values for Arguments.
37
var DefaultArguments = Arguments{
38
Port: 80,
39
TagSeparator: ",",
40
RefreshInterval: 60 * time.Second,
41
}
42
43
var _ river.Unmarshaler = (*Arguments)(nil)
44
45
// UnmarshalRiver implements river.Unmarshaler, applying defaults and
46
// validating the provided config.
47
func (args *Arguments) UnmarshalRiver(f func(interface{}) error) error {
48
*args = DefaultArguments
49
50
type arguments Arguments
51
if err := f((*arguments)(args)); err != nil {
52
return err
53
}
54
return nil
55
}
56
57
// Convert converts Arguments to the upstream Prometheus SD type.
58
func (args Arguments) Convert() gce.SDConfig {
59
return gce.SDConfig{
60
Project: args.Project,
61
Zone: args.Zone,
62
Filter: args.Filter,
63
RefreshInterval: model.Duration(args.RefreshInterval),
64
Port: args.Port,
65
TagSeparator: args.TagSeparator,
66
}
67
}
68
69
// New returns a new instance of a discovery.gce component.
70
func New(opts component.Options, args Arguments) (component.Component, error) {
71
return discovery.New(opts, args, func(args component.Arguments) (discovery.Discoverer, error) {
72
conf := args.(Arguments).Convert()
73
return gce.NewDiscovery(conf, opts.Logger)
74
})
75
}
76
77