@@ -96,6 +96,13 @@ type MetricStorageReconciler struct {
9696 Cache cache.Cache
9797}
9898
99+ // ConnectionInfo holds information about connection to a compute node
100+ type ConnectionInfo struct {
101+ IP string
102+ Hostname string
103+ TLS bool
104+ }
105+
99106// GetLogger returns a logger object with a prefix of "conroller.name" and aditional controller context fields
100107func (r * MetricStorageReconciler ) GetLogger (ctx context.Context ) logr.Logger {
101108 return log .FromContext (ctx ).WithName ("Controllers" ).WithName ("MetricStorage" )
@@ -506,7 +513,7 @@ func (r *MetricStorageReconciler) createServiceScrapeConfig(
506513 log logr.Logger ,
507514 description string ,
508515 serviceName string ,
509- targets [] string ,
516+ targets interface {} ,
510517 tlsEnabled bool ,
511518) error {
512519 scrapeConfig := & monv1alpha1.ScrapeConfig {
@@ -593,30 +600,31 @@ func (r *MetricStorageReconciler) createScrapeConfigs(
593600 return ctrl.Result {}, err
594601 }
595602
596- // ScrapeConfigs for NodeExporters
597- endpointsNonTLS , endpointsTLS , err := getMetricExporterTargets (instance , helper , telemetryv1 .DefaultNodeExporterPort )
603+ connectionInfo , err := getComputeNodesConnectionInfo (instance , helper )
598604 if err != nil {
599- Log .Info (fmt .Sprintf ("Cannot get node exporter targets . Scrape configs not created. Error: %s" , err ))
605+ Log .Info (fmt .Sprintf ("Cannot get compute node connection info . Scrape configs not created. Error: %s" , err ))
600606 }
601607
608+ // ScrapeConfigs for NodeExporters
609+ neTargetsTLS , neTargetsNonTLS := getNodeExporterTargets (connectionInfo )
602610 // ScrapeConfig for non-tls nodes
603611 neServiceName := fmt .Sprintf ("%s-node-exporter" , telemetry .ServiceName )
604612 err = r .createServiceScrapeConfig (ctx , instance , Log , "Node Exporter" ,
605- neServiceName , endpointsNonTLS , false )
613+ neServiceName , neTargetsNonTLS , false )
606614 if err != nil {
607615 return ctrl.Result {}, err
608616 }
609617
610618 // ScrapeConfig for tls nodes
611619 neServiceName = fmt .Sprintf ("%s-node-exporter-tls" , telemetry .ServiceName )
612620 err = r .createServiceScrapeConfig (ctx , instance , Log , "Node Exporter" ,
613- neServiceName , endpointsTLS , true )
621+ neServiceName , neTargetsTLS , true )
614622 if err != nil {
615623 return ctrl.Result {}, err
616624 }
617625
618626 // kepler scrape endpoints
619- _ , keplerEndpoints , err := getMetricExporterTargets ( instance , helper , telemetryv1 . DefaultKeplerPort )
627+ keplerEndpoints , _ := getKeplerTargets ( connectionInfo )
620628 if err != nil {
621629 Log .Info (fmt .Sprintf ("Cannot get Kepler targets. Scrape configs not created. Error: %s" , err ))
622630 }
@@ -633,6 +641,37 @@ func (r *MetricStorageReconciler) createScrapeConfigs(
633641 return ctrl.Result {}, err
634642}
635643
644+ func getNodeExporterTargets (nodes []ConnectionInfo ) ([]metricstorage.LabeledTarget , []metricstorage.LabeledTarget ) {
645+ tls := []metricstorage.LabeledTarget {}
646+ nonTLS := []metricstorage.LabeledTarget {}
647+ for _ , node := range nodes {
648+ target := metricstorage.LabeledTarget {
649+ IP : fmt .Sprintf ("%s:%d" , node .IP , telemetryv1 .DefaultNodeExporterPort ),
650+ Hostname : node .Hostname ,
651+ }
652+ if node .TLS {
653+ tls = append (tls , target )
654+ } else {
655+ nonTLS = append (nonTLS , target )
656+ }
657+ }
658+ return tls , nonTLS
659+ }
660+
661+ func getKeplerTargets (nodes []ConnectionInfo ) ([]string , []string ) {
662+ tls := []string {}
663+ nonTLS := []string {}
664+ for _ , node := range nodes {
665+ target := fmt .Sprintf ("%s:%d" , node .IP , telemetryv1 .DefaultKeplerPort )
666+ if node .TLS {
667+ tls = append (tls , target )
668+ } else {
669+ nonTLS = append (nonTLS , target )
670+ }
671+ }
672+ return tls , nonTLS
673+ }
674+
636675func (r * MetricStorageReconciler ) createDashboardObjects (ctx context.Context , instance * telemetryv1.MetricStorage , eventHandler handler.EventHandler ) (ctrl.Result , error ) {
637676 Log := r .GetLogger (ctx )
638677 uiPluginObj := & obsui.UIPlugin {
@@ -795,26 +834,24 @@ func (r *MetricStorageReconciler) ensureWatches(
795834 return err
796835}
797836
798- func getMetricExporterTargets (
837+ func getComputeNodesConnectionInfo (
799838 instance * telemetryv1.MetricStorage ,
800839 helper * helper.Helper ,
801- defaultMetricExporterPort int32 ,
802- ) ([]string , []string , error ) {
840+ ) ([]ConnectionInfo , error ) {
803841 ipSetList , err := getIPSetList (instance , helper )
804842 if err != nil {
805- return []string {}, [] string {}, err
843+ return []ConnectionInfo {}, err
806844 }
807845 inventorySecretList , err := getInventorySecretList (instance , helper )
808846 if err != nil {
809- return []string {}, [] string {}, err
847+ return []ConnectionInfo {}, err
810848 }
811849 var address string
812- addressesNonTLS := []string {}
813- addressesTLS := []string {}
850+ connectionInfo := []ConnectionInfo {}
814851 for _ , secret := range inventorySecretList .Items {
815852 inventory , err := ansible .UnmarshalYAML (secret .Data ["inventory" ])
816853 if err != nil {
817- return []string {}, [] string {}, err
854+ return []ConnectionInfo {}, err
818855 }
819856 nodeSetGroup := inventory .Groups [secret .Labels ["openstackdataplanenodeset" ]]
820857 containsTelemetry := false
@@ -842,20 +879,28 @@ func getMetricExporterTargets(
842879 address , _ = getAddressFromAnsibleHost (& item )
843880 } else {
844881 // we were unable to find an IP or HostName for a node, so we do not go further
845- return addressesNonTLS , addressesTLS , fmt .Errorf ("failed to find an IP or HostName for node %s" , name )
882+ return connectionInfo , fmt .Errorf ("failed to find an IP or HostName for node %s" , name )
846883 }
847884 if address == "" {
848885 // we were unable to find an IP or HostName for a node, so we do not go further
849- return addressesNonTLS , addressesTLS , fmt .Errorf ("failed to find an IP or HostName for node %s" , name )
886+ return connectionInfo , fmt .Errorf ("failed to find an IP or HostName for node %s" , name )
850887 }
851888 if TLSEnabled , ok := nodeSetGroup .Vars ["edpm_tls_certs_enabled" ].(bool ); ok && TLSEnabled {
852- addressesTLS = append (addressesTLS , fmt .Sprintf ("%s:%d" , address , defaultMetricExporterPort ))
889+ connectionInfo = append (connectionInfo , ConnectionInfo {
890+ IP : address ,
891+ Hostname : name ,
892+ TLS : true ,
893+ })
853894 } else {
854- addressesNonTLS = append (addressesNonTLS , fmt .Sprintf ("%s:%d" , address , defaultMetricExporterPort ))
895+ connectionInfo = append (connectionInfo , ConnectionInfo {
896+ IP : address ,
897+ Hostname : name ,
898+ TLS : false ,
899+ })
855900 }
856901 }
857902 }
858- return addressesNonTLS , addressesTLS , nil
903+ return connectionInfo , nil
859904}
860905
861906func getIPSetList (instance * telemetryv1.MetricStorage , helper * helper.Helper ) (* infranetworkv1.IPSetList , error ) {
0 commit comments