Skip to content

Commit

Permalink
feat(stackdriver): Add support for composing queries using global res…
Browse files Browse the repository at this point in the history
…ource type. (#171)
  • Loading branch information
Matt Duftler committed Dec 20, 2017
1 parent b5a0dda commit c7514af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public Map queryMetrics(@RequestParam(required = false) final String metricsAcco
@RequestParam(required = false) List<String> groupByFields, // metric.label.instance_name
@RequestParam(required = false) final String project,
@ApiParam(defaultValue = "gce_instance") @RequestParam String resourceType,
@ApiParam(defaultValue = "us-central1") @RequestParam String region,
@ApiParam(defaultValue = "myapp-v059") @RequestParam String scope,
@ApiParam(defaultValue = "us-central1") @RequestParam(required = false) String region,
@ApiParam(defaultValue = "myapp-v059") @RequestParam(required = false) String scope,
@ApiParam(defaultValue = "2017-11-21T12:48:00Z") @RequestParam Instant startTimeIso,
@ApiParam(defaultValue = "2017-11-21T12:51:00Z") @RequestParam Instant endTimeIso,
@ApiParam(defaultValue = "3600") @RequestParam Long step,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,28 @@ public List<MetricSet> queryMetrics(String metricsAccountName,

String customFilter = expandCustomFilter(canaryConfig, stackdriverMetricSetQuery, stackdriverCanaryScope);
String filter = "metric.type=\"" + stackdriverMetricSetQuery.getMetricType() + "\"" +
" AND resource.type=" + resourceType +
" AND ";
" AND resource.type=" + resourceType;

// TODO(duftler): Replace direct string-manipulating with helper functions.
// TODO-maybe(duftler): Replace this logic with a library of templates, one for each resource type.
// TODO(duftler): Support 'global' resource type.
if (StringUtils.isEmpty(customFilter)) {
if ("gce_instance".equals(resourceType)) {
filter += "resource.labels.project_id=" + projectId +
filter += " AND resource.labels.project_id=" + projectId +
" AND metadata.user_labels.\"spinnaker-region\"=" + region +
" AND metadata.user_labels.\"spinnaker-server-group\"=" + stackdriverCanaryScope.getScope();
} else if ("aws_ec2_instance".equals(resourceType)) {
filter += "resource.labels.region=\"aws:" + region + "\"" +
filter += " AND resource.labels.region=\"aws:" + region + "\"" +
" AND metadata.user_labels.\"aws:autoscaling:groupname\"=" + stackdriverCanaryScope.getScope();
} else if ("gae_app".equals(resourceType)) {
filter += "resource.labels.project_id=" + projectId +
filter += " AND resource.labels.project_id=" + projectId +
" AND resource.labels.version_id=" + stackdriverCanaryScope.getScope();

Map<String, String> extendedScopeParams = stackdriverCanaryScope.getExtendedScopeParams();

if (extendedScopeParams != null && extendedScopeParams.containsKey("service")) {
filter += " AND resource.labels.module_id=" + extendedScopeParams.get("service");
}
} else {
} else if (!"global".equals(resourceType)) {
throw new IllegalArgumentException("Resource type '" + resourceType + "' not yet supported.");
}
} else {
Expand Down

0 comments on commit c7514af

Please sign in to comment.