Skip to content

Commit ca13ad7

Browse files
committed
Adds alias for nested lists
1 parent a0d1d0c commit ca13ad7

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

receiver/azuremonitorreceiver/config.go

+21-19
Original file line numberDiff line numberDiff line change
@@ -228,31 +228,33 @@ var (
228228
}
229229
)
230230

231+
type NestedListAlias = map[string]map[string][]string
232+
231233
type DimensionsConfig struct {
232-
Enabled *bool `mapstructure:"enabled"`
233-
Overrides map[string]map[string][]string `mapstructure:"overrides"`
234+
Enabled *bool `mapstructure:"enabled"`
235+
Overrides NestedListAlias `mapstructure:"overrides"`
234236
}
235237

236238
// Config defines the configuration for the various elements of the receiver agent.
237239
type Config struct {
238240
scraperhelper.ControllerConfig `mapstructure:",squash"`
239-
MetricsBuilderConfig metadata.MetricsBuilderConfig `mapstructure:",squash"`
240-
Cloud string `mapstructure:"cloud"`
241-
SubscriptionID string `mapstructure:"subscription_id"`
242-
Authentication string `mapstructure:"auth"`
243-
TenantID string `mapstructure:"tenant_id"`
244-
ClientID string `mapstructure:"client_id"`
245-
ClientSecret string `mapstructure:"client_secret"`
246-
FederatedTokenFile string `mapstructure:"federated_token_file"`
247-
ResourceGroups []string `mapstructure:"resource_groups"`
248-
Services []string `mapstructure:"services"`
249-
Metrics map[string]map[string][]string `mapstructure:"metrics"`
250-
CacheResources float64 `mapstructure:"cache_resources"`
251-
CacheResourcesDefinitions float64 `mapstructure:"cache_resources_definitions"`
252-
MaximumNumberOfMetricsInACall int `mapstructure:"maximum_number_of_metrics_in_a_call"`
253-
MaximumNumberOfRecordsPerResource int32 `mapstructure:"maximum_number_of_records_per_resource"`
254-
AppendTagsAsAttributes bool `mapstructure:"append_tags_as_attributes"`
255-
Dimensions DimensionsConfig `mapstructure:"dimensions"`
241+
MetricsBuilderConfig metadata.MetricsBuilderConfig `mapstructure:",squash"`
242+
Cloud string `mapstructure:"cloud"`
243+
SubscriptionID string `mapstructure:"subscription_id"`
244+
Authentication string `mapstructure:"auth"`
245+
TenantID string `mapstructure:"tenant_id"`
246+
ClientID string `mapstructure:"client_id"`
247+
ClientSecret string `mapstructure:"client_secret"`
248+
FederatedTokenFile string `mapstructure:"federated_token_file"`
249+
ResourceGroups []string `mapstructure:"resource_groups"`
250+
Services []string `mapstructure:"services"`
251+
Metrics NestedListAlias `mapstructure:"metrics"`
252+
CacheResources float64 `mapstructure:"cache_resources"`
253+
CacheResourcesDefinitions float64 `mapstructure:"cache_resources_definitions"`
254+
MaximumNumberOfMetricsInACall int `mapstructure:"maximum_number_of_metrics_in_a_call"`
255+
MaximumNumberOfRecordsPerResource int32 `mapstructure:"maximum_number_of_records_per_resource"`
256+
AppendTagsAsAttributes bool `mapstructure:"append_tags_as_attributes"`
257+
Dimensions DimensionsConfig `mapstructure:"dimensions"`
256258
}
257259

