Skip to content

Commit

Permalink
Standardize on iso timestamps. (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Duftler committed Jul 18, 2017
1 parent 11d156f commit 73fec42
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.netflix.kayenta.canary.CanaryScopeFactory;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.Map;

@Component
Expand All @@ -31,16 +32,15 @@ public boolean handles(String serviceType) {
}

@Override
// TODO(duftler): Standardize on ISO timestamps.
public CanaryScope buildCanaryScope(String scope,
String startTimeMillis,
String endTimeMillis,
Instant startTimeInstant,
Instant endTimeInstant,
String step,
Map<String, String> extendedScopeParams) {
AtlasCanaryScope atlasCanaryScope = new AtlasCanaryScope();
atlasCanaryScope.setScope(scope);
atlasCanaryScope.setStart(startTimeMillis);
atlasCanaryScope.setEnd(endTimeMillis);
atlasCanaryScope.setStart(startTimeInstant.toEpochMilli() + "");
atlasCanaryScope.setEnd(endTimeInstant.toEpochMilli() + "");
atlasCanaryScope.setStep(step);

if (extendedScopeParams != null && extendedScopeParams.containsKey("type")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public List<MetricSet> queryMetrics(String accountName,
AtlasCanaryMetricSetQueryConfig atlasMetricSetQuery = (AtlasCanaryMetricSetQueryConfig)canaryMetricConfig.getQuery();
String decoratedQuery = atlasMetricSetQuery.getQ() + "," + atlasCanaryScope.cq();
List<AtlasResults> atlasResultsList = atlasRemoteService.fetch(decoratedQuery,
atlasCanaryScope.getStart() + "",
atlasCanaryScope.getEnd() + "",
atlasCanaryScope.getStart(),
atlasCanaryScope.getEnd(),
atlasCanaryScope.getStep());
Map<String, AtlasResults> idToAtlasResultsMap = AtlasResultsHelper.merge(atlasResultsList);
List<MetricSet> metricSetList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

package com.netflix.kayenta.canary;

import java.time.Instant;
import java.util.Map;

public interface CanaryScopeFactory {

boolean handles(String serviceType);

CanaryScope buildCanaryScope(String scope,
String startTimeMillis,
String endTimeMillis,
Instant startTimeInstant,
Instant endTimeInstant,
String step,
Map<String, String> extendedScopeParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,16 @@ public boolean handles(String serviceType) {

@Override
public CanaryScope buildCanaryScope(String scope,
String startTimeMillis,
String endTimeMillis,
Instant startTimeInstant,
Instant endTimeInstant,
String step,
Map<String, String> extendedScopeParams) {
Instant intervalStartTimeIso = Instant.ofEpochMilli(Long.parseLong(startTimeMillis));
Instant intervalEndTimeIso = Instant.ofEpochMilli(Long.parseLong(endTimeMillis));

StackdriverCanaryScope stackdriverCanaryScope = new StackdriverCanaryScope();
stackdriverCanaryScope.setScope(scope);
stackdriverCanaryScope.setStart(startTimeMillis);
stackdriverCanaryScope.setEnd(endTimeMillis);
stackdriverCanaryScope.setIntervalStartTimeIso(intervalStartTimeIso + "");
stackdriverCanaryScope.setIntervalEndTimeIso(intervalEndTimeIso + "");
stackdriverCanaryScope.setStart(startTimeInstant.toEpochMilli() + "");
stackdriverCanaryScope.setEnd(endTimeInstant.toEpochMilli() + "");
stackdriverCanaryScope.setIntervalStartTimeIso(startTimeInstant + "");
stackdriverCanaryScope.setIntervalEndTimeIso(endTimeInstant + "");
stackdriverCanaryScope.setStep(step);

return stackdriverCanaryScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public String queryMetrics(@RequestParam(required = false) final String metricsA
@ApiParam(defaultValue = "compute.googleapis.com/instance/cpu/utilization") @RequestParam String metricType,
@RequestParam(required = false) List<String> groupByFields, // metric.label.instance_name
@ApiParam(defaultValue = "myapp-v010-") @RequestParam String scope,
@ApiParam(defaultValue = "2017-06-01T15:13:00Z") @RequestParam String intervalStartTimeIso,
@ApiParam(defaultValue = "2017-06-02T15:27:00Z") @RequestParam String intervalEndTimeIso,
@ApiParam(defaultValue = "2017-07-01T15:13:00Z") @RequestParam String intervalStartTimeIso,
@ApiParam(defaultValue = "2017-07-02T15:27:00Z") @RequestParam String intervalEndTimeIso,
@ApiParam(defaultValue = "3600") @RequestParam String step) throws IOException {
String resolvedMetricsAccountName = CredentialsHelper.resolveAccountByNameOrType(metricsAccountName,
AccountCredentials.Type.METRICS_STORE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -84,9 +85,8 @@ public String initiateCanary(@RequestParam(required = false) final String metric
@ApiParam(defaultValue = "MySampleStackdriverCanaryConfig") @RequestParam String canaryConfigId,
@ApiParam(defaultValue = "myapp-v010-") @RequestParam String controlScope,
@ApiParam(defaultValue = "myapp-v021-") @RequestParam String experimentScope,
// TODO(duftler): Standardize on ISO timestamps.
@ApiParam(defaultValue = "1496329980000") @RequestParam String startTimeMillis,
@ApiParam(defaultValue = "1496417220000") @RequestParam String endTimeMillis,
@ApiParam(defaultValue = "2017-07-01T15:13:00Z") @RequestParam String startTimeIso,
@ApiParam(defaultValue = "2017-07-02T15:27:00Z") @RequestParam String endTimeIso,
// TODO(duftler): Normalize this somehow. Stackdriver expects a number in seconds and Atlas expects a duration like PT10S.
@ApiParam(value = "Stackdriver expects a number in seconds and Atlas expects a duration like PT10S.", defaultValue = "3600") @RequestParam String step,
@ApiParam(value = "Atlas requires \"type\" to be set to application, cluster or node.") @RequestBody(required = false) Map<String, String> extendedScopeParams) {
Expand Down Expand Up @@ -121,10 +121,12 @@ public String initiateCanary(@RequestParam(required = false) final String metric
.filter((f) -> f.handles(serviceType)).findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unable to resolve canary scope factory for '" + serviceType + "'."));

Instant startTimeInstant = Instant.parse(startTimeIso);
Instant endTimeInstant = Instant.parse(endTimeIso);
CanaryScope controlScopeModel =
canaryScopeFactory.buildCanaryScope(controlScope, startTimeMillis, endTimeMillis, step, extendedScopeParams);
canaryScopeFactory.buildCanaryScope(controlScope, startTimeInstant, endTimeInstant, step, extendedScopeParams);
CanaryScope experimentScopeModel =
canaryScopeFactory.buildCanaryScope(experimentScope, startTimeMillis, endTimeMillis, step, extendedScopeParams);
canaryScopeFactory.buildCanaryScope(experimentScope, startTimeInstant, endTimeInstant, step, extendedScopeParams);

Map<String, Object> fetchControlContext =
Maps.newHashMap(
Expand Down
8 changes: 4 additions & 4 deletions scratch/stackdriver_pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"canaryConfigId": "MySampleStackdriverCanaryConfig",
"stackdriverCanaryScope": {
"scope": "myapp-v010-",
"intervalStartTimeIso": "2017-06-01T15:13:00Z",
"intervalEndTimeIso": "2017-06-02T15:27:00Z",
"intervalStartTimeIso": "2017-07-01T15:13:00Z",
"intervalEndTimeIso": "2017-07-02T15:27:00Z",
"step": "3600"
}
},
Expand All @@ -38,8 +38,8 @@
"canaryConfigId": "MySampleStackdriverCanaryConfig",
"stackdriverCanaryScope": {
"scope": "myapp-v021-",
"intervalStartTimeIso": "2017-06-01T15:13:00Z",
"intervalEndTimeIso": "2017-06-02T15:27:00Z",
"intervalStartTimeIso": "2017-07-01T15:13:00Z",
"intervalEndTimeIso": "2017-07-02T15:27:00Z",
"step": "3600"
}
},
Expand Down

0 comments on commit 73fec42

Please sign in to comment.