Skip to content

Commit

Permalink
allow lowercasing of dimension values
Browse files Browse the repository at this point in the history
fixes #90

Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Sep 15, 2024
1 parent 31887b4 commit a841328
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 5 additions & 2 deletions config/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions metrics/insights.subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion metrics/insights.target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
8 changes: 7 additions & 1 deletion metrics/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type (
MetricTemplate string
HelpTemplate string

DimensionLowercase bool

// cache
Cache *time.Duration
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a841328

Please sign in to comment.