-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
64 lines (55 loc) · 1.63 KB
/
config.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
package serverset
import (
"fmt"
"strings"
"time"
"github.com/influxdata/influxdb/toml"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
)
// Config is a Serverset service discovery configuration
type Config struct {
Enabled bool `toml:"enabled" override:"enabled"`
ID string `toml:"id" override:"id"`
Servers []string `toml:"servers" override:"servers"`
Paths []string `toml:"paths" override:"paths"`
Timeout toml.Duration `toml:"timeout" override:"timeout"`
}
// Init adds default values to Serverset configuration
func (s *Config) Init() {
s.Timeout = toml.Duration(10 * time.Second)
}
// Validate validates Serverset configuration
func (s Config) Validate() error {
if s.ID == "" {
return fmt.Errorf("server set discovery must be given a ID")
}
for _, path := range s.Paths {
if !strings.HasPrefix(path, "/") {
return fmt.Errorf("serverset discovery config paths must begin with '/': %s", path)
}
}
return nil
}
// Prom writes the prometheus configuration for discoverer into ScrapeConfig
func (s Config) Prom(c *config.ScrapeConfig) {
c.ServiceDiscoveryConfig.ServersetSDConfigs = []*config.ServersetSDConfig{
s.PromConfig(),
}
}
// PromConfig returns the prometheus configuration for this discoverer
func (s Config) PromConfig() *config.ServersetSDConfig {
return &config.ServersetSDConfig{
Servers: s.Servers,
Paths: s.Paths,
Timeout: model.Duration(s.Timeout),
}
}
// Service return discoverer type
func (s Config) Service() string {
return "serverset"
}
// ServiceID returns the discoverers name
func (s Config) ServiceID() string {
return s.ID
}