mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
discovery/azure:optimize iteration logic for VMScalesets, VMScalesetVMs, and VMs (#5363)
Signed-off-by: tariqibrahim <tariq181290@gmail.com>
This commit is contained in:
parent
b7e978d255
commit
0d7104b7eb
|
@ -421,22 +421,15 @@ func (client *azureClient) getVMs(ctx context.Context) ([]virtualMachine, error)
|
||||||
var vms []virtualMachine
|
var vms []virtualMachine
|
||||||
result, err := client.vm.ListAll(ctx)
|
result, err := client.vm.ListAll(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not list virtual machines: %s", err)
|
return nil, fmt.Errorf("could not list virtual machines: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
for result.NotDone() {
|
||||||
for _, vm := range result.Values() {
|
for _, vm := range result.Values() {
|
||||||
vms = append(vms, mapFromVM(vm))
|
vms = append(vms, mapFromVM(vm))
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we still have results, keep going until we have no more.
|
|
||||||
for result.NotDone() {
|
|
||||||
err = result.NextWithContext(ctx)
|
err = result.NextWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not list virtual machines: %s", err)
|
return nil, fmt.Errorf("could not list virtual machines: %s", err.Error())
|
||||||
}
|
|
||||||
|
|
||||||
for _, vm := range result.Values() {
|
|
||||||
vms = append(vms, mapFromVM(vm))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,16 +440,14 @@ func (client *azureClient) getScaleSets(ctx context.Context) ([]compute.VirtualM
|
||||||
var scaleSets []compute.VirtualMachineScaleSet
|
var scaleSets []compute.VirtualMachineScaleSet
|
||||||
result, err := client.vmss.ListAll(ctx)
|
result, err := client.vmss.ListAll(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not list virtual machine scale sets: %s", err)
|
return nil, fmt.Errorf("could not list virtual machine scale sets: %s", err.Error())
|
||||||
}
|
}
|
||||||
scaleSets = append(scaleSets, result.Values()...)
|
|
||||||
|
|
||||||
for result.NotDone() {
|
for result.NotDone() {
|
||||||
|
scaleSets = append(scaleSets, result.Values()...)
|
||||||
err = result.NextWithContext(ctx)
|
err = result.NextWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not list virtual machine scale sets: %s", err)
|
return nil, fmt.Errorf("could not list virtual machine scale sets: %s", err.Error())
|
||||||
}
|
}
|
||||||
scaleSets = append(scaleSets, result.Values()...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return scaleSets, nil
|
return scaleSets, nil
|
||||||
|
@ -473,21 +464,15 @@ func (client *azureClient) getScaleSetVMs(ctx context.Context, scaleSet compute.
|
||||||
|
|
||||||
result, err := client.vmssvm.List(ctx, r.ResourceGroup, *(scaleSet.Name), "", "", "")
|
result, err := client.vmssvm.List(ctx, r.ResourceGroup, *(scaleSet.Name), "", "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not list virtual machine scale set vms: %s", err)
|
return nil, fmt.Errorf("could not list virtual machine scale set vms: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
for result.NotDone() {
|
||||||
for _, vm := range result.Values() {
|
for _, vm := range result.Values() {
|
||||||
vms = append(vms, mapFromVMScaleSetVM(vm, *scaleSet.Name))
|
vms = append(vms, mapFromVMScaleSetVM(vm, *scaleSet.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
for result.NotDone() {
|
|
||||||
err = result.NextWithContext(ctx)
|
err = result.NextWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not list virtual machine scale set vms: %s", err)
|
return nil, fmt.Errorf("could not list virtual machine scale set vms: %s", err.Error())
|
||||||
}
|
|
||||||
|
|
||||||
for _, vm := range result.Values() {
|
|
||||||
vms = append(vms, mapFromVMScaleSetVM(vm, *scaleSet.Name))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue