Support Azure Sovereign Environments with endpoint_url option (#5453)
This commit is contained in:
parent
03776088f1
commit
6add84eb25
|
@ -40,6 +40,11 @@ written as a dimension on each Azure Monitor metric.
|
||||||
## The Azure Resource ID against which metric will be logged, e.g.
|
## The Azure Resource ID against which metric will be logged, e.g.
|
||||||
## ex: resource_id = "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>"
|
## ex: resource_id = "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>"
|
||||||
# resource_id = ""
|
# resource_id = ""
|
||||||
|
|
||||||
|
## Optionally, if in Azure US Government, China, or other sovereign
|
||||||
|
## cloud environment, set the appropriate REST endpoint for receiving
|
||||||
|
## metrics. (Note: region may be unused in this context)
|
||||||
|
# endpoint_url = "https://monitoring.core.usgovcloudapi.net"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
|
@ -31,6 +31,7 @@ type AzureMonitor struct {
|
||||||
StringsAsDimensions bool `toml:"strings_as_dimensions"`
|
StringsAsDimensions bool `toml:"strings_as_dimensions"`
|
||||||
Region string
|
Region string
|
||||||
ResourceID string `toml:"resource_id"`
|
ResourceID string `toml:"resource_id"`
|
||||||
|
EndpointUrl string `toml:"endpoint_url"`
|
||||||
|
|
||||||
url string
|
url string
|
||||||
auth autorest.Authorizer
|
auth autorest.Authorizer
|
||||||
|
@ -65,6 +66,7 @@ const (
|
||||||
vmInstanceMetadataURL = "http://169.254.169.254/metadata/instance?api-version=2017-12-01"
|
vmInstanceMetadataURL = "http://169.254.169.254/metadata/instance?api-version=2017-12-01"
|
||||||
resourceIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s"
|
resourceIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s"
|
||||||
urlTemplate = "https://%s.monitoring.azure.com%s/metrics"
|
urlTemplate = "https://%s.monitoring.azure.com%s/metrics"
|
||||||
|
urlOverrideTemplate = "%s%s/metrics"
|
||||||
maxRequestBodySize = 4000000
|
maxRequestBodySize = 4000000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -91,6 +93,11 @@ var sampleConfig = `
|
||||||
## The Azure Resource ID against which metric will be logged, e.g.
|
## The Azure Resource ID against which metric will be logged, e.g.
|
||||||
## ex: resource_id = "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>"
|
## ex: resource_id = "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>"
|
||||||
# resource_id = ""
|
# resource_id = ""
|
||||||
|
|
||||||
|
## Optionally, if in Azure US Government, China or other sovereign
|
||||||
|
## cloud environment, set appropriate REST endpoint for receiving
|
||||||
|
## metrics. (Note: region may be unused in this context)
|
||||||
|
# endpoint_url = "https://monitoring.core.usgovcloudapi.net"
|
||||||
`
|
`
|
||||||
|
|
||||||
// Description provides a description of the plugin
|
// Description provides a description of the plugin
|
||||||
|
@ -125,6 +132,8 @@ func (a *AzureMonitor) Connect() error {
|
||||||
var err error
|
var err error
|
||||||
var region string
|
var region string
|
||||||
var resourceID string
|
var resourceID string
|
||||||
|
var endpointUrl string
|
||||||
|
|
||||||
if a.Region == "" || a.ResourceID == "" {
|
if a.Region == "" || a.ResourceID == "" {
|
||||||
// Pull region and resource identifier
|
// Pull region and resource identifier
|
||||||
region, resourceID, err = vmInstanceMetadata(a.client)
|
region, resourceID, err = vmInstanceMetadata(a.client)
|
||||||
|
@ -138,13 +147,21 @@ func (a *AzureMonitor) Connect() error {
|
||||||
if a.ResourceID != "" {
|
if a.ResourceID != "" {
|
||||||
resourceID = a.ResourceID
|
resourceID = a.ResourceID
|
||||||
}
|
}
|
||||||
|
if a.EndpointUrl != "" {
|
||||||
|
endpointUrl = a.EndpointUrl
|
||||||
|
}
|
||||||
|
|
||||||
if resourceID == "" {
|
if resourceID == "" {
|
||||||
return fmt.Errorf("no resource ID configured or available via VM instance metadata")
|
return fmt.Errorf("no resource ID configured or available via VM instance metadata")
|
||||||
} else if region == "" {
|
} else if region == "" {
|
||||||
return fmt.Errorf("no region configured or available via VM instance metadata")
|
return fmt.Errorf("no region configured or available via VM instance metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if endpointUrl == "" {
|
||||||
a.url = fmt.Sprintf(urlTemplate, region, resourceID)
|
a.url = fmt.Sprintf(urlTemplate, region, resourceID)
|
||||||
|
} else {
|
||||||
|
a.url = fmt.Sprintf(urlOverrideTemplate, endpointUrl, resourceID)
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("D! Writing to Azure Monitor URL: %s", a.url)
|
log.Printf("D! Writing to Azure Monitor URL: %s", a.url)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue