Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Azure Sovereign Environments with EndpointOverride argument #5453

Merged
merged 9 commits into from
Feb 20, 2019
5 changes: 5 additions & 0 deletions plugins/outputs/azure_monitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
## ex: resource_id = "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>"
# 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"
danielnelson marked this conversation as resolved.
Show resolved Hide resolved
```

### Setup
Expand Down
19 changes: 18 additions & 1 deletion plugins/outputs/azure_monitor/azure_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type AzureMonitor struct {
StringsAsDimensions bool `toml:"strings_as_dimensions"`
Region string
ResourceID string `toml:"resource_id"`
EndpointUrl string `toml:"endpoint_url"`

url string
auth autorest.Authorizer
Expand Down Expand Up @@ -65,6 +66,7 @@ const (
vmInstanceMetadataURL = "http://169.254.169.254/metadata/instance?api-version=2017-12-01"
resourceIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s"
urlTemplate = "https://%s.monitoring.azure.com%s/metrics"
urlOverrideTemplate = "%s%s/metrics"
maxRequestBodySize = 4000000
)

Expand All @@ -91,6 +93,11 @@ var sampleConfig = `
## 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>"
# 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
Expand Down Expand Up @@ -125,6 +132,8 @@ func (a *AzureMonitor) Connect() error {
var err error
var region string
var resourceID string
var endpointUrl string

if a.Region == "" || a.ResourceID == "" {
// Pull region and resource identifier
region, resourceID, err = vmInstanceMetadata(a.client)
Expand All @@ -138,13 +147,21 @@ func (a *AzureMonitor) Connect() error {
if a.ResourceID != "" {
resourceID = a.ResourceID
}
if a.EndpointUrl != "" {
endpointUrl = a.EndpointUrl
}

if resourceID == "" {
return fmt.Errorf("no resource ID configured or available via VM instance metadata")
} else if region == "" {
return fmt.Errorf("no region configured or available via VM instance metadata")
}
a.url = fmt.Sprintf(urlTemplate, region, resourceID)

if endpointUrl == "" {
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)

Expand Down