258260
const (

receiver/azuremonitorreceiver/dimension_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestFilterDimensions(t *testing.T) {
6565
},
6666
cfg: DimensionsConfig{
6767
Enabled: to.Ptr(true),
68-
Overrides: map[string]map[string][]string{
68+
Overrides: NestedListAlias{
6969
"rt1": {
7070
"m1": {
7171
"foo",

receiver/azuremonitorreceiver/scraper.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ func getResourceMetricsValuesRequestOptions(
452452
metrics []string,
453453
dimensionsStr string,
454454
timeGrain string,
455-
aggregations string,
455+
aggregationsStr string,
456456
start int,
457457
end int,
458458
top int32,
@@ -461,7 +461,7 @@ func getResourceMetricsValuesRequestOptions(
461461
Metricnames: to.Ptr(strings.Join(metrics[start:end], ",")),
462462
Interval: to.Ptr(timeGrain),
463463
Timespan: to.Ptr(timeGrain),
464-
Aggregation: to.Ptr(aggregations),
464+
Aggregation: to.Ptr(aggregationsStr),
465465
Top: to.Ptr(top),
466466
Filter: buildDimensionsFilter(dimensionsStr),
467467
}
@@ -503,7 +503,7 @@ func (s *azureScraper) processTimeseriesData(
503503
}
504504
}
505505

506-
func getMetricAggregations(metricNamespace, metricName string, filters map[string]map[string][]string) []string {
506+
func getMetricAggregations(metricNamespace, metricName string, filters NestedListAlias) []string {
507507
// default behavior when no metric filters specified: pass all metrics with all aggregations
508508
if len(filters) == 0 {
509509
return aggregations

receiver/azuremonitorreceiver/scraper_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func TestAzureScraperScrape(t *testing.T) {
346346

347347
cfgLimitedMertics := createDefaultConfig().(*Config)
348348
cfgLimitedMertics.MaximumNumberOfMetricsInACall = 2
349-
cfgLimitedMertics.Metrics = map[string]map[string][]string{
349+
cfgLimitedMertics.Metrics = NestedListAlias{
350350
"namespace1": {
351351
"metric1": {"*"},
352352
"metric3": {"total"},
@@ -768,24 +768,24 @@ func TestGetMetricAggregations(t *testing.T) {
768768
testMetricName := "MetricName"
769769
tests := []struct {
770770
name string
771-
filters map[string]map[string][]string
771+
filters NestedListAlias
772772
want []string
773773
}{
774774
{
775775
"should return all aggregations when metrics filter empty",
776-
map[string]map[string][]string{},
776+
NestedListAlias{},
777777
aggregations,
778778
},
779779
{
780780
"should return all aggregations when namespace not in filters",
781-
map[string]map[string][]string{
781+
NestedListAlias{
782782
"another.namespace": nil,
783783
},
784784
aggregations,
785785
},
786786
{
787787
"should return all aggregations when metric in filters",
788-
map[string]map[string][]string{
788+
NestedListAlias{
789789
testNamespaceName: {
790790
testMetricName: {},
791791
},
@@ -794,7 +794,7 @@ func TestGetMetricAggregations(t *testing.T) {
794794
},
795795
{
796796
"should return all aggregations ignoring metric name case",
797-
map[string]map[string][]string{
797+
NestedListAlias{
798798
testNamespaceName: {
799799
strings.ToLower(testMetricName): {},
800800
},
@@ -803,7 +803,7 @@ func TestGetMetricAggregations(t *testing.T) {
803803
},
804804
{
805805
"should return all aggregations when asterisk in filters",
806-
map[string]map[string][]string{
806+
NestedListAlias{
807807
testNamespaceName: {
808808
testMetricName: {filterAllAggregations},
809809
},
@@ -812,7 +812,7 @@ func TestGetMetricAggregations(t *testing.T) {
812812
},
813813
{
814814
"should be empty when metric not in filters",
815-
map[string]map[string][]string{
815+
NestedListAlias{
816816
testNamespaceName: {
817817
"not_this_metric": {},
818818
},
@@ -821,7 +821,7 @@ func TestGetMetricAggregations(t *testing.T) {
821821
},
822822
{
823823
"should return one aggregations",
824-
map[string]map[string][]string{
824+
NestedListAlias{
825825
testNamespaceName: {
826826
testMetricName: {aggregations[0]},
827827
},
@@ -830,7 +830,7 @@ func TestGetMetricAggregations(t *testing.T) {
830830
},
831831
{
832832
"should return one aggregations ignoring aggregation case",
833-
map[string]map[string][]string{
833+
NestedListAlias{
834834
testNamespaceName: {
835835
testMetricName: {strings.ToLower(aggregations[0])},
836836
},
@@ -839,7 +839,7 @@ func TestGetMetricAggregations(t *testing.T) {
839839
},
840840
{
841841
"should return many aggregations",
842-
map[string]map[string][]string{
842+
NestedListAlias{
843843
testNamespaceName: {
844844
testMetricName: {aggregations[0], aggregations[2]},
845845
},

0 commit comments

Comments
 (0)