Skip to content

Commit

Permalink
Get atlas metrics service working against updated Atlas. (#29)
Browse files Browse the repository at this point in the history
Add 'node' scope type to atlas canary scope.
Drop stupidPretendScheduler from orca lib test in favor of @EnableScheduling.
  • Loading branch information
Matt Duftler committed May 29, 2017
1 parent 79155d1 commit 4ad0641
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public class AtlasCanaryScope extends CanaryScope {
public String cq() {
switch (type) {
case "application":
return ":list,(,nf.app," + scope + ",:eq,:cq,),:each";
case "cluster":
return ":list,(,nf.cluster," + scope + ",:eq,:cq,),:each";
case "node":
return ":list,(,nf." + type + "," + scope + ",:eq,:cq,),:each";
default:
throw new IllegalArgumentException("Scope type is unknown: " + scope);
throw new IllegalArgumentException("Scope type '" + type + "' is unknown: scope=" + scope);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public String queryMetrics(@RequestParam(required = false) final String metricsA
@ApiParam(defaultValue = "cpu") @RequestParam String metricSetName,
@ApiParam(defaultValue = "cluster") @RequestParam String type,
@RequestParam String scope,
@ApiParam(defaultValue = "0") @RequestParam Long start,
@ApiParam(defaultValue = "6000000") @RequestParam Long end,
@ApiParam(defaultValue = "0") @RequestParam String start,
@ApiParam(defaultValue = "6000000") @RequestParam String end,
@ApiParam(defaultValue = "PT1M") @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 @@ -69,8 +69,8 @@ private CanaryConfig getConfig(String filename) throws IOException {

private CanaryMetricConfigWithResults queryMetric(CanaryMetricConfig metric, AtlasCanaryScope scope) {
long step = Duration.parse(scope.getStep()).toMillis();
long start = scope.getStart() / step * step;
long end = scope.getEnd() / step * step;
long start = Long.parseLong(scope.getStart()) / step * step;
long end = Long.parseLong(scope.getEnd()) / step * step;
long count = (end - start) / step;

AtlasMetricSetQuery atlasMetricSetQuery = (AtlasMetricSetQuery)metric.getQuery();
Expand Down Expand Up @@ -99,14 +99,14 @@ public void loadConfig() throws Exception {
AtlasCanaryScope experiment = new AtlasCanaryScope();
experiment.setType("application");
experiment.setScope("app_leo");
experiment.setStart(0L);
experiment.setEnd(600000L);
experiment.setStart("0");
experiment.setEnd("600000");
experiment.setStep("PT1M");
AtlasCanaryScope control = new AtlasCanaryScope();
control.setType("application");
control.setScope("app_lep");
control.setStart(0L);
control.setEnd(600000L);
control.setStart("0");
control.setEnd("600000");
control.setStep("PT1M");

// 3. for each metric in the config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public class CanaryScope {
protected String scope;

@NotNull
protected Long start;
protected String start;

@NotNull
protected Long end;
protected String end;

@NotNull
protected String step;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,24 @@
import com.netflix.spinnaker.orca.q.PipelineBuilderKt;
import com.netflix.spinnaker.orca.q.Queue;
import com.netflix.spinnaker.orca.q.QueueExecutionRunner;
import com.netflix.spinnaker.orca.q.QueueProcessor;
import com.netflix.spinnaker.orca.test.redis.EmbeddedRedisConfiguration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.PostConstruct;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicBoolean;

import static com.netflix.appinfo.InstanceInfo.InstanceStatus.OUT_OF_SERVICE;
import static com.netflix.appinfo.InstanceInfo.InstanceStatus.STARTING;
Expand Down Expand Up @@ -147,7 +144,9 @@ public void canRunASimplePipeline() {
RestrictExecutionDuringTimeWindow.class
})

@EnableScheduling
class TestConfig {

@Bean
Registry registry() {
return new NoopRegistry();
Expand Down Expand Up @@ -177,37 +176,6 @@ public String getType() {
};
}

@Bean
Object stupidPretendScheduler(QueueProcessor queueProcessor) {
return new DisposableBean() {
AtomicBoolean running = new AtomicBoolean(false);

@PostConstruct
void afterPropertiesSet() {
running.set(true);

new Thread(new Runnable() {
@Override
public void run() {
while (running.get()) {
queueProcessor.pollOnce();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}

@Override
public void destroy() throws Exception {
running.set(false);
}
};
}

@Bean
String currentInstanceId() {
return "localhost";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public String queryMetrics(@RequestParam(required = false) final String metricsA
if (metricsService.isPresent()) {
StackdriverCanaryScope stackdriverCanaryScope = new StackdriverCanaryScope();
stackdriverCanaryScope.setScope(scope);
stackdriverCanaryScope.setStart(startTimeMillis);
stackdriverCanaryScope.setEnd(endTimeMillis);
stackdriverCanaryScope.setStart(startTimeMillis + "");
stackdriverCanaryScope.setEnd(endTimeMillis + "");
stackdriverCanaryScope.setIntervalStartTimeIso(intervalStartTimeIso);
stackdriverCanaryScope.setIntervalEndTimeIso(intervalEndTimeIso);
stackdriverCanaryScope.setStep(step);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public List<MetricSet> queryMetrics(String accountName,

ListTimeSeriesResponse response = list.execute();

long elapsedSeconds = (stackdriverCanaryScope.getStart() - stackdriverCanaryScope.getEnd()) / 1000;
long startAsLong = Long.parseLong(stackdriverCanaryScope.getStart());
long endAsLong = Long.parseLong(stackdriverCanaryScope.getEnd());
long elapsedSeconds = (endAsLong - startAsLong) / 1000;
long numIntervals = elapsedSeconds / alignmentPeriodSec;
long remainder = elapsedSeconds % alignmentPeriodSec;

Expand Down

0 comments on commit 4ad0641

Please sign in to comment.