Skip to content

Commit

Permalink
Merge pull request prometheus#13285 from daniel-resdiary/DedupGetNic
Browse files Browse the repository at this point in the history
Dedup code handling getting network interface
  • Loading branch information
roidelapluie authored Dec 18, 2023
2 parents 7600e6c + 0704c72 commit 5d5303c
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions discovery/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5d5303c

Please sign in to comment.