Skip to content

Commit

Permalink
Spectatorize (#139)
Browse files Browse the repository at this point in the history
Additional metrics for atlas queries and pipeline failure metric
  • Loading branch information
Michael Graff committed Dec 1, 2017
1 parent dd062ce commit 9821a37
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
import com.netflix.kayenta.retrofit.config.RemoteService;
import com.netflix.kayenta.retrofit.config.RetrofitClientFactory;
import com.netflix.kayenta.security.AccountCredentialsRepository;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Timer;
import com.squareup.okhttp.OkHttpClient;
import lombok.Builder;
import lombok.Getter;
import lombok.Singular;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.inject.Inject;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.time.Duration;
Expand All @@ -58,13 +61,16 @@ public class AtlasMetricsService implements MetricsService {
private List<String> accountNames;

@Autowired
AccountCredentialsRepository accountCredentialsRepository;
private final AccountCredentialsRepository accountCredentialsRepository;

@Autowired
RetrofitClientFactory retrofitClientFactory;
private final RetrofitClientFactory retrofitClientFactory;

@Autowired
AtlasSSEConverter atlasSSEConverter;
private final AtlasSSEConverter atlasSSEConverter;

@Autowired
private final Registry registry;

@Override
public String getType() {
Expand Down Expand Up @@ -121,12 +127,20 @@ public List<MetricSet> queryMetrics(String accountName,
AtlasCanaryMetricSetQueryConfig atlasMetricSetQuery = (AtlasCanaryMetricSetQueryConfig)canaryMetricConfig.getQuery();
String decoratedQuery = atlasMetricSetQuery.getQ() + "," + atlasCanaryScope.cq();
String isoStep = Duration.of(atlasCanaryScope.getStep(), SECONDS) + "";
List<AtlasResults> atlasResultsList = atlasRemoteService.fetch(decoratedQuery,
atlasCanaryScope.getStart().toEpochMilli(),
atlasCanaryScope.getEnd().toEpochMilli(),
isoStep,
credentials.getFetchId(),
UUID.randomUUID() + "");

long start = registry.clock().monotonicTime();
List < AtlasResults > atlasResultsList;
try {
atlasResultsList = atlasRemoteService.fetch(decoratedQuery,
atlasCanaryScope.getStart().toEpochMilli(),
atlasCanaryScope.getEnd().toEpochMilli(),
isoStep,
credentials.getFetchId(),
UUID.randomUUID() + "");
} finally {
long end = registry.clock().monotonicTime();
registry.timer("atlas.fetchTime").record(end - start, TimeUnit.NANOSECONDS);
}
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 @@ -24,6 +24,7 @@
import com.netflix.kayenta.storage.ObjectType;
import com.netflix.kayenta.storage.StorageService;
import com.netflix.kayenta.storage.StorageServiceRepository;
import com.netflix.spectator.api.Registry;
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.netflix.kayenta.storage.ObjectType;
import com.netflix.kayenta.storage.StorageService;
import com.netflix.kayenta.storage.StorageServiceRepository;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.Registry;
import com.netflix.spinnaker.orca.ExecutionStatus;
import com.netflix.spinnaker.orca.pipeline.ExecutionLauncher;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class CanaryController {
private final List<CanaryScopeFactory> canaryScopeFactories;
private final Registry registry;
private final ObjectMapper kayentaObjectMapper;
private final Id pipelineRunId;
private final Id failureId;

@Autowired
public CanaryController(String currentInstanceId,
Expand All @@ -88,6 +91,8 @@ public CanaryController(String currentInstanceId,

this.registry = registry;
this.kayentaObjectMapper = kayentaObjectMapper;
this.pipelineRunId = registry.createId("canary.pipelines.initiated");
this.failureId = registry.createId("canary.pipelines.startupFailed");
}

//
Expand Down Expand Up @@ -136,7 +141,7 @@ public CanaryExecutionResponse initiateCanary(@RequestParam(required = false) fi
.filter((f) -> f.handles(serviceType)).findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unable to resolve canary scope factory for '" + serviceType + "'."));

registry.counter(registry.createId("canary.pipelines.initiated")).increment();
registry.counter(pipelineRunId.withTag("canaryConfigId", canaryConfigId).withTag("canaryConfigName", canaryConfig.getName())).increment();

CanaryScope controlScopeModel = canaryScopeFactory.buildCanaryScope(canaryExecutionRequest.getControlScope());
CanaryScope experimentScopeModel = canaryScopeFactory.buildCanaryScope(canaryExecutionRequest.getExperimentScope());
Expand Down Expand Up @@ -314,6 +319,8 @@ private Execution handleStartupFailure(Execution execution, Throwable failure) {
executionRepository.updateStatus(execution.getId(), status);
executionRepository.cancel(execution.getId(), canceledBy, reason);

registry.counter(failureId).increment();

return executionRepository.retrieve(execution.getType(), execution.getId());
}
}

0 comments on commit 9821a37

Please sign in to comment.