Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0-fr1] [OSPRH-11692] node_exporter scrapeconfig must include full fqdn instead #541

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions controllers/metricstorage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type ConnectionInfo struct {
IP string
Hostname string
TLS bool
FQDN string
}

// GetLogger returns a logger object with a prefix of "conroller.name" and aditional controller context fields
Expand Down Expand Up @@ -646,8 +647,8 @@ func getNodeExporterTargets(nodes []ConnectionInfo) ([]metricstorage.LabeledTarg
nonTLS := []metricstorage.LabeledTarget{}
for _, node := range nodes {
target := metricstorage.LabeledTarget{
IP: fmt.Sprintf("%s:%d", node.IP, telemetryv1.DefaultNodeExporterPort),
Hostname: node.Hostname,
IP: fmt.Sprintf("%s:%d", node.IP, telemetryv1.DefaultNodeExporterPort),
FQDN: node.FQDN,
}
if node.TLS {
tls = append(tls, target)
Expand Down Expand Up @@ -885,17 +886,22 @@ func getComputeNodesConnectionInfo(
// we were unable to find an IP or HostName for a node, so we do not go further
return connectionInfo, fmt.Errorf("failed to find an IP or HostName for node %s", name)
}

fqdn, _ := getCanonicalHostname(&item)

if TLSEnabled, ok := nodeSetGroup.Vars["edpm_tls_certs_enabled"].(bool); ok && TLSEnabled {
connectionInfo = append(connectionInfo, ConnectionInfo{
IP: address,
Hostname: name,
TLS: true,
FQDN: fqdn,
})
} else {
connectionInfo = append(connectionInfo, ConnectionInfo{
IP: address,
Hostname: name,
TLS: false,
FQDN: fqdn,
})
}
}
Expand Down Expand Up @@ -974,6 +980,16 @@ func getAddressFromAnsibleHost(item *ansible.Host) (string, discoveryv1.AddressT
return "", ""
}

func getCanonicalHostname(item *ansible.Host) (string, discoveryv1.AddressType) {
canonicalHostname := item.Vars["canonical_hostname"].(string)
// is it a valid hostname?
if isValidDomain(canonicalHostname) {
// it is an valid domain name
return canonicalHostname, discoveryv1.AddressTypeFQDN
}
return "", ""
}

// isValidDomain returns true if the domain is valid.
func isValidDomain(domain string) bool {
domainRegexp := regexp.MustCompile(`^(?i)[a-z0-9-]+(\.[a-z0-9-]+)+\.?$`)
Expand Down
6 changes: 3 additions & 3 deletions pkg/metricstorage/scrape_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
)

type LabeledTarget struct {
IP string
Hostname string
IP string
FQDN string
}

// ScrapeConfig creates a ScrapeConfig CR
Expand Down Expand Up @@ -69,7 +69,7 @@ func ScrapeConfig(
staticConfigs = append(staticConfigs, monv1alpha1.StaticConfig{
Targets: []monv1alpha1.Target{monv1alpha1.Target(t.IP)},
Labels: map[monv1.LabelName]string{
"hostname": t.Hostname,
"fqdn": t.FQDN,
},
})
}
Expand Down