mirror of https://github.com/prometheus/prometheus
sd: change hetzner role type and constants to be exportable
Signed-off-by: Marc Tuduri <marctc@protonmail.com>pull/12620/head
parent
3c80963e81
commit
98383fdc63
|
@ -91,7 +91,7 @@ func (d *hcloudDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, er
|
||||||
targets := make([]model.LabelSet, len(servers))
|
targets := make([]model.LabelSet, len(servers))
|
||||||
for i, server := range servers {
|
for i, server := range servers {
|
||||||
labels := model.LabelSet{
|
labels := model.LabelSet{
|
||||||
hetznerLabelRole: model.LabelValue(hetznerRoleHcloud),
|
hetznerLabelRole: model.LabelValue(HetznerRoleHcloud),
|
||||||
hetznerLabelServerID: model.LabelValue(fmt.Sprintf("%d", server.ID)),
|
hetznerLabelServerID: model.LabelValue(fmt.Sprintf("%d", server.ID)),
|
||||||
hetznerLabelServerName: model.LabelValue(server.Name),
|
hetznerLabelServerName: model.LabelValue(server.Name),
|
||||||
hetznerLabelDatacenter: model.LabelValue(server.Datacenter.Name),
|
hetznerLabelDatacenter: model.LabelValue(server.Datacenter.Name),
|
||||||
|
|
|
@ -57,7 +57,7 @@ type SDConfig struct {
|
||||||
|
|
||||||
RefreshInterval model.Duration `yaml:"refresh_interval"`
|
RefreshInterval model.Duration `yaml:"refresh_interval"`
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
Role role `yaml:"role"`
|
Role Role `yaml:"role"`
|
||||||
hcloudEndpoint string // For tests only.
|
hcloudEndpoint string // For tests only.
|
||||||
robotEndpoint string // For tests only.
|
robotEndpoint string // For tests only.
|
||||||
}
|
}
|
||||||
|
@ -74,26 +74,26 @@ type refresher interface {
|
||||||
refresh(context.Context) ([]*targetgroup.Group, error)
|
refresh(context.Context) ([]*targetgroup.Group, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// role is the role of the target within the Hetzner Ecosystem.
|
// Role is the Role of the target within the Hetzner Ecosystem.
|
||||||
type role string
|
type Role string
|
||||||
|
|
||||||
// The valid options for role.
|
// The valid options for role.
|
||||||
const (
|
const (
|
||||||
// Hetzner Robot Role (Dedicated Server)
|
// Hetzner Robot Role (Dedicated Server)
|
||||||
// https://robot.hetzner.com
|
// https://robot.hetzner.com
|
||||||
hetznerRoleRobot role = "robot"
|
HetznerRoleRobot Role = "robot"
|
||||||
// Hetzner Cloud Role
|
// Hetzner Cloud Role
|
||||||
// https://console.hetzner.cloud
|
// https://console.hetzner.cloud
|
||||||
hetznerRoleHcloud role = "hcloud"
|
HetznerRoleHcloud Role = "hcloud"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
||||||
func (c *role) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (c *Role) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
if err := unmarshal((*string)(c)); err != nil {
|
if err := unmarshal((*string)(c)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch *c {
|
switch *c {
|
||||||
case hetznerRoleRobot, hetznerRoleHcloud:
|
case HetznerRoleRobot, HetznerRoleHcloud:
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown role %q", *c)
|
return fmt.Errorf("unknown role %q", *c)
|
||||||
|
@ -143,12 +143,12 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*refresh.Discovery, error)
|
||||||
|
|
||||||
func newRefresher(conf *SDConfig, l log.Logger) (refresher, error) {
|
func newRefresher(conf *SDConfig, l log.Logger) (refresher, error) {
|
||||||
switch conf.Role {
|
switch conf.Role {
|
||||||
case hetznerRoleHcloud:
|
case HetznerRoleHcloud:
|
||||||
if conf.hcloudEndpoint == "" {
|
if conf.hcloudEndpoint == "" {
|
||||||
conf.hcloudEndpoint = hcloud.Endpoint
|
conf.hcloudEndpoint = hcloud.Endpoint
|
||||||
}
|
}
|
||||||
return newHcloudDiscovery(conf, l)
|
return newHcloudDiscovery(conf, l)
|
||||||
case hetznerRoleRobot:
|
case HetznerRoleRobot:
|
||||||
if conf.robotEndpoint == "" {
|
if conf.robotEndpoint == "" {
|
||||||
conf.robotEndpoint = "https://robot-ws.your-server.de"
|
conf.robotEndpoint = "https://robot-ws.your-server.de"
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (d *robotDiscovery) refresh(context.Context) ([]*targetgroup.Group, error)
|
||||||
targets := make([]model.LabelSet, len(servers))
|
targets := make([]model.LabelSet, len(servers))
|
||||||
for i, server := range servers {
|
for i, server := range servers {
|
||||||
labels := model.LabelSet{
|
labels := model.LabelSet{
|
||||||
hetznerLabelRole: model.LabelValue(hetznerRoleRobot),
|
hetznerLabelRole: model.LabelValue(HetznerRoleRobot),
|
||||||
hetznerLabelServerID: model.LabelValue(strconv.Itoa(server.Server.ServerNumber)),
|
hetznerLabelServerID: model.LabelValue(strconv.Itoa(server.Server.ServerNumber)),
|
||||||
hetznerLabelServerName: model.LabelValue(server.Server.ServerName),
|
hetznerLabelServerName: model.LabelValue(server.Server.ServerName),
|
||||||
hetznerLabelDatacenter: model.LabelValue(strings.ToLower(server.Server.Dc)),
|
hetznerLabelDatacenter: model.LabelValue(strings.ToLower(server.Server.Dc)),
|
||||||
|
|
Loading…
Reference in New Issue