Skip to content

Commit

Permalink
rename dimensionNames to dimensionNameRequirements
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Utley <[email protected]>
  • Loading branch information
jutley committed Jun 30, 2022
1 parent 4e65024 commit 6d10019
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Note: Only [tagged resources](https://docs.aws.amazon.com/general/latest/gr/aws_
| roundingPeriod | Specifies how the current time is rounded before calculating start/end times for CloudWatch GetMetricData requests. This rounding is optimize performance of the CloudWatch request. This setting only makes sense to use if, for example, you specify a very long period (such as 1 day) but want your times rounded to a shorter time (such as 5 minutes). to For example, a value of 300 will round the current time to the nearest 5 minutes. If not specified, the roundingPeriod defaults to the same value as shortest period in the job. |
| addCloudwatchTimestamp | Export the metric with the original CloudWatch timestamp (General Setting for all metrics in this job) |
| customTags | Custom tags to be added as a list of Key/Value pairs |
| dimensionNames | List of metric dimensions to query. Before querying metric values, the total list of metrics will be filtered to only those that contain exactly this list of dimensions. An empty or undefined list results in all dimension combinations being included. |
| dimensionNameRequirements | List of metric dimensions to query. Before querying metric values, the total list of metrics will be filtered to only those that contain exactly this list of dimensions. An empty or undefined list results in all dimension combinations being included. |
| metrics | List of metric definitions |

searchTags example:
Expand Down
2 changes: 1 addition & 1 deletion pkg/abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func getMetricDataForQueries(
if len(resources) == 0 {
logger.Debug("No resources for metric", "metric_name", metric.Name, "namespace", svc.Namespace)
}
getMetricDatas = append(getMetricDatas, getFilteredMetricDatas(region, accountId, discoveryJob.Type, discoveryJob.CustomTags, tagsOnMetrics, svc.DimensionRegexps, resources, metricsList.Metrics, discoveryJob.DimensionNames, metric)...)
getMetricDatas = append(getMetricDatas, getFilteredMetricDatas(region, accountId, discoveryJob.Type, discoveryJob.CustomTags, tagsOnMetrics, svc.DimensionRegexps, resources, metricsList.Metrics, discoveryJob.DimensionNameRequirements, metric)...)
}
return getMetricDatas
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/aws_cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@ func getFilteredMetricDatas(region string, accountId *string, namespace string,
return getMetricsData
}

func metricDimensionsMatchNames(metric *cloudwatch.Metric, dimensionNames []string) bool {
if len(dimensionNames) != len(metric.Dimensions) {
func metricDimensionsMatchNames(metric *cloudwatch.Metric, dimensionNameRequirements []string) bool {
if len(dimensionNameRequirements) != len(metric.Dimensions) {
return false
}
for _, dimension := range metric.Dimensions {
foundMatch := false
for _, dimensionName := range dimensionNames {
for _, dimensionName := range dimensionNameRequirements {
if *dimension.Name == dimensionName {
foundMatch = true
break
Expand Down
24 changes: 12 additions & 12 deletions pkg/aws_cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ func TestSortyByTimeStamp(t *testing.T) {

func Test_getFilteredMetricDatas(t *testing.T) {
type args struct {
region string
accountId *string
namespace string
customTags []Tag
tagsOnMetrics exportedTagsOnMetrics
dimensionRegexps []*string
dimensionNames []string
resources []*taggedResource
metricsList []*cloudwatch.Metric
m *Metric
region string
accountId *string
namespace string
customTags []Tag
tagsOnMetrics exportedTagsOnMetrics
dimensionRegexps []*string
dimensionNameRequirements []string
resources []*taggedResource
metricsList []*cloudwatch.Metric
m *Metric
}
tests := []struct {
name string
Expand Down Expand Up @@ -251,7 +251,7 @@ func Test_getFilteredMetricDatas(t *testing.T) {
customTags: nil,
tagsOnMetrics: nil,
dimensionRegexps: SupportedServices.GetService("alb").DimensionRegexps,
dimensionNames: []string{"LoadBalancer", "TargetGroup"},
dimensionNameRequirements: []string{"LoadBalancer", "TargetGroup"},
resources: []*taggedResource{
{
ARN: "arn:aws:elasticloadbalancing:us-east-1:123123123123:loadbalancer/app/some-ALB/0123456789012345",
Expand Down Expand Up @@ -365,7 +365,7 @@ func Test_getFilteredMetricDatas(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for i, got := range getFilteredMetricDatas(tt.args.region, tt.args.accountId, tt.args.namespace, tt.args.customTags, tt.args.tagsOnMetrics, tt.args.dimensionRegexps, tt.args.resources, tt.args.metricsList, tt.args.dimensionNames, tt.args.m) {
for i, got := range getFilteredMetricDatas(tt.args.region, tt.args.accountId, tt.args.namespace, tt.args.customTags, tt.args.tagsOnMetrics, tt.args.dimensionRegexps, tt.args.resources, tt.args.metricsList, tt.args.dimensionNameRequirements, tt.args.m) {
if *got.AccountId != *tt.wantGetMetricsData[i].AccountId {
t.Errorf("getFilteredMetricDatas().AccountId = %v, want %v", *got.AccountId, *tt.wantGetMetricsData[i].AccountId)
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ type Discovery struct {
type exportedTagsOnMetrics map[string][]string

type Job struct {
Regions []string `yaml:"regions"`
Type string `yaml:"type"`
Roles []Role `yaml:"roles"`
SearchTags []Tag `yaml:"searchTags"`
CustomTags []Tag `yaml:"customTags"`
DimensionNames []string `yaml:"dimensionNames"`
Metrics []*Metric `yaml:"metrics"`
Length int64 `yaml:"length"`
Delay int64 `yaml:"delay"`
Period int64 `yaml:"period"`
RoundingPeriod *int64 `yaml:"roundingPeriod"`
Statistics []string `yaml:"statistics"`
AddCloudwatchTimestamp *bool `yaml:"addCloudwatchTimestamp"`
NilToZero *bool `yaml:"nilToZero"`
Regions []string `yaml:"regions"`
Type string `yaml:"type"`
Roles []Role `yaml:"roles"`
SearchTags []Tag `yaml:"searchTags"`
CustomTags []Tag `yaml:"customTags"`
DimensionNameRequirements []string `yaml:"dimensionNameRequirements"`
Metrics []*Metric `yaml:"metrics"`
Length int64 `yaml:"length"`
Delay int64 `yaml:"delay"`
Period int64 `yaml:"period"`
RoundingPeriod *int64 `yaml:"roundingPeriod"`
Statistics []string `yaml:"statistics"`
AddCloudwatchTimestamp *bool `yaml:"addCloudwatchTimestamp"`
NilToZero *bool `yaml:"nilToZero"`
}

type Static struct {
Expand Down

0 comments on commit 6d10019

Please sign in to comment.