Skip to content

Commit a841328

Browse files
committed
allow lowercasing of dimension values
fixes #90 Signed-off-by: Markus Blaschke <[email protected]>
1 parent 31887b4 commit a841328

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ Application Options:
7070
--log.devel development mode [$LOG_DEVEL]
7171
--log.json Switch log output to json format [$LOG_JSON]
7272
--azure-environment= Azure environment name (default: AZUREPUBLICCLOUD) [$AZURE_ENVIRONMENT]
73-
--azure-ad-resource-url= Specifies the AAD resource ID to use. If not set, it defaults to ResourceManagerEndpoint for
74-
operations with Azure Resource Manager [$AZURE_AD_RESOURCE]
75-
--azure.servicediscovery.cache= Duration for caching Azure ServiceDiscovery of workspaces to reduce API calls (time.Duration)
76-
(default: 30m) [$AZURE_SERVICEDISCOVERY_CACHE]
73+
--azure-ad-resource-url= Specifies the AAD resource ID to use. If not set, it defaults to ResourceManagerEndpoint for operations with Azure Resource Manager
74+
[$AZURE_AD_RESOURCE]
75+
--azure.servicediscovery.cache= Duration for caching Azure ServiceDiscovery of workspaces to reduce API calls (time.Duration) (default: 30m)
76+
[$AZURE_SERVICEDISCOVERY_CACHE]
7777
--azure.resource-tag= Azure Resource tags (space delimiter) (default: owner) [$AZURE_RESOURCE_TAG]
7878
--metrics.template= Template for metric name (default: {name}) [$METRIC_TEMPLATE]
7979
--metrics.help= Metric help (with template support) (default: Azure monitor insight metric) [$METRIC_HELP]
80+
--metrics.dimensions.lowercase Lowercase dimension values [$METRIC_DIMENSIONS_LOWERCASE]
8081
--concurrency.subscription= Concurrent subscription fetches (default: 5) [$CONCURRENCY_SUBSCRIPTION]
81-
--concurrency.subscription.resource= Concurrent requests per resource (inside subscription requests) (default: 10)
82-
[$CONCURRENCY_SUBSCRIPTION_RESOURCE]
82+
--concurrency.subscription.resource= Concurrent requests per resource (inside subscription requests) (default: 10) [$CONCURRENCY_SUBSCRIPTION_RESOURCE]
8383
--enable-caching Enable internal caching [$ENABLE_CACHING]
8484
--server.bind= Server address (default: :8080) [$SERVER_BIND]
8585
--server.timeout.read= Server read timeout (default: 5s) [$SERVER_TIMEOUT_READ]

config/opts.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ type (
2525
}
2626

2727
Metrics struct {
28-
Template string `long:"metrics.template" env:"METRIC_TEMPLATE" description:"Template for metric name" default:"{name}"`
29-
Help string `long:"metrics.help" env:"METRIC_HELP" description:"Metric help (with template support)" default:"Azure monitor insight metric"`
28+
Template string `long:"metrics.template" env:"METRIC_TEMPLATE" description:"Template for metric name" default:"{name}"`
29+
Help string `long:"metrics.help" env:"METRIC_HELP" description:"Metric help (with template support)" default:"Azure monitor insight metric"`
30+
Dimensions struct {
31+
Lowercase bool `long:"metrics.dimensions.lowercase" env:"METRIC_DIMENSIONS_LOWERCASE" description:"Lowercase dimension values"`
32+
}
3033
}
3134

3235
// Prober settings

metrics/insights.subscription.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (r *AzureInsightSubscriptionMetricsResult) SendMetricToChannel(channel chan
3838
dimensionRowName := to.String(dimensionRow.Name.Value)
3939
dimensionRowValue := to.String(dimensionRow.Value)
4040

41+
if r.prober.settings.DimensionLowercase {
42+
dimensionRowValue = strings.ToLower(dimensionRowValue)
43+
}
44+
4145
if strings.EqualFold(dimensionRowName, "microsoft.resourceid") {
4246
resourceId = dimensionRowValue
4347
} else {

metrics/insights.target.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ func (r *AzureInsightMetricsResult) SendMetricToChannel(channel chan<- Prometheu
3333
dimensions := map[string]string{}
3434
if timeseries.Metadatavalues != nil {
3535
for _, dimensionRow := range timeseries.Metadatavalues {
36-
dimensions[to.String(dimensionRow.Name.Value)] = to.String(dimensionRow.Value)
36+
dimensionValue := to.String(dimensionRow.Value)
37+
if r.prober.settings.DimensionLowercase {
38+
dimensionValue = strings.ToLower(dimensionValue)
39+
}
40+
dimensions[to.String(dimensionRow.Name.Value)] = dimensionValue
3741
}
3842
}
3943

metrics/settings.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type (
3939
MetricTemplate string
4040
HelpTemplate string
4141

42+
DimensionLowercase bool
43+
4244
// cache
4345
Cache *time.Duration
4446
}
@@ -67,7 +69,11 @@ func NewRequestMetricSettingsForAzureResourceApi(r *http.Request, opts config.Op
6769
}
6870

6971
func NewRequestMetricSettings(r *http.Request, opts config.Opts) (RequestMetricSettings, error) {
70-
ret := RequestMetricSettings{}
72+
ret := RequestMetricSettings{
73+
// force lowercasing of dimensions
74+
DimensionLowercase: opts.Metrics.Dimensions.Lowercase,
75+
}
76+
7177
params := r.URL.Query()
7278

7379
// param name

0 commit comments

Comments
 (0)