From dcab5c1ab10489a18e7f5fd1de3faa31130229e6 Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Tue, 19 Feb 2019 17:51:37 -0800 Subject: [PATCH 1/9] Add support for overriding .monitoring.azure.com to support soveriegn Azure Cloud metrics gathering. E.g. Azure US Government endpoint needs an override. --- plugins/outputs/azure_monitor/README.md | 5 +++++ plugins/outputs/azure_monitor/azure_monitor.go | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/outputs/azure_monitor/README.md b/plugins/outputs/azure_monitor/README.md index 28bb66af6662e..c4d95c94b603f 100644 --- a/plugins/outputs/azure_monitor/README.md +++ b/plugins/outputs/azure_monitor/README.md @@ -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//resourceGroups//providers/Microsoft.Compute/virtualMachines/" # 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_override = "monitoring.core.usgovcloudapi.net" ``` ### Setup diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index e52d66b991d9b..d5e0f87aea4a9 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -31,6 +31,7 @@ type AzureMonitor struct { StringsAsDimensions bool `toml:"strings_as_dimensions"` Region string ResourceID string `toml:"resource_id"` + EndpointOverride string `toml:"endpoint_override"` url string auth autorest.Authorizer @@ -138,13 +139,21 @@ func (a *AzureMonitor) Connect() error { if a.ResourceID != "" { resourceID = a.ResourceID } + if a.EndpointOverride != "" { + endpointOverride = a.EndpointOverride + } 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 EndpointOverride == "" { + a.url = fmt.Sprintf(urlTemplate, region, resourceID) + } else { + a.url = fmt.Sprintf("https://%s%s/metrics", EndpointOverride, resourceID) + } log.Printf("D! Writing to Azure Monitor URL: %s", a.url) From ea0fe7c7d9b7181e13bfeabd25025a5630c0c255 Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Tue, 19 Feb 2019 17:58:05 -0800 Subject: [PATCH 2/9] Fix case in conditional --- plugins/outputs/azure_monitor/azure_monitor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index d5e0f87aea4a9..12da3882e43c0 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -149,10 +149,10 @@ func (a *AzureMonitor) Connect() error { return fmt.Errorf("no region configured or available via VM instance metadata") } - if EndpointOverride == "" { + if endpointOverride == "" { a.url = fmt.Sprintf(urlTemplate, region, resourceID) } else { - a.url = fmt.Sprintf("https://%s%s/metrics", EndpointOverride, resourceID) + a.url = fmt.Sprintf("https://%s%s/metrics", endpointOverride, resourceID) } log.Printf("D! Writing to Azure Monitor URL: %s", a.url) From 9f6669442443e76ed4c6948d6c11dac442339d70 Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Tue, 19 Feb 2019 18:19:08 -0800 Subject: [PATCH 3/9] Fix: gofmt error --- plugins/outputs/azure_monitor/azure_monitor.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index 12da3882e43c0..8d7e6d6f5f9c1 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -66,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 = "https://monitoring.%s%s/metrics" maxRequestBodySize = 4000000 ) @@ -152,7 +153,7 @@ func (a *AzureMonitor) Connect() error { if endpointOverride == "" { a.url = fmt.Sprintf(urlTemplate, region, resourceID) } else { - a.url = fmt.Sprintf("https://%s%s/metrics", endpointOverride, resourceID) + a.url = fmt.Sprintf(urlOverrideTemplate, endpointOverride, resourceID) } log.Printf("D! Writing to Azure Monitor URL: %s", a.url) From ec2231129f15b4fcc922ea0cb0160f3d6985f0ff Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Wed, 20 Feb 2019 10:32:12 -0800 Subject: [PATCH 4/9] Fix: var declaration oversight --- plugins/outputs/azure_monitor/azure_monitor.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index 8d7e6d6f5f9c1..9aa8c1b3621b7 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -127,6 +127,8 @@ func (a *AzureMonitor) Connect() error { var err error var region string var resourceID string + var endpointOverride string + if a.Region == "" || a.ResourceID == "" { // Pull region and resource identifier region, resourceID, err = vmInstanceMetadata(a.client) From 8b35afd1620111aa52e15581dc7c5977c9fd168e Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Wed, 20 Feb 2019 10:34:52 -0800 Subject: [PATCH 5/9] Fix: go fmt --- plugins/outputs/azure_monitor/azure_monitor.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index 9aa8c1b3621b7..23fb03a5d5173 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -128,7 +128,7 @@ func (a *AzureMonitor) Connect() error { var region string var resourceID string var endpointOverride string - + if a.Region == "" || a.ResourceID == "" { // Pull region and resource identifier region, resourceID, err = vmInstanceMetadata(a.client) @@ -143,7 +143,7 @@ func (a *AzureMonitor) Connect() error { resourceID = a.ResourceID } if a.EndpointOverride != "" { - endpointOverride = a.EndpointOverride + endpointOverride = a.EndpointOverride } if resourceID == "" { @@ -152,10 +152,10 @@ func (a *AzureMonitor) Connect() error { return fmt.Errorf("no region configured or available via VM instance metadata") } - if endpointOverride == "" { - a.url = fmt.Sprintf(urlTemplate, region, resourceID) + if endpointOverride == "" { + a.url = fmt.Sprintf(urlTemplate, region, resourceID) } else { - a.url = fmt.Sprintf(urlOverrideTemplate, endpointOverride, resourceID) + a.url = fmt.Sprintf(urlOverrideTemplate, endpointOverride, resourceID) } log.Printf("D! Writing to Azure Monitor URL: %s", a.url) From 408577cb4576789f84bd4c81abb62032b7b20227 Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Wed, 20 Feb 2019 11:49:17 -0800 Subject: [PATCH 6/9] To align with the cloudwatch output endpoint_url setting, renamed vars in the azure_monitor output. --- plugins/outputs/azure_monitor/README.md | 2 +- plugins/outputs/azure_monitor/azure_monitor.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/outputs/azure_monitor/README.md b/plugins/outputs/azure_monitor/README.md index c4d95c94b603f..fbb49358665a5 100644 --- a/plugins/outputs/azure_monitor/README.md +++ b/plugins/outputs/azure_monitor/README.md @@ -44,7 +44,7 @@ written as a dimension on each Azure Monitor metric. ## 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_override = "monitoring.core.usgovcloudapi.net" + # endpoint_url = "https://monitoring.core.usgovcloudapi.net" ``` ### Setup diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index 23fb03a5d5173..e183239cbcd32 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -31,7 +31,7 @@ type AzureMonitor struct { StringsAsDimensions bool `toml:"strings_as_dimensions"` Region string ResourceID string `toml:"resource_id"` - EndpointOverride string `toml:"endpoint_override"` + EndpointURL string `toml:"endpoint_url"` url string auth autorest.Authorizer @@ -66,7 +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 = "https://monitoring.%s%s/metrics" + urlOverrideTemplate = "%s%s/metrics" maxRequestBodySize = 4000000 ) @@ -127,7 +127,7 @@ func (a *AzureMonitor) Connect() error { var err error var region string var resourceID string - var endpointOverride string + var endpointUrl string if a.Region == "" || a.ResourceID == "" { // Pull region and resource identifier @@ -142,8 +142,8 @@ func (a *AzureMonitor) Connect() error { if a.ResourceID != "" { resourceID = a.ResourceID } - if a.EndpointOverride != "" { - endpointOverride = a.EndpointOverride + if a.EndpointUrl != "" { + endpointUrl = a.EndpointUrl } if resourceID == "" { @@ -152,10 +152,10 @@ func (a *AzureMonitor) Connect() error { return fmt.Errorf("no region configured or available via VM instance metadata") } - if endpointOverride == "" { + if endpointUrl == "" { a.url = fmt.Sprintf(urlTemplate, region, resourceID) } else { - a.url = fmt.Sprintf(urlOverrideTemplate, endpointOverride, resourceID) + a.url = fmt.Sprintf(urlOverrideTemplate, endpointUrl, resourceID) } log.Printf("D! Writing to Azure Monitor URL: %s", a.url) From 64ec8cd2f4be94844d36ffab8aacc7ba918e92fd Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Wed, 20 Feb 2019 12:57:57 -0800 Subject: [PATCH 7/9] Fix: var naming (camel case fix) --- plugins/outputs/azure_monitor/azure_monitor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index e183239cbcd32..3e1fe2ed8fa4d 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -31,7 +31,7 @@ type AzureMonitor struct { StringsAsDimensions bool `toml:"strings_as_dimensions"` Region string ResourceID string `toml:"resource_id"` - EndpointURL string `toml:"endpoint_url"` + EndpointUrl string `toml:"endpoint_url"` url string auth autorest.Authorizer From c99192de4fad4d1ed1e1f2ce8864931243ae5bab Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Wed, 20 Feb 2019 14:59:40 -0800 Subject: [PATCH 8/9] Update SampleConfig() per request in PR #5453 --- plugins/outputs/azure_monitor/azure_monitor.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index 3e1fe2ed8fa4d..a451180a71d35 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -93,6 +93,11 @@ var sampleConfig = ` ## The Azure Resource ID against which metric will be logged, e.g. ## ex: resource_id = "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/" # resource_id = "" + + ## Optionall, 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 From 48d527c8e3efc6ddca91cb80cc18d8177a23249a Mon Sep 17 00:00:00 2001 From: Andrew Ernst Date: Wed, 20 Feb 2019 15:01:11 -0800 Subject: [PATCH 9/9] Fix: spelling --- plugins/outputs/azure_monitor/azure_monitor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index a451180a71d35..408976c536338 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -94,7 +94,7 @@ var sampleConfig = ` ## ex: resource_id = "/subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/" # resource_id = "" - ## Optionall, if in Azure US Government, China or other sovereign + ## 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"