Skip to content

Commit

Permalink
chore(location): Replace region with location everywhere. (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Duftler committed Mar 30, 2018
1 parent 51f4c71 commit 3e6d82f
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public boolean handles(String serviceType) {
public CanaryScope buildCanaryScope(CanaryScope canaryScope){
AtlasCanaryScope atlasCanaryScope = new AtlasCanaryScope();
atlasCanaryScope.setScope(canaryScope.getScope());
atlasCanaryScope.setRegion(canaryScope.getRegion());
atlasCanaryScope.setLocation(canaryScope.getLocation());
atlasCanaryScope.setStart(canaryScope.getStart());
atlasCanaryScope.setEnd(canaryScope.getEnd());
atlasCanaryScope.setStep(canaryScope.getStep());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco
@ApiParam(defaultValue = "cpu") @RequestParam String metricSetName,
@ApiParam(defaultValue = "cluster") @RequestParam String type,
@RequestParam String scope,
@ApiParam(defaultValue = "us-east-1") @RequestParam String region,
@ApiParam(defaultValue = "us-east-1") @RequestParam String location,
@ApiParam(defaultValue = "2000-01-01T00:00:00Z") @RequestParam Instant start,
@ApiParam(defaultValue = "2000-01-01T04:00:00Z") @RequestParam Instant end,
@ApiParam(defaultValue = "300") @RequestParam Long step) throws IOException {
Expand All @@ -84,7 +84,7 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco
AtlasCanaryScope atlasCanaryScope = new AtlasCanaryScope();
atlasCanaryScope.setType(type);
atlasCanaryScope.setScope(scope);
atlasCanaryScope.setRegion(region);
atlasCanaryScope.setLocation(location);
atlasCanaryScope.setStart(start);
atlasCanaryScope.setEnd(end);
atlasCanaryScope.setStep(step);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ public List<MetricSet> queryMetrics(String accountName,
.orElseThrow(() -> new IllegalArgumentException("Unable to resolve account " + accountName + "."));
Optional<Backend> backend = credentials.getBackendUpdater().getBackendDatabase().getOne(atlasCanaryScope.getDeployment(),
atlasCanaryScope.getDataset(),
atlasCanaryScope.getRegion(),
atlasCanaryScope.getLocation(),
atlasCanaryScope.getEnvironment());
if (!backend.isPresent()) {
throw new IllegalArgumentException("Unable to find an appropriate Atlas cluster for" +
" region=" + atlasCanaryScope.getRegion() +
" region=" + atlasCanaryScope.getLocation() +
" dataset=" + atlasCanaryScope.getDataset() +
" deployment=" + atlasCanaryScope.getDeployment() +
" environment=" + atlasCanaryScope.getEnvironment());
Expand All @@ -117,7 +117,7 @@ public List<MetricSet> queryMetrics(String accountName,
String uri = backend.get().getUri("http",
atlasCanaryScope.getDeployment(),
atlasCanaryScope.getDataset(),
atlasCanaryScope.getRegion(),
atlasCanaryScope.getLocation(),
atlasCanaryScope.getEnvironment());
RemoteService remoteService = new RemoteService();
log.info("Using Atlas backend {}", uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class CanaryScope {
protected String scope;

@NotNull
private String region;
private String location;

@NotNull
protected Instant start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco
.query(datadogCanaryMetricSetQueryConfig)
.build();

CanaryScope canaryScope = new CanaryScope(scope, null /* region */, Instant.parse(start), Instant.parse(end), step, Collections.emptyMap());
CanaryScope canaryScope = new CanaryScope(scope, null /* location */, Instant.parse(start), Instant.parse(end), step, Collections.emptyMap());

String metricSetListId = synchronousQueryProcessor.processQuery(resolvedMetricsAccountName,
resolvedStorageAccountName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public boolean handles(String serviceType) {
public CanaryScope buildCanaryScope(CanaryScope canaryScope){
PrometheusCanaryScope prometheusCanaryScope = new PrometheusCanaryScope();
prometheusCanaryScope.setScope(canaryScope.getScope());
prometheusCanaryScope.setRegion(canaryScope.getRegion());
prometheusCanaryScope.setLocation(canaryScope.getLocation());
prometheusCanaryScope.setStart(canaryScope.getStart());
prometheusCanaryScope.setEnd(canaryScope.getEnd());
prometheusCanaryScope.setStep(canaryScope.getStep());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PrometheusConfigurationTestControllerDefaultProperties {

@Getter
@Setter
private String region;
private String location;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco
@ApiParam(value = "Used to identify the type of the resource being queried, " +
"e.g. aws_ec2_instance, gce_instance.")
@RequestParam(required = false) String resourceType,
@ApiParam(value = "The region to use when scoping the query. Valid choices depend on what cloud " +
"platform the query relates to.")
@RequestParam(required = false) String region,
@ApiParam(value = "The location to use when scoping the query. Valid choices depend on what cloud " +
"platform the query relates to (could be a region, a namespace, or something else).")
@RequestParam(required = false) String location,
@ApiParam(value = "The name of the resource to use when scoping the query. " +
"The most common use-case is to provide a server group name.")
@RequestParam(required = false) String scope,
Expand All @@ -87,7 +87,7 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco
// Apply defaults.
project = determineDefaultProperty(project, "project", prometheusConfigurationTestControllerDefaultProperties);
resourceType = determineDefaultProperty(resourceType, "resourceType", prometheusConfigurationTestControllerDefaultProperties);
region = determineDefaultProperty(region, "region", prometheusConfigurationTestControllerDefaultProperties);
location = determineDefaultProperty(location, "location", prometheusConfigurationTestControllerDefaultProperties);
scope = determineDefaultProperty(scope, "scope", prometheusConfigurationTestControllerDefaultProperties);
start = determineDefaultProperty(start, "start", prometheusConfigurationTestControllerDefaultProperties);
end = determineDefaultProperty(end, "end", prometheusConfigurationTestControllerDefaultProperties);
Expand Down Expand Up @@ -127,7 +127,7 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco

PrometheusCanaryScope prometheusCanaryScope = new PrometheusCanaryScope();
prometheusCanaryScope.setScope(scope);
prometheusCanaryScope.setRegion(region);
prometheusCanaryScope.setLocation(location);
prometheusCanaryScope.setResourceType(resourceType);
prometheusCanaryScope.setStart(Instant.parse(start));
prometheusCanaryScope.setEnd(Instant.parse(end));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ private StringBuilder addScopeFilter(StringBuilder queryBuilder,
String customFilter) {
String scope = prometheusCanaryScope.getScope();
String projectId = prometheusCanaryScope.getProject();
String region = prometheusCanaryScope.getRegion();
String location = prometheusCanaryScope.getLocation();
List<String> filters = queryConfig.getLabelBindings();
if (filters == null) {
filters = new ArrayList<>();
}

if (StringUtils.isEmpty(customFilter)) {
if ("gce_instance".equals(resourceType)) {
addGCEFilters(scopeLabel, scope, projectId, region, filters);
addGCEFilters(scopeLabel, scope, projectId, location, filters);
} else if ("aws_ec2_instance".equals(resourceType)) {
addEC2Filters("asg_groupName", scope, region, filters);
addEC2Filters("asg_groupName", scope, location, filters);
} else if (!StringUtils.isEmpty(resourceType)) {
throw new IllegalArgumentException("There is no explicit support for resourceType '" + resourceType + "'. " +
"You may build whatever query makes sense for your environment via label " +
Expand Down Expand Up @@ -132,9 +132,9 @@ private StringBuilder addScopeFilter(StringBuilder queryBuilder,
return queryBuilder;
}

private static void addGCEFilters(String scopeLabel, String scope, String projectId, String region, List<String> filters) {
if (StringUtils.isEmpty(region)) {
throw new IllegalArgumentException("Region is required when resourceType is 'gce_instance'.");
private static void addGCEFilters(String scopeLabel, String scope, String projectId, String location, List<String> filters) {
if (StringUtils.isEmpty(location)) {
throw new IllegalArgumentException("Location (i.e. region) is required when resourceType is 'gce_instance'.");
}

if (!StringUtils.isEmpty(scope)) {
Expand All @@ -149,20 +149,20 @@ private static void addGCEFilters(String scopeLabel, String scope, String projec
zoneRegex += "projects/" + projectId + "/";
}

zoneRegex += "zones/" + region + "-.{1}";
zoneRegex += "zones/" + location + "-.{1}";
filters.add("zone=~\"" + zoneRegex + "\"");
}

private static void addEC2Filters(String scopeLabel, String scope, String region, List<String> filters) {
if (StringUtils.isEmpty(region)) {
throw new IllegalArgumentException("Region is required when resourceType is 'aws_ec2_instance'.");
private static void addEC2Filters(String scopeLabel, String scope, String location, List<String> filters) {
if (StringUtils.isEmpty(location)) {
throw new IllegalArgumentException("Location (i.e. region) is required when resourceType is 'aws_ec2_instance'.");
}

if (!StringUtils.isEmpty(scope)) {
filters.add(scopeLabel + "=\"" + scope + "\"");
}

filters.add("zone=~\"" + region + ".{1}\"");
filters.add("zone=~\"" + location + ".{1}\"");
}

private static StringBuilder addAvgQuery(StringBuilder queryBuilder) {
Expand Down Expand Up @@ -216,7 +216,7 @@ public List<MetricSet> queryMetrics(String accountName,
canaryConfig,
queryConfig,
prometheusCanaryScope,
new String[]{"project", "resourceType", "scope", "region"});
new String[]{"project", "resourceType", "scope", "location"});

StringBuilder queryBuilder = new StringBuilder(queryConfig.getMetricName());
queryBuilder = addScopeFilter(queryBuilder, prometheusCanaryScope, resourceType, queryConfig, customFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public boolean handles(String serviceType) {
public CanaryScope buildCanaryScope(CanaryScope canaryScope){
StackdriverCanaryScope stackdriverCanaryScope = new StackdriverCanaryScope();
stackdriverCanaryScope.setScope(canaryScope.getScope());
stackdriverCanaryScope.setRegion(canaryScope.getRegion());
stackdriverCanaryScope.setLocation(canaryScope.getLocation());
stackdriverCanaryScope.setStart(canaryScope.getStart());
stackdriverCanaryScope.setEnd(canaryScope.getEnd());
stackdriverCanaryScope.setStep(canaryScope.getStep());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class StackdriverConfigurationTestControllerDefaultProperties {

@Getter
@Setter
private String region;
private String location;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco
@ApiParam(value = "Used to identify the type of the resource being queried, " +
"e.g. aws_ec2_instance, gce_instance.")
@RequestParam(required = false) String resourceType,
@ApiParam(value = "The region to use when scoping the query. Valid choices depend on what cloud " +
"platform the query relates to.")
@RequestParam(required = false) String region,
@ApiParam(value = "The location to use when scoping the query. Valid choices depend on what cloud " +
"platform the query relates to (could be a region, a namespace, or something else).")
@RequestParam(required = false) String location,
@ApiParam(value = "The name of the resource to use when scoping the query. " +
"The most common use-case is to provide a server group name.")
@RequestParam(required = false) String scope,
Expand All @@ -90,7 +90,7 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco
// Apply defaults.
project = determineDefaultProperty(project, "project", stackdriverConfigurationTestControllerDefaultProperties);
resourceType = determineDefaultProperty(resourceType, "resourceType", stackdriverConfigurationTestControllerDefaultProperties);
region = determineDefaultProperty(region, "region", stackdriverConfigurationTestControllerDefaultProperties);
location = determineDefaultProperty(location, "location", stackdriverConfigurationTestControllerDefaultProperties);
scope = determineDefaultProperty(scope, "scope", stackdriverConfigurationTestControllerDefaultProperties);
startTimeIso = determineDefaultProperty(startTimeIso, "start", stackdriverConfigurationTestControllerDefaultProperties);
endTimeIso = determineDefaultProperty(endTimeIso, "end", stackdriverConfigurationTestControllerDefaultProperties);
Expand Down Expand Up @@ -132,7 +132,7 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco

StackdriverCanaryScope stackdriverCanaryScope = new StackdriverCanaryScope();
stackdriverCanaryScope.setScope(scope);
stackdriverCanaryScope.setRegion(region);
stackdriverCanaryScope.setLocation(location);
stackdriverCanaryScope.setResourceType(resourceType);
stackdriverCanaryScope.setStart(Instant.parse(startTimeIso));
stackdriverCanaryScope.setEnd(Instant.parse(endTimeIso));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<MetricSet> queryMetrics(String metricsAccountName,
Monitoring monitoring = stackdriverCredentials.getMonitoring();
StackdriverCanaryMetricSetQueryConfig stackdriverMetricSetQuery = (StackdriverCanaryMetricSetQueryConfig)canaryMetricConfig.getQuery();
String projectId = stackdriverCanaryScope.getProject();
String region = stackdriverCanaryScope.getRegion();
String location = stackdriverCanaryScope.getLocation();
String scope = stackdriverCanaryScope.getScope();
String resourceType = stackdriverCanaryScope.getResourceType();

Expand All @@ -129,7 +129,7 @@ public List<MetricSet> queryMetrics(String metricsAccountName,
canaryConfig,
stackdriverMetricSetQuery,
stackdriverCanaryScope,
new String[]{"project", "resourceType", "scope", "region"});
new String[]{"project", "resourceType", "scope", "location"});
String filter = "metric.type=\"" + stackdriverMetricSetQuery.getMetricType() + "\"" +
" AND resource.type=" + resourceType;

Expand All @@ -141,27 +141,27 @@ public List<MetricSet> queryMetrics(String metricsAccountName,
}

if ("gce_instance".equals(resourceType)) {
if (StringUtils.isEmpty(region)) {
throw new IllegalArgumentException("Region is required when resourceType is 'gce_instance'.");
if (StringUtils.isEmpty(location)) {
throw new IllegalArgumentException("Location (i.e. region) is required when resourceType is 'gce_instance'.");
}

if (StringUtils.isEmpty(scope)) {
throw new IllegalArgumentException("Scope is required when resourceType is 'gce_instance'.");
}

filter += " AND resource.labels.project_id=" + projectId +
" AND metadata.user_labels.\"spinnaker-region\"=" + region +
" AND metadata.user_labels.\"spinnaker-region\"=" + location +
" AND metadata.user_labels.\"spinnaker-server-group\"=" + scope;
} else if ("aws_ec2_instance".equals(resourceType)) {
if (StringUtils.isEmpty(region)) {
throw new IllegalArgumentException("Region is required when resourceType is 'aws_ec2_instance'.");
if (StringUtils.isEmpty(location)) {
throw new IllegalArgumentException("Location (i.e. region) is required when resourceType is 'aws_ec2_instance'.");
}

if (StringUtils.isEmpty(scope)) {
throw new IllegalArgumentException("Scope is required when resourceType is 'aws_ec2_instance'.");
}

filter += " AND resource.labels.region=\"aws:" + region + "\"" +
filter += " AND resource.labels.region=\"aws:" + location + "\"" +
" AND metadata.user_labels.\"aws:autoscaling:groupname\"=" + scope;
} else if ("gae_app".equals(resourceType)) {
if (StringUtils.isEmpty(scope)) {
Expand Down Expand Up @@ -237,8 +237,8 @@ public List<MetricSet> queryMetrics(String metricsAccountName,
long endTime = registry.clock().monotonicTime();
Id stackdriverFetchTimerId = registry.createId("stackdriver.fetchTime").withTag("project", projectId);

if (!StringUtils.isEmpty(region)) {
stackdriverFetchTimerId = stackdriverFetchTimerId.withTag("region", region);
if (!StringUtils.isEmpty(location)) {
stackdriverFetchTimerId = stackdriverFetchTimerId.withTag("location", location);
}

registry.timer(stackdriverFetchTimerId).record(endTime - startTime, TimeUnit.NANOSECONDS);
Expand Down
Loading

0 comments on commit 3e6d82f

Please sign in to comment.