Skip to content

Commit

Permalink
Support Azure Sovereign Environments with endpoint_url option (influx…
Browse files Browse the repository at this point in the history
  • Loading branch information
ernstae authored and bitcharmer committed Oct 18, 2019
1 parent c10ea89 commit 32e7bbd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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"
```

### 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

0 comments on commit 32e7bbd

Please sign in to comment.