mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promscrape/discovery/eureka: follow-up after eec76718e9
This commit is contained in:
parent
bb2bcb9725
commit
8608e956dd
3 changed files with 43 additions and 46 deletions
|
@ -16,17 +16,11 @@ type apiConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAPIConfig(sdc *SDConfig, baseDir string) (*apiConfig, error) {
|
func newAPIConfig(sdc *SDConfig, baseDir string) (*apiConfig, error) {
|
||||||
var (
|
token := ""
|
||||||
ba *promauth.BasicAuthConfig
|
|
||||||
token string
|
|
||||||
)
|
|
||||||
if sdc.Token != nil {
|
if sdc.Token != nil {
|
||||||
token = *sdc.Token
|
token = *sdc.Token
|
||||||
}
|
}
|
||||||
port := 80
|
var ba *promauth.BasicAuthConfig
|
||||||
if sdc.Port == nil {
|
|
||||||
sdc.Port = &port
|
|
||||||
}
|
|
||||||
if len(sdc.Username) > 0 {
|
if len(sdc.Username) > 0 {
|
||||||
ba = &promauth.BasicAuthConfig{
|
ba = &promauth.BasicAuthConfig{
|
||||||
Username: sdc.Username,
|
Username: sdc.Username,
|
||||||
|
|
|
@ -27,6 +27,7 @@ type SDConfig struct {
|
||||||
// refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option.
|
// refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option.
|
||||||
Port *int `yaml:"port,omitempty"`
|
Port *int `yaml:"port,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type applications struct {
|
type applications struct {
|
||||||
Applications []Application `xml:"application"`
|
Applications []Application `xml:"application"`
|
||||||
}
|
}
|
||||||
|
@ -93,41 +94,42 @@ func GetLabels(sdc *SDConfig, baseDir string) ([]map[string]string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return addInstanceLabels(apps, *sdc.Port), nil
|
port := 80
|
||||||
|
if sdc.Port != nil {
|
||||||
|
port = *sdc.Port
|
||||||
|
}
|
||||||
|
return addInstanceLabels(apps, port), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addInstanceLabels(applications *applications, port int) []map[string]string {
|
func addInstanceLabels(apps *applications, port int) []map[string]string {
|
||||||
var ms []map[string]string
|
var ms []map[string]string
|
||||||
for _, app := range applications.Applications {
|
for _, app := range apps.Applications {
|
||||||
for _, instance := range app.Instances {
|
for _, instance := range app.Instances {
|
||||||
var targetAddress string
|
instancePort := port
|
||||||
if instance.Port.Port > 0 {
|
if instance.Port.Port != 0 {
|
||||||
targetAddress = discoveryutils.JoinHostPort(instance.HostName, instance.Port.Port)
|
instancePort = instance.Port.Port
|
||||||
} else {
|
|
||||||
targetAddress = discoveryutils.JoinHostPort(instance.HostName, port)
|
|
||||||
}
|
}
|
||||||
|
targetAddress := discoveryutils.JoinHostPort(instance.HostName, instancePort)
|
||||||
m := map[string]string{
|
m := map[string]string{
|
||||||
"__address__": targetAddress,
|
"__address__": targetAddress,
|
||||||
"instance": instance.InstanceID,
|
"instance": instance.InstanceID,
|
||||||
"__meta_eureka_app_instance_app_nanem": app.Name,
|
"__meta_eureka_app_name": app.Name,
|
||||||
"__meta_eureka_app_instance_hostname": instance.HostName,
|
"__meta_eureka_app_instance_hostname": instance.HostName,
|
||||||
"__meta_eureka_app_instance_homepage_url": instance.HomePageURL,
|
"__meta_eureka_app_instance_homepage_url": instance.HomePageURL,
|
||||||
"__meta_eureka_app_instance_statuspage_url": instance.StatusPageURL,
|
"__meta_eureka_app_instance_statuspage_url": instance.StatusPageURL,
|
||||||
"__meta_eureka_app_instance_healthcheck_url": instance.HealthCheckURL,
|
"__meta_eureka_app_instance_healthcheck_url": instance.HealthCheckURL,
|
||||||
"__meta_eureka_app_instance_ip_addr": instance.IPAddr,
|
"__meta_eureka_app_instance_ip_addr": instance.IPAddr,
|
||||||
"__meta_eureka_app_instance_vip_address": instance.VipAddress,
|
"__meta_eureka_app_instance_vip_address": instance.VipAddress,
|
||||||
|
"__meta_eureka_app_instance_secure_vip_address": instance.SecureVipAddress,
|
||||||
"__meta_eureka_app_instance_status": instance.Status,
|
"__meta_eureka_app_instance_status": instance.Status,
|
||||||
"__meta_eureka_app_instance_country_id": strconv.Itoa(instance.CountryID),
|
"__meta_eureka_app_instance_country_id": strconv.Itoa(instance.CountryID),
|
||||||
"__meta_eureka_app_instance_id": instance.InstanceID,
|
"__meta_eureka_app_instance_id": instance.InstanceID,
|
||||||
}
|
}
|
||||||
if len(instance.SecureVipAddress) > 0 {
|
if instance.Port.Port != 0 {
|
||||||
m["__meta_eureka_app_instance_secure_vip_address"] = instance.SecureVipAddress
|
|
||||||
}
|
|
||||||
if instance.Port.Port > 0 {
|
|
||||||
m["__meta_eureka_app_instance_port"] = strconv.Itoa(instance.Port.Port)
|
m["__meta_eureka_app_instance_port"] = strconv.Itoa(instance.Port.Port)
|
||||||
m["__meta_eureka_app_instance_port_enabled"] = strconv.FormatBool(instance.Port.Enabled)
|
m["__meta_eureka_app_instance_port_enabled"] = strconv.FormatBool(instance.Port.Enabled)
|
||||||
}
|
}
|
||||||
if instance.SecurePort.Port > 0 {
|
if instance.SecurePort.Port != 0 {
|
||||||
m["__meta_eureka_app_instance_secure_port"] = strconv.Itoa(instance.SecurePort.Port)
|
m["__meta_eureka_app_instance_secure_port"] = strconv.Itoa(instance.SecurePort.Port)
|
||||||
m["__meta_eureka_app_instance_secure_port_enabled"] = strconv.FormatBool(instance.SecurePort.Enabled)
|
m["__meta_eureka_app_instance_secure_port_enabled"] = strconv.FormatBool(instance.SecurePort.Enabled)
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,11 @@ func Test_addInstanceLabels(t *testing.T) {
|
||||||
"__address__": "host-1:9100",
|
"__address__": "host-1:9100",
|
||||||
"instance": "some-id",
|
"instance": "some-id",
|
||||||
"__meta_eureka_app_instance_hostname": "host-1",
|
"__meta_eureka_app_instance_hostname": "host-1",
|
||||||
"__meta_eureka_app_instance_app_nanem": "test-app",
|
"__meta_eureka_app_name": "test-app",
|
||||||
"__meta_eureka_app_instance_healthcheck_url": "some-url",
|
"__meta_eureka_app_instance_healthcheck_url": "some-url",
|
||||||
"__meta_eureka_app_instance_ip_addr": "10.15.11.11",
|
"__meta_eureka_app_instance_ip_addr": "10.15.11.11",
|
||||||
"__meta_eureka_app_instance_vip_address": "10.15.11.11",
|
"__meta_eureka_app_instance_vip_address": "10.15.11.11",
|
||||||
|
"__meta_eureka_app_instance_secure_vip_address": "",
|
||||||
"__meta_eureka_app_instance_country_id": "5",
|
"__meta_eureka_app_instance_country_id": "5",
|
||||||
"__meta_eureka_app_instance_homepage_url": "some-home-url",
|
"__meta_eureka_app_instance_homepage_url": "some-home-url",
|
||||||
"__meta_eureka_app_instance_statuspage_url": "some-status-url",
|
"__meta_eureka_app_instance_statuspage_url": "some-status-url",
|
||||||
|
|
Loading…
Reference in a new issue