Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 9fe5794

Browse files
author
Joe Sondow
committed
ASGARD-1261 - Create monitoring bucket type of "none"
A new monitor bucket type on the application config which allows for a monitoring type of "none". This will result in an empty string for the value of the monitor bucket to be inserted into the user data of a launch config. This is part of our migration to a model that generally does not use this deploy-time setting for monitoring decisions.
1 parent 76f20e0 commit 9fe5794

File tree

5 files changed

+79
-12
lines changed

5 files changed

+79
-12
lines changed

grails-app/services/com/netflix/asgard/ApplicationService.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,17 @@ class ApplicationService implements CacheInitializer, InitializingBean {
232232
}
233233

234234
/**
235-
* Provides a string to use for monitoring bucket, either provided cluster name or app name based on the
236-
* application settings. If the application is not found, the app name is returned.
235+
* Provides a string to use for monitoring bucket, either provided an empty string, cluster name or app name based
236+
* on the application settings.
237237
*
238238
* @param userContext who, where, why
239-
* @param appName application name to lookup
239+
* @param appName application name to look up, and the value to return if the bucket type is 'application'
240240
* @param clusterName value to return if the application's monitor bucket type is 'cluster'
241-
* @return appName or clusterName parameter, based on the application's monitorBucketType
241+
* @return appName or clusterName or empty string, based on the application's monitorBucketType
242242
*/
243243
String getMonitorBucket(UserContext userContext, String appName, String clusterName) {
244-
MonitorBucketType bucketType = getRegisteredApplication(userContext, appName)?.monitorBucketType
245-
(bucketType == MonitorBucketType.cluster) ? clusterName : appName
244+
MonitorBucketType type = getRegisteredApplication(userContext, appName)?.monitorBucketType
245+
type == MonitorBucketType.application ? appName : type == MonitorBucketType.cluster ? clusterName : ''
246246
}
247247
}
248248

grails-app/views/application/create.gsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<td class="value">
101101
<select id="monitorBucketType" name="monitorBucketType">
102102
<g:each var="bucketType" in="${MonitorBucketType.values()}">
103-
<option ${MonitorBucketType.getDefaultForNewApps() == bucketType.name() ? 'selected' : ''} value="${bucketType.name()}">${bucketType.description}</option>
103+
<option ${MonitorBucketType.getDefaultForNewApps() == bucketType ? 'selected' : ''} value="${bucketType.name()}">${bucketType.description}</option>
104104
</g:each>
105105
</select>
106106
</td>

src/groovy/com/netflix/asgard/model/MonitorBucketType.groovy

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ package com.netflix.asgard.model
2020
*/
2121
enum MonitorBucketType {
2222

23-
application, cluster
23+
none('none (Do not configure monitoring)'),
24+
application('application (Aggregate monitoring data by application)'),
25+
cluster('cluster (Aggregate monitoring data by cluster)')
2426

25-
String getDescription() {
26-
"Aggregate monitoring data by ${name()}"
27+
/**
28+
* Human-readable explanation of the type for display on web pages.
29+
*/
30+
String description
31+
32+
MonitorBucketType(String description) {
33+
this.description = description
2734
}
2835

2936
/**
@@ -36,7 +43,13 @@ enum MonitorBucketType {
3643
return name ? MonitorBucketType.values().find { it.name() == name } as MonitorBucketType : null
3744
}
3845

39-
static MonitorBucketType getDefaultForOldApps() { application }
46+
/**
47+
* @return the type that should be used if an application does not have any monitor bucket type specified
48+
*/
49+
static MonitorBucketType getDefaultForOldApps() { none }
4050

41-
static MonitorBucketType getDefaultForNewApps() { cluster }
51+
/**
52+
* @return the type that should be prepopulated when creating a new application via a web form
53+
*/
54+
static MonitorBucketType getDefaultForNewApps() { none }
4255
}

test/unit/com/netflix/asgard/ApplicationServiceUnitSpec.groovy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.amazonaws.services.simpledb.AmazonSimpleDB
1919
import com.netflix.asgard.mock.Mocks
2020
import com.netflix.asgard.model.MonitorBucketType
2121
import spock.lang.Specification
22+
import spock.lang.Unroll
2223

2324
@SuppressWarnings("GroovyAssignabilityCheck")
2425
class ApplicationServiceUnitSpec extends Specification {
@@ -86,4 +87,20 @@ class ApplicationServiceUnitSpec extends Specification {
8687
1 * applicationService.simpleDbClient.putAttributes(_)
8788
notThrown(NullPointerException)
8889
}
90+
91+
@Unroll('monitor bucket should be "#monitorBucket" if monitor bucket type is #type')
92+
def 'monitor bucket value should depend on monitor bucket type'() {
93+
94+
AppRegistration app = new AppRegistration(name: 'hello', monitorBucketType: MonitorBucketType.byName(type))
95+
applicationService.getRegisteredApplication(_, _) >> app
96+
97+
expect:
98+
monitorBucket == applicationService.getMonitorBucket(UserContext.auto(), 'hello', 'hello-there')
99+
100+
where:
101+
type | monitorBucket
102+
'none' | ''
103+
'application' | 'hello'
104+
'cluster' | 'hello-there'
105+
}
89106
}

test/unit/com/netflix/asgard/NetflixAdvancedUserDataProviderSpec.groovy

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.amazonaws.services.ec2.model.Tag
2020
import com.netflix.asgard.model.AutoScalingGroupBeanOptions
2121
import com.netflix.asgard.model.LaunchConfigurationBeanOptions
2222
import com.netflix.asgard.model.LaunchContext
23+
import com.netflix.asgard.model.MonitorBucketType
2324
import com.netflix.asgard.plugin.UserDataProvider
2425
import javax.xml.bind.DatatypeConverter
2526
import spock.lang.Specification
@@ -99,6 +100,42 @@ class NetflixAdvancedUserDataProviderSpec extends Specification {
99100
111.1 | helloStandardUserData
100101
}
101102

103+
@Unroll('monitor bucket should be "#monitorBucket" if monitor bucket type is #type')
104+
def 'monitor bucket should be empty, cluster, or app name as requested'() {
105+
106+
String description = "blah blah blah, ancestor_version=nflx-base-2.0-12345-h24"
107+
launchContext.image = new Image(description: description)
108+
AppRegistration app = new AppRegistration(name: 'hi', monitorBucketType: MonitorBucketType.byName(type))
109+
launchContext.application = app
110+
launchContext.autoScalingGroup = new AutoScalingGroupBeanOptions(autoScalingGroupName: 'hi-dev-v001')
111+
launchContext.launchConfiguration = new LaunchConfigurationBeanOptions(
112+
launchConfigurationName: 'hi-dev-v001-1234567')
113+
netflixAdvancedUserDataProvider.applicationService = Spy(ApplicationService) {
114+
getRegisteredApplication(_, _) >> app
115+
}
116+
117+
when:
118+
String userData = decode(netflixAdvancedUserDataProvider.buildUserData(launchContext))
119+
120+
then:
121+
userData == """\
122+
export NETFLIX_ENVIRONMENT=test
123+
export NETFLIX_MONITOR_BUCKET=${monitorBucket ?: ''}
124+
export NETFLIX_APP=hi
125+
export NETFLIX_STACK=dev
126+
export NETFLIX_CLUSTER=hi-dev
127+
export NETFLIX_AUTO_SCALE_GROUP=hi-dev-v001
128+
export NETFLIX_LAUNCH_CONFIG=hi-dev-v001-1234567
129+
export EC2_REGION=us-west-2
130+
""".stripIndent()
131+
132+
where:
133+
type | monitorBucket
134+
'none' | ''
135+
'cluster' | 'hi-dev'
136+
'application' | 'hi'
137+
}
138+
102139
def 'should build user data with legacy format if AMI description does not match the standard pattern'() {
103140

104141
launchContext.image = new Image(description: 'blah blah blah')

0 commit comments

Comments
 (0)