From 0704c7254876fefbdde85fecb8ad389106312af2 Mon Sep 17 00:00:00 2001 From: Daniel Nicholls Date: Wed, 13 Dec 2023 14:14:01 +0000 Subject: [PATCH] Dedup code handling getting network interface Signed-off-by: Daniel Nicholls --- discovery/azure/azure.go | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/discovery/azure/azure.go b/discovery/azure/azure.go index 4a85db232..2a0f8380b 100644 --- a/discovery/azure/azure.go +++ b/discovery/azure/azure.go @@ -411,29 +411,19 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { } else { if vm.ScaleSet == "" { networkInterface, err = client.getVMNetworkInterfaceByID(ctx, nicID) - if err != nil { - if errors.Is(err, errorNotFound) { - level.Warn(d.logger).Log("msg", "Network interface does not exist", "name", nicID, "err", err) - } else { - ch <- target{labelSet: nil, err: err} - } - // Get out of this routine because we cannot continue without a network interface. - return - } - d.addToCache(nicID, networkInterface) } else { networkInterface, err = client.getVMScaleSetVMNetworkInterfaceByID(ctx, nicID, vm.ScaleSet, vm.InstanceID) - if err != nil { - if errors.Is(err, errorNotFound) { - level.Warn(d.logger).Log("msg", "Network interface does not exist", "name", nicID, "err", err) - } else { - ch <- target{labelSet: nil, err: err} - } - // Get out of this routine because we cannot continue without a network interface. - return + } + if err != nil { + if errors.Is(err, errorNotFound) { + level.Warn(d.logger).Log("msg", "Network interface does not exist", "name", nicID, "err", err) + } else { + ch <- target{labelSet: nil, err: err} } - d.addToCache(nicID, networkInterface) + // Get out of this routine because we cannot continue without a network interface. + return } + d.addToCache(nicID, networkInterface) } if networkInterface.Properties == nil {