@@ -115,7 +115,16 @@ type ResourceSkuRetriever interface {
115115
116116// NewAzureInfoer creates a new instance of the Azure infoer.
117117func NewAzureInfoer (config Config , logger cloudinfo.Logger ) (* AzureInfoer , error ) {
118+ logger .Info ("NewAzureInfoer: config received" , map [string ]interface {}{
119+ "configSubscriptionId" : config .SubscriptionID ,
120+ "configTenantId" : config .TenantID ,
121+ "configClientId" : config .ClientID ,
122+ "hasClientSecret" : config .ClientSecret != "" ,
123+ })
124+
118125 var authorizer autorest.Authorizer
126+ authSource := "none"
127+
119128 if config .ClientID != "" && config .ClientSecret != "" && config .TenantID != "" {
120129 credentialsConfig := auth .NewClientCredentialsConfig (config .ClientID , config .ClientSecret , config .TenantID )
121130 a , err := credentialsConfig .Authorizer ()
@@ -124,18 +133,27 @@ func NewAzureInfoer(config Config, logger cloudinfo.Logger) (*AzureInfoer, error
124133 }
125134
126135 authorizer = a
136+ authSource = "clientCredentials"
137+ logger .Info ("NewAzureInfoer: using client credentials auth" )
127138 }
128139
129140 if authorizer == nil {
141+ logger .Info ("NewAzureInfoer: client credentials not available, trying environment auth" )
130142 a , err := auth .NewAuthorizerFromEnvironment ()
131143 authorizer = a
132144 if err != nil { // Failed to create authorizer from environment, try from file
145+ logger .Info ("NewAzureInfoer: environment auth failed, trying file auth" , map [string ]interface {}{
146+ "envAuthError" : err .Error (),
147+ })
133148 a , err := auth .NewAuthorizerFromFile (azure .PublicCloud .ResourceManagerEndpoint )
134149 if err != nil {
135150 return nil , errors .Wrap (err , "failed to get authorizer from both env and file" )
136151 }
137152
138153 authorizer = a
154+ authSource = "file"
155+ } else {
156+ authSource = "environment"
139157 }
140158 }
141159
@@ -154,6 +172,13 @@ func NewAzureInfoer(config Config, logger cloudinfo.Logger) (*AzureInfoer, error
154172 containerServiceClient := containerservice .NewContainerServicesClient (config .SubscriptionID )
155173 containerServiceClient .Authorizer = authorizer
156174
175+ logger .Info ("NewAzureInfoer: initialized" , map [string ]interface {}{
176+ "authSource" : authSource ,
177+ "subscriptionId" : config .SubscriptionID ,
178+ "tenantId" : config .TenantID ,
179+ "clientId" : config .ClientID ,
180+ })
181+
157182 return & AzureInfoer {
158183 subscriptionId : config .SubscriptionID ,
159184 subscriptionsClient : sClient ,
@@ -576,22 +601,87 @@ func (a *AzureInfoer) addSuffix(mt string, suffixes ...string) []string {
576601
577602func (a * AzureInfoer ) GetVirtualMachines (region string ) ([]types.VMInfo , error ) {
578603 logger := a .log .WithFields (map [string ]interface {}{"region" : region })
579- logger .Debug ("getting product info" )
604+ startTime := time .Now ()
605+
606+ logger .Info ("GetVirtualMachines: starting SKU API call" , map [string ]interface {}{
607+ "subscriptionId" : a .subscriptionId ,
608+ })
580609
581610 skusResultPage , err := a .skusClient .List (context .Background ())
582611 if err != nil {
612+ logger .Error ("GetVirtualMachines: SKU API List() failed" , map [string ]interface {}{
613+ "error" : err .Error (),
614+ "elapsed" : time .Since (startTime ).String (),
615+ })
583616 return nil , err
584617 }
585618
619+ logger .Info ("GetVirtualMachines: SKU API List() returned" , map [string ]interface {}{
620+ "elapsed" : time .Since (startTime ).String (),
621+ "notDone" : skusResultPage .NotDone (),
622+ "hasNextLink" : skusResultPage .Response ().NextLink != nil && len (* skusResultPage .Response ().NextLink ) > 0 ,
623+ })
624+
586625 var virtualMachines []types.VMInfo
626+ totalSKUs := 0
627+ totalPages := 0
628+ resourceTypeCounts := make (map [string ]int )
629+ regionMatchCount := 0
630+ vmSampleNames := make ([]string , 0 , 20 )
631+
632+ // Iterate through ALL pages of SKU results
633+ for ; skusResultPage .NotDone (); err = skusResultPage .NextWithContext (context .Background ()) {
634+ if err != nil {
635+ logger .Error ("GetVirtualMachines: error fetching next SKU page" , map [string ]interface {}{
636+ "page" : totalPages ,
637+ "error" : err .Error (),
638+ "elapsed" : time .Since (startTime ).String (),
639+ })
640+ break
641+ }
587642
588- for _ , sku := range skusResultPage .Values () {
589- for _ , locationInfo := range * sku .LocationInfo {
590- if strings .ToLower (* locationInfo .Location ) == region {
591- if * sku .ResourceType == "virtualMachines" {
592- var memory float64
593- var cpu float64
643+ pageSkus := skusResultPage .Values ()
644+ totalPages ++
645+ totalSKUs += len (pageSkus )
646+
647+ // Check if there's a next page
648+ resp := skusResultPage .Response ()
649+ hasNext := resp .NextLink != nil && len (* resp .NextLink ) > 0
650+
651+ // Log per-page details
652+ logger .Info ("GetVirtualMachines: processing page" , map [string ]interface {}{
653+ "page" : totalPages ,
654+ "pageSKUs" : len (pageSkus ),
655+ "hasNextLink" : hasNext ,
656+ "elapsed" : time .Since (startTime ).String (),
657+ })
658+
659+ pageVMsInRegion := 0
660+ for _ , sku := range pageSkus {
661+ if sku .ResourceType != nil {
662+ resourceTypeCounts [* sku .ResourceType ]++
663+ }
664+
665+ if sku .LocationInfo == nil {
666+ continue
667+ }
668+ for _ , locationInfo := range * sku .LocationInfo {
669+ if locationInfo .Location == nil || strings .ToLower (* locationInfo .Location ) != region {
670+ continue
671+ }
672+ regionMatchCount ++
673+ if sku .ResourceType == nil || * sku .ResourceType != "virtualMachines" {
674+ continue
675+ }
676+
677+ pageVMsInRegion ++
678+ var memory float64
679+ var cpu float64
680+ if sku .Capabilities != nil {
594681 for _ , capabilities := range * sku .Capabilities {
682+ if capabilities .Name == nil || capabilities .Value == nil {
683+ continue
684+ }
595685 switch * capabilities .Name {
596686 case "MemoryGB" :
597687 memory , err = strconv .ParseFloat (* capabilities .Value , 64 )
@@ -607,29 +697,54 @@ func (a *AzureInfoer) GetVirtualMachines(region string) ([]types.VMInfo, error)
607697 }
608698 }
609699 }
610- category , err := a .mapCategory (* sku .Family )
611- if err != nil {
612- logger .Debug (emperror .Wrap (err , "failed to get virtual machine category" ).Error (),
613- map [string ]interface {}{"instanceType" : * sku .Name })
614- }
700+ }
701+ category , err := a .mapCategory (* sku .Family )
702+ if err != nil {
703+ logger .Debug (emperror .Wrap (err , "failed to get virtual machine category" ).Error (),
704+ map [string ]interface {}{"instanceType" : * sku .Name })
705+ }
615706
616- virtualMachines = append (virtualMachines , types.VMInfo {
617- Category : category ,
618- Series : a .mapSeries (* sku .Family ),
619- Type : * sku .Name ,
620- Mem : memory ,
621- Cpus : cpu ,
622- NtwPerf : "1 Gbit/s" ,
623- NtwPerfCat : types .NtwLow ,
624- Zones : * locationInfo .Zones ,
625- Attributes : cloudinfo .Attributes (fmt .Sprint (cpu ), fmt .Sprint (memory ), types .NtwLow , category ),
626- })
707+ virtualMachines = append (virtualMachines , types.VMInfo {
708+ Category : category ,
709+ Series : a .mapSeries (* sku .Family ),
710+ Type : * sku .Name ,
711+ Mem : memory ,
712+ Cpus : cpu ,
713+ NtwPerf : "1 Gbit/s" ,
714+ NtwPerfCat : types .NtwLow ,
715+ Zones : * locationInfo .Zones ,
716+ Attributes : cloudinfo .Attributes (fmt .Sprint (cpu ), fmt .Sprint (memory ), types .NtwLow , category ),
717+ })
718+
719+ // Collect sample VM names (first 20)
720+ if len (vmSampleNames ) < 20 && sku .Name != nil {
721+ vmSampleNames = append (vmSampleNames , * sku .Name )
627722 }
628723 }
629724 }
725+
726+ logger .Info ("GetVirtualMachines: page VMs found" , map [string ]interface {}{
727+ "page" : totalPages ,
728+ "vmsInRegion" : pageVMsInRegion ,
729+ "totalVMsSoFar" : len (virtualMachines ),
730+ })
731+ }
732+
733+ // Log resource type breakdown
734+ topTypes := make ([]string , 0 , len (resourceTypeCounts ))
735+ for rt , count := range resourceTypeCounts {
736+ topTypes = append (topTypes , fmt .Sprintf ("%s=%d" , rt , count ))
630737 }
631738
632- logger .Debug ("found virtual machines" , map [string ]interface {}{"numberOfVms" : len (virtualMachines )})
739+ logger .Info ("GetVirtualMachines: complete" , map [string ]interface {}{
740+ "totalPages" : totalPages ,
741+ "totalSKUs" : totalSKUs ,
742+ "regionMatchSKUs" : regionMatchCount ,
743+ "vmSKUs" : len (virtualMachines ),
744+ "resourceTypes" : fmt .Sprintf ("%v" , topTypes ),
745+ "sampleVMs" : fmt .Sprintf ("%v" , vmSampleNames ),
746+ "elapsed" : time .Since (startTime ).String (),
747+ })
633748 return virtualMachines , nil
634749}
635750
0 commit comments