Repository: prometheus/prometheus (language: go)

Issue:
Azure SD with Public IP Address: panic: runtime error: invalid memory address or nil pointer dereference
## Version
Docker image `prom/prometheus`, tags `latest` and `main`, both have the same problem.

## Problem
We're receiving a panic from Azure SD plugin whenever it tries to enumerate our VMs. The problem is caused by an incorrect nil check as seen below:

https://github.com/prometheus/prometheus/blob/579331446a04503b2b1515767e7ceaceab2c6342/discovery/azure/azure.go#L374-L376

## Fix
The current code is checking `ip.PublicIPAddress.PublicIPAddressPropertiesFormat` but is dereferencing `ip.PublicIPAddress.IPAddress`. We should nil check `ip.PublicIPAddress.IPAddress` instead.

## Stacktrace
```
Feb 08 17:14:17 prometheus docker[8302]: panic: runtime error: invalid memory address or nil pointer dereference
Feb 08 17:14:17 prometheus docker[8302]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xeb0ac1]
Feb 08 17:14:17 prometheus docker[8302]: goroutine 776 [running]:
Feb 08 17:14:17 prometheus docker[8302]: github.com/prometheus/prometheus/discovery/azure.(*Discovery).refresh.func1(0xd9bebd0f7c815613, {{0xc00194db80, 0x92}, {0xc001950228, 0x11}, {0xc001950240, 0x11}, {0xc0019726f0, 0x21}, {0xc001a62590, ...}, ...})
Feb 08 17:14:17 prometheus docker[8302]:         /app/discovery/azure/azure.go:375 +0x7a1
Feb 08 17:14:17 prometheus docker[8302]: created by github.com/prometheus/prometheus/discovery/azure.(*Discovery).refresh
Feb 08 17:14:17 prometheus docker[8302]:         /app/discovery/azure/azure.go:321 +0xd52
```


Discussion / hints:
Thanks for your report. This was theoretically fixed in https://github.com/prometheus/prometheus/pull/5587, and https://github.com/prometheus/prometheus/pull/5587#discussion_r286171167 explains why `ip.PublicIPAddress.PublicIPAddressPropertiesFormat` is used instead. I don't think that check works though, as can be seen in this example (and the bug you found): https://go.dev/play/p/qDzVx0mnoXL.
We've started receiving the same panic with our prometheus implementation today, out the blue with no changes. 

````
Feb 10 14:40:34 xxxxx prometheus: panic: runtime error: invalid memory address or nil pointer dereference
Feb 10 14:40:34 xxxxx prometheus: [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xb419b8]
Feb 10 14:40:34 xxxx prometheus: goroutine 9930314 [running]:
Feb 10 14:40:34 xxxx  prometheus: github.com/prometheus/prometheus/discovery/azure.(*Discovery).refresh.func1(0xc0cf006aa0, 0xc0e7a0b050, 0xc15b820840, 0xc0d7ff5400, 0x2a1a460, 0xc13b79a300, 0x7, 0xc112e50e60, 0x94, 0xc14b363f80, ...)
Feb 10 14:40:34 xxxx prometheus: /app/discovery/azure/azure.go:339 +0xb38````

prometheus, version 2.13.0 (branch: HEAD, revision: 6ea4252299f542669aca11860abc2192bdc7bede)
  build user:       root@f30bdad2c3fd
  build date:       20191004-11:25:34
  go version:       go1.13.1
  
  
That's interesting because this bug was last seen around 2019, but only now it's showing up. Maybe something changed on Azure's side?
I've opened #10280 to fix this.

Fix patch:
diff --git a/discovery/azure/azure.go b/discovery/azure/azure.go
index 3e7cd4e1224..4a70416bba7 100644
--- a/discovery/azure/azure.go
+++ b/discovery/azure/azure.go
@@ -361,7 +361,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
 
 				if *networkInterface.Primary {
 					for _, ip := range *networkInterface.IPConfigurations {
-						if ip.PublicIPAddress != nil && ip.PublicIPAddress.PublicIPAddressPropertiesFormat != nil {
+						if ip.PublicIPAddress != nil && ip.PublicIPAddress.IPAddress != nil {
 							labels[azureLabelMachinePublicIP] = model.LabelValue(*ip.PublicIPAddress.IPAddress)
 						}
 						if ip.PrivateIPAddress != nil {


Test patch: