Skip to content

Commit cee9d9e

Browse files
committed
add flag for lowercase resourceids
Fixes #7 Signed-off-by: Markus Blaschke <[email protected]>
1 parent 538178d commit cee9d9e

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,17 @@ Application Options:
6464
--debug debug mode [$DEBUG]
6565
-v, --verbose verbose mode [$VERBOSE]
6666
--log.json Switch log output to json format [$LOG_JSON]
67-
--azure-environment= Azure environment name (default: AZUREPUBLICCLOUD)
68-
[$AZURE_ENVIRONMENT]
67+
--azure-environment= Azure environment name (default: AZUREPUBLICCLOUD) [$AZURE_ENVIRONMENT]
6968
--azure-ad-resource-url= Specifies the AAD resource ID to use. If not set, it defaults to
7069
ResourceManagerEndpoint for operations with Azure Resource Manager
7170
[$AZURE_AD_RESOURCE]
72-
--azure.servicediscovery.cache= Duration for caching Azure ServiceDiscovery of workspaces to reduce
73-
API calls (time.Duration) (default: 30m)
74-
[$AZURE_SERVICEDISCOVERY_CACHE]
71+
--azure.servicediscovery.cache= Duration for caching Azure ServiceDiscovery of workspaces to reduce API calls
72+
(time.Duration) (default: 30m) [$AZURE_SERVICEDISCOVERY_CACHE]
73+
--metrics.resourceid.lowercase Publish lowercase Azure Resoruce ID in metrics [$METRIC_RESOURCEID_LOWERCASE]
7574
--metrics.template= Template for metric name (default: {name}) [$METRIC_TEMPLATE]
76-
--concurrency.subscription= Concurrent subscription fetches (default: 5)
77-
[$CONCURRENCY_SUBSCRIPTION]
78-
--concurrency.subscription.resource= Concurrent requests per resource (inside subscription requests)
79-
(default: 10) [$CONCURRENCY_SUBSCRIPTION_RESOURCE]
75+
--concurrency.subscription= Concurrent subscription fetches (default: 5) [$CONCURRENCY_SUBSCRIPTION]
76+
--concurrency.subscription.resource= Concurrent requests per resource (inside subscription requests) (default: 10)
77+
[$CONCURRENCY_SUBSCRIPTION_RESOURCE]
8078
--enable-caching Enable internal caching [$ENABLE_CACHING]
8179
--bind= Server address (default: :8080) [$SERVER_BIND]
8280

config/opts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ type (
2525
}
2626

2727
Metrics struct {
28-
Template string `long:"metrics.template" env:"METRIC_TEMPLATE" description:"Template for metric name" default:"{name}"`
28+
ResourceIdLowercase bool `long:"metrics.resourceid.lowercase" env:"METRIC_RESOURCEID_LOWERCASE" description:"Publish lowercase Azure Resoruce ID in metrics"`
29+
Template string `long:"metrics.template" env:"METRIC_TEMPLATE" description:"Template for metric name" default:"{name}"`
2930
}
3031

3132
// Prober settings

metrics/insights.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package metrics
22

33
import (
44
"github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2018-03-01/insights"
5+
"github.com/Azure/go-autorest/autorest/to"
56
"github.com/prometheus/client_golang/prometheus"
67
"regexp"
78
"strings"
@@ -121,15 +122,20 @@ func (r *AzureInsightMetricsResult) SendMetricToChannel(channel chan<- Prometheu
121122
}
122123
}
123124

125+
resourceId := to.String(r.ResourceID)
126+
if r.settings.LowercaseResourceId {
127+
resourceId = strings.ToLower(resourceId)
128+
}
129+
124130
if timeseriesData.Total != nil {
125131
channel <- r.buildMetric(
126132
prometheus.Labels{
127-
"resourceID": *r.ResourceID,
128-
"metric": stringPtrToString(metric.Name.Value),
133+
"resourceID": resourceId,
134+
"metric": to.String(metric.Name.Value),
129135
"dimension": dimensionName,
130136
"unit": string(metric.Unit),
131137
"aggregation": "total",
132-
"interval": stringPtrToString(r.settings.Interval),
138+
"interval": to.String(r.settings.Interval),
133139
"timespan": r.settings.Timespan,
134140
},
135141
*timeseriesData.Total,
@@ -139,12 +145,12 @@ func (r *AzureInsightMetricsResult) SendMetricToChannel(channel chan<- Prometheu
139145
if timeseriesData.Minimum != nil {
140146
channel <- r.buildMetric(
141147
prometheus.Labels{
142-
"resourceID": *r.ResourceID,
143-
"metric": stringPtrToString(metric.Name.Value),
148+
"resourceID": resourceId,
149+
"metric": to.String(metric.Name.Value),
144150
"dimension": dimensionName,
145151
"unit": string(metric.Unit),
146152
"aggregation": "minimum",
147-
"interval": stringPtrToString(r.settings.Interval),
153+
"interval": to.String(r.settings.Interval),
148154
"timespan": r.settings.Timespan,
149155
},
150156
*timeseriesData.Minimum,
@@ -154,12 +160,12 @@ func (r *AzureInsightMetricsResult) SendMetricToChannel(channel chan<- Prometheu
154160
if timeseriesData.Maximum != nil {
155161
channel <- r.buildMetric(
156162
prometheus.Labels{
157-
"resourceID": *r.ResourceID,
158-
"metric": stringPtrToString(metric.Name.Value),
163+
"resourceID": resourceId,
164+
"metric": to.String(metric.Name.Value),
159165
"dimension": dimensionName,
160166
"unit": string(metric.Unit),
161167
"aggregation": "maximum",
162-
"interval": stringPtrToString(r.settings.Interval),
168+
"interval": to.String(r.settings.Interval),
163169
"timespan": r.settings.Timespan,
164170
},
165171
*timeseriesData.Maximum,
@@ -169,12 +175,12 @@ func (r *AzureInsightMetricsResult) SendMetricToChannel(channel chan<- Prometheu
169175
if timeseriesData.Average != nil {
170176
channel <- r.buildMetric(
171177
prometheus.Labels{
172-
"resourceID": *r.ResourceID,
173-
"metric": stringPtrToString(metric.Name.Value),
178+
"resourceID": resourceId,
179+
"metric": to.String(metric.Name.Value),
174180
"dimension": dimensionName,
175181
"unit": string(metric.Unit),
176182
"aggregation": "average",
177-
"interval": stringPtrToString(r.settings.Interval),
183+
"interval": to.String(r.settings.Interval),
178184
"timespan": r.settings.Timespan,
179185
},
180186
*timeseriesData.Average,
@@ -184,12 +190,12 @@ func (r *AzureInsightMetricsResult) SendMetricToChannel(channel chan<- Prometheu
184190
if timeseriesData.Count != nil {
185191
channel <- r.buildMetric(
186192
prometheus.Labels{
187-
"resourceID": *r.ResourceID,
188-
"metric": stringPtrToString(metric.Name.Value),
193+
"resourceID": resourceId,
194+
"metric": to.String(metric.Name.Value),
189195
"dimension": dimensionName,
190196
"unit": string(metric.Unit),
191197
"aggregation": "count",
192-
"interval": stringPtrToString(r.settings.Interval),
198+
"interval": to.String(r.settings.Interval),
193199
"timespan": r.settings.Timespan,
194200
},
195201
*timeseriesData.Count,

metrics/misc.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ func paramsGetListRequired(params url.Values, name string) (list []string, err e
3232
return
3333
}
3434

35-
func stringPtrToString(v *string) string {
36-
if v == nil {
37-
return ""
38-
}
39-
40-
return *v
41-
}
42-
4335
func stringToStringList(v string, sep string) (list []string) {
4436
for _, v := range strings.Split(v, sep) {
4537
list = append(list, strings.TrimSpace(v))

metrics/settings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type (
3535

3636
MetricTemplate string
3737

38+
LowercaseResourceId bool
39+
3840
// cache
3941
Cache *time.Duration
4042
}
@@ -44,6 +46,8 @@ func NewRequestMetricSettings(r *http.Request, opts config.Opts) (RequestMetricS
4446
ret := RequestMetricSettings{}
4547
params := r.URL.Query()
4648

49+
ret.LowercaseResourceId = opts.Metrics.ResourceIdLowercase
50+
4751
// param name
4852
ret.Name = paramsGetWithDefault(params, "name", PrometheusMetricNameDefault)
4953

0 commit comments

Comments
 (0)