Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws): allow enabledMetrics: [] to enable all metrics #6238

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ private String createAsg(

// enable metrics and monitoring
if (cfg.getEnabledMetrics() != null
&& !cfg.getEnabledMetrics().isEmpty()
&& cfg.getInstanceMonitoring() != null
&& cfg.getInstanceMonitoring()) {
task.updateStatus(taskPhase, "Enabling metrics collection for: " + asgName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,28 @@ class AsgWithLaunchConfigurationBuilderSpec extends Specification {
null | null | 0
[] | null | 0
[] | false | 0
[] | true | 0
['GroupMinSize', 'GroupMaxSize'] | null | 0
['GroupMinSize', 'GroupMaxSize'] | [] | 0
['GroupMinSize', 'GroupMaxSize'] | false | 0
['GroupMinSize', 'GroupMaxSize'] | true | 1
}

void "enables metrics collection for all metrics when enabledMetrics is an empty list and instanceMonitoring is true"() {
setup:
def asgWithLcBuilder = new AsgWithLaunchConfigurationBuilder(lcBuilder, autoScaling, amazonEC2, asgLifecycleHookWorker)
asgConfig.enabledMetrics = []
asgConfig.instanceMonitoring = true

when:
asgWithLcBuilder.build(task, taskPhase, asgName, asgConfig)

then:
// According to
// https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_EnableMetricsCollection.html,
// specifying granularity with no metrics means all metrics.
1 * autoScaling.enableMetricsCollection({ (it.granularity == '1Minute') && (it.metrics == []) })
}

void "continues if serverGroup already exists, is reasonably the same and within safety window"() {
given:
def asgWithLcBuilder = new AsgWithLaunchConfigurationBuilder(lcBuilder, autoScaling, amazonEC2, asgLifecycleHookWorker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,29 @@ class AsgWithLaunchTemplateBuilderSpec extends Specification {
null | null | 0
[] | null | 0
[] | false | 0
[] | true | 0
['GroupMinSize', 'GroupMaxSize'] | null | 0
['GroupMinSize', 'GroupMaxSize'] | [] | 0
['GroupMinSize', 'GroupMaxSize'] | false | 0
['GroupMinSize', 'GroupMaxSize'] | true | 1
}

void "enables metrics collection for all metrics when enabledMetrics is an empty list and instanceMonitoring is true"() {
setup:
def asgWithLtBuilder = new AsgWithLaunchTemplateBuilder(ltService, securityGroupService, deployDefaults, autoScaling, amazonEC2, asgLifecycleHookWorker)
asgConfig.enabledMetrics = []
asgConfig.instanceMonitoring = true

when:
asgWithLtBuilder.build(task, taskPhase, asgName, asgConfig)

then:
1 * ltService.createLaunchTemplate(asgConfig, asgName, _) >> lt
// According to
// https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_EnableMetricsCollection.html,
// specifying granularity with no metrics means all metrics.
1 * autoScaling.enableMetricsCollection({ (it.granularity == '1Minute') && (it.metrics == []) })
}

void "continues if serverGroup already exists, is reasonably the same and within safety window"() {
given:
def asgWithLtBuilder = new AsgWithLaunchTemplateBuilder(ltService, securityGroupService, deployDefaults, autoScaling, amazonEC2, asgLifecycleHookWorker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,29 @@ class AsgWithMixedInstancesPolicyBuilderSpec extends Specification {
null | null | 0
[] | null | 0
[] | false | 0
[] | true | 0
['GroupMinSize', 'GroupMaxSize'] | null | 0
['GroupMinSize', 'GroupMaxSize'] | [] | 0
['GroupMinSize', 'GroupMaxSize'] | false | 0
['GroupMinSize', 'GroupMaxSize'] | true | 1
}

void "enables metrics collection for all metrics when enabledMetrics is an empty list and instanceMonitoring is true"() {
setup:
def asgWithMipBuilder = new AsgWithMixedInstancesPolicyBuilder(ec2LtService, securityGroupService, deployDefaults, autoScaling, amazonEC2, asgLifecycleHookWorker)
asgConfig.enabledMetrics = []
asgConfig.instanceMonitoring = true

when:
asgWithMipBuilder.build(task, taskPhase, asgName, asgConfig)

then:
1 * ec2LtService.createLaunchTemplate(asgConfig, asgName, _) >> ec2Lt
// According to
// https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_EnableMetricsCollection.html,
// specifying granularity with no metrics means all metrics.
1 * autoScaling.enableMetricsCollection({ (it.granularity == '1Minute') && (it.metrics == []) })
}

void "continues if serverGroup already exists, is reasonably the same and within safety window"() {
given:
def asgWithMipBuilder = new AsgWithMixedInstancesPolicyBuilder(ec2LtService, securityGroupService, deployDefaults, autoScaling, amazonEC2, asgLifecycleHookWorker)
Expand Down
Loading