From 21494d7fc0c473b312b512c75216ae5df81605e4 Mon Sep 17 00:00:00 2001 From: Renat Shajmardanov Date: Thu, 3 Dec 2020 12:18:53 +0300 Subject: [PATCH 1/2] use client base uri according Azure Cloud --- README.md | 13 +++++++------ azure_insights.go | 4 ++-- config/opts.go | 3 ++- main.go | 11 +++++++++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fce7818..98f5402 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Application Options: -v, --verbose verbose mode [$VERBOSE] --log.json Switch log output to json format [$LOG_JSON] --azure-environment= Azure environment name (default: AZUREPUBLICCLOUD) [$AZURE_ENVIRONMENT] + --azure-ad-resource-url= Specifies the AAD resource ID to use. If not set, it defaults to ResourceManagerEndpoint for operations with Azure Resource Manager [$AZURE_AD_RESOURCE] --concurrency.subscription= Concurrent subscription fetches (default: 5) [$CONCURRENCY_SUBSCRIPTION] --concurrency.subscription.resource= Concurrent requests per resource (inside subscription requests) (default: 10) [$CONCURRENCY_SUBSCRIPTION_RESOURCE] @@ -137,10 +138,10 @@ Azure Redis metrics metrics_path: /probe/metrics/list params: name: ["my_own_metric_name"] - subscription: + subscription: - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx filter: ["resourceType eq 'Microsoft.Cache/Redis'"] - metric: + metric: - connectedclients - totalcommandsprocessed - cachehits @@ -162,7 +163,7 @@ Azure Redis metrics - errors interval: ["PT1M"] timespan: ["PT1M"] - aggregation: + aggregation: - average - total static_configs: @@ -176,10 +177,10 @@ Virtual Gateway metrics metrics_path: /probe/metrics/list params: name: ["my_own_metric_name"] - subscription: + subscription: - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx filter: ["resourceType eq 'Microsoft.Network/virtualNetworkGateways'"] - metric: + metric: - AverageBandwidth - P2SBandwidth - P2SConnectionCount @@ -219,7 +220,7 @@ Virtual Gateway connection metrics (dimension support) - TunnelIngressPacketDropTSMismatch interval: ["PT5M"] timespan: ["PT5M"] - aggregation: + aggregation: - average - total # by connection (dimension support) diff --git a/azure_insights.go b/azure_insights.go index 9d261c9..ce93169 100644 --- a/azure_insights.go +++ b/azure_insights.go @@ -34,7 +34,7 @@ func (m *AzureInsightMetrics) MetricsClient(subscriptionId string) *insights.Met m.clientMutex.Lock() if _, ok := m.metricsClientCache[subscriptionId]; !ok { - client := insights.NewMetricsClient(subscriptionId) + client := insights.NewMetricsClientWithBaseURI(AzureAdResourceUrl, subscriptionId) client.Authorizer = AzureAuthorizer m.metricsClientCache[subscriptionId] = &client } @@ -49,7 +49,7 @@ func (m *AzureInsightMetrics) ResourcesClient(subscriptionId string) *resources. m.clientMutex.Lock() if _, ok := m.resourceClientCache[subscriptionId]; !ok { - client := resources.NewClient(subscriptionId) + client := resources.NewClientWithBaseURI(AzureAdResourceUrl, subscriptionId) client.Authorizer = AzureAuthorizer m.resourceClientCache[subscriptionId] = &client } diff --git a/config/opts.go b/config/opts.go index 5fc467f..083d680 100644 --- a/config/opts.go +++ b/config/opts.go @@ -16,7 +16,8 @@ type ( // azure Azure struct { - Environment *string `long:"azure-environment" env:"AZURE_ENVIRONMENT" description:"Azure environment name" default:"AZUREPUBLICCLOUD"` + Environment *string `long:"azure-environment" env:"AZURE_ENVIRONMENT" description:"Azure environment name" default:"AZUREPUBLICCLOUD"` + AdResourceUrl *string `long:"azure-ad-resource-url" env:"AZURE_AD_RESOURCE" description:"Specifies the AAD resource ID to use. If not set, it defaults to ResourceManagerEndpoint for operations with Azure Resource Manager"` } // Prober settings diff --git a/main.go b/main.go index 8b47657..8ac1c19 100644 --- a/main.go +++ b/main.go @@ -43,8 +43,9 @@ var ( argparser *flags.Parser opts config.Opts - AzureEnvironment azure.Environment - AzureAuthorizer autorest.Authorizer + AzureEnvironment azure.Environment + AzureAuthorizer autorest.Authorizer + AzureAdResourceUrl string prometheusCollectTime *prometheus.SummaryVec prometheusMetricRequests *prometheus.CounterVec @@ -132,6 +133,12 @@ func initAzureConnection() { log.Panic(err) } + if opts.Azure.AdResourceUrl == nil { + AzureAdResourceUrl = AzureEnvironment.ResourceManagerEndpoint + } else { + AzureAdResourceUrl = *opts.Azure.AdResourceUrl + } + // setup azure authorizer AzureAuthorizer, err = auth.NewAuthorizerFromEnvironment() if err != nil { From 29249f40f841bb1602866fffa7149aca86bff49a Mon Sep 17 00:00:00 2001 From: Renat Shajmardanov Date: Thu, 3 Dec 2020 12:59:16 +0300 Subject: [PATCH 2/2] return README.md formatting back --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 98f5402..65e176a 100644 --- a/README.md +++ b/README.md @@ -138,10 +138,10 @@ Azure Redis metrics metrics_path: /probe/metrics/list params: name: ["my_own_metric_name"] - subscription: + subscription: - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx filter: ["resourceType eq 'Microsoft.Cache/Redis'"] - metric: + metric: - connectedclients - totalcommandsprocessed - cachehits @@ -163,7 +163,7 @@ Azure Redis metrics - errors interval: ["PT1M"] timespan: ["PT1M"] - aggregation: + aggregation: - average - total static_configs: @@ -177,10 +177,10 @@ Virtual Gateway metrics metrics_path: /probe/metrics/list params: name: ["my_own_metric_name"] - subscription: + subscription: - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx filter: ["resourceType eq 'Microsoft.Network/virtualNetworkGateways'"] - metric: + metric: - AverageBandwidth - P2SBandwidth - P2SConnectionCount @@ -220,7 +220,7 @@ Virtual Gateway connection metrics (dimension support) - TunnelIngressPacketDropTSMismatch interval: ["PT5M"] timespan: ["PT5M"] - aggregation: + aggregation: - average - total # by connection (dimension support)