diff --git a/README.md b/README.md index d1c7558..54f07fc 100644 --- a/README.md +++ b/README.md @@ -70,16 +70,16 @@ Application Options: --log.devel development mode [$LOG_DEVEL] --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] - --azure.servicediscovery.cache= Duration for caching Azure ServiceDiscovery of workspaces to reduce API calls (time.Duration) - (default: 30m) [$AZURE_SERVICEDISCOVERY_CACHE] + --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] + --azure.servicediscovery.cache= Duration for caching Azure ServiceDiscovery of workspaces to reduce API calls (time.Duration) (default: 30m) + [$AZURE_SERVICEDISCOVERY_CACHE] --azure.resource-tag= Azure Resource tags (space delimiter) (default: owner) [$AZURE_RESOURCE_TAG] --metrics.template= Template for metric name (default: {name}) [$METRIC_TEMPLATE] --metrics.help= Metric help (with template support) (default: Azure monitor insight metric) [$METRIC_HELP] + --metrics.dimensions.lowercase Lowercase dimension values [$METRIC_DIMENSIONS_LOWERCASE] --concurrency.subscription= Concurrent subscription fetches (default: 5) [$CONCURRENCY_SUBSCRIPTION] - --concurrency.subscription.resource= Concurrent requests per resource (inside subscription requests) (default: 10) - [$CONCURRENCY_SUBSCRIPTION_RESOURCE] + --concurrency.subscription.resource= Concurrent requests per resource (inside subscription requests) (default: 10) [$CONCURRENCY_SUBSCRIPTION_RESOURCE] --enable-caching Enable internal caching [$ENABLE_CACHING] --server.bind= Server address (default: :8080) [$SERVER_BIND] --server.timeout.read= Server read timeout (default: 5s) [$SERVER_TIMEOUT_READ] diff --git a/config/opts.go b/config/opts.go index a874693..4ad5ace 100644 --- a/config/opts.go +++ b/config/opts.go @@ -25,8 +25,11 @@ type ( } Metrics struct { - Template string `long:"metrics.template" env:"METRIC_TEMPLATE" description:"Template for metric name" default:"{name}"` - Help string `long:"metrics.help" env:"METRIC_HELP" description:"Metric help (with template support)" default:"Azure monitor insight metric"` + Template string `long:"metrics.template" env:"METRIC_TEMPLATE" description:"Template for metric name" default:"{name}"` + Help string `long:"metrics.help" env:"METRIC_HELP" description:"Metric help (with template support)" default:"Azure monitor insight metric"` + Dimensions struct { + Lowercase bool `long:"metrics.dimensions.lowercase" env:"METRIC_DIMENSIONS_LOWERCASE" description:"Lowercase dimension values"` + } } // Prober settings diff --git a/metrics/insights.subscription.go b/metrics/insights.subscription.go index 598e19f..ed865ac 100644 --- a/metrics/insights.subscription.go +++ b/metrics/insights.subscription.go @@ -38,6 +38,10 @@ func (r *AzureInsightSubscriptionMetricsResult) SendMetricToChannel(channel chan dimensionRowName := to.String(dimensionRow.Name.Value) dimensionRowValue := to.String(dimensionRow.Value) + if r.prober.settings.DimensionLowercase { + dimensionRowValue = strings.ToLower(dimensionRowValue) + } + if strings.EqualFold(dimensionRowName, "microsoft.resourceid") { resourceId = dimensionRowValue } else { diff --git a/metrics/insights.target.go b/metrics/insights.target.go index a4a7414..c893f66 100644 --- a/metrics/insights.target.go +++ b/metrics/insights.target.go @@ -33,7 +33,11 @@ func (r *AzureInsightMetricsResult) SendMetricToChannel(channel chan<- Prometheu dimensions := map[string]string{} if timeseries.Metadatavalues != nil { for _, dimensionRow := range timeseries.Metadatavalues { - dimensions[to.String(dimensionRow.Name.Value)] = to.String(dimensionRow.Value) + dimensionValue := to.String(dimensionRow.Value) + if r.prober.settings.DimensionLowercase { + dimensionValue = strings.ToLower(dimensionValue) + } + dimensions[to.String(dimensionRow.Name.Value)] = dimensionValue } } diff --git a/metrics/settings.go b/metrics/settings.go index 535a0a1..7aff264 100644 --- a/metrics/settings.go +++ b/metrics/settings.go @@ -39,6 +39,8 @@ type ( MetricTemplate string HelpTemplate string + DimensionLowercase bool + // cache Cache *time.Duration } @@ -67,7 +69,11 @@ func NewRequestMetricSettingsForAzureResourceApi(r *http.Request, opts config.Op } func NewRequestMetricSettings(r *http.Request, opts config.Opts) (RequestMetricSettings, error) { - ret := RequestMetricSettings{} + ret := RequestMetricSettings{ + // force lowercasing of dimensions + DimensionLowercase: opts.Metrics.Dimensions.Lowercase, + } + params := r.URL.Query() // param name