@Override public String buildQuery(String metricsAccountName, CanaryConfig canaryConfig, CanaryMetricConfig canaryMetricConfig, CanaryScope canaryScope) { DatadogCanaryMetricSetQueryConfig queryConfig = (DatadogCanaryMetricSetQueryConfig)canaryMetricConfig.getQuery(); return queryConfig.getMetricName() + "{" + canaryScope.getScope() + "}"; }
private CanaryScope getScopeForNamedScope(CanaryExecutionRequest executionRequest, String scopeName, boolean isCanary) { CanaryScopePair canaryScopePair = executionRequest.getScopes().get(scopeName); CanaryScope canaryScope = isCanary ? canaryScopePair.getExperimentScope() : canaryScopePair.getControlScope(); if (canaryScope == null) { throw new IllegalArgumentException("Canary scope for named scope " + scopeName + " is missing experimentScope or controlScope keys"); } return canaryScope; }
@Override public String buildQuery(String metricsAccountName, CanaryConfig canaryConfig, CanaryMetricConfig canaryMetricConfig, CanaryScope canaryScope) throws IOException { GraphiteCanaryMetricSetQueryConfig queryConfig = (GraphiteCanaryMetricSetQueryConfig) canaryMetricConfig.getQuery(); String query = queryConfig.getMetricName(); if (!Strings.isNullOrEmpty(canaryScope.getScope())) { query = query.replace(SCOPE_VARIABLE, canaryScope.getScope()); } if (!Strings.isNullOrEmpty(canaryScope.getLocation())) { query = query.replace(LOCATION_VARIABLE, canaryScope.getLocation()); } log.debug("Query sent to graphite: {}.", query); return query; }
@Override public CanaryScope buildCanaryScope(CanaryScope canaryScope) { SignalFxCanaryScope signalFxCanaryScope = new SignalFxCanaryScope(); signalFxCanaryScope.setScope(canaryScope.getScope()); signalFxCanaryScope.setLocation(canaryScope.getLocation()); signalFxCanaryScope.setStart(canaryScope.getStart()); signalFxCanaryScope.setEnd(canaryScope.getEnd()); signalFxCanaryScope.setStep(canaryScope.getStep()); Optional.ofNullable(canaryScope.getExtendedScopeParams()).ifPresent(extendedParameters -> { signalFxCanaryScope.setScopeKey(extendedParameters.getOrDefault(SCOPE_KEY_KEY, null)); signalFxCanaryScope.setLocationKey(extendedParameters.getOrDefault(LOCATION_KEY_KEY, null)); signalFxCanaryScope.setExtendedScopeParams(extendedParameters); }); return signalFxCanaryScope; } }
String resolvedMetricsAccountName, String resolvedStorageAccountName) { return IntStream.range(0, canaryConfig.getMetrics().size()) .mapToObj(index -> { CanaryMetricConfig metric = canaryConfig.getMetrics().get(index); String serviceType = metric.getQuery().getServiceType(); CanaryScopeFactory canaryScopeFactory = getScopeFactoryForServiceType(serviceType); if (metric.getScopeName() == null) { throw new IllegalArgumentException("Canary scope for metric named '" + metric.getName() + "' is null."); CanaryScope inspecificScope = getScopeForNamedScope(executionRequest, metric.getScopeName(), isCanary); CanaryScope scopeModel = canaryScopeFactory.buildCanaryScope(inspecificScope); String stagePrefix = (isCanary ? CanaryStageNames.REFID_FETCH_EXPERIMENT_PREFIX : CanaryStageNames.REFID_FETCH_CONTROL_PREFIX); String scopeJson;
private void validateManadtoryParams(InfluxdbCanaryMetricSetQueryConfig queryConfig, CanaryScope canaryScope) { if (StringUtils.isEmpty(queryConfig.getMetricName())) { throw new IllegalArgumentException("Measurement is required to query metrics"); } if (null == canaryScope) { throw new IllegalArgumentException("CanaryScope is missing"); } if (null == canaryScope.getStart() || null == canaryScope.getEnd()) { throw new IllegalArgumentException("Start and End times are required"); } }
private void checkForDuplicateCanaryConfig(CanaryConfig canaryConfig, String canaryConfigId, AwsNamedAccountCredentials credentials) { String canaryConfigName = canaryConfig.getName(); List<String> applications = canaryConfig.getApplications(); String existingCanaryConfigId = canaryConfigIndex.getIdFromName(credentials, canaryConfigName, applications); // We want to avoid creating a naming collision due to the renaming of an existing canary config. if (!StringUtils.isEmpty(existingCanaryConfigId) && !existingCanaryConfigId.equals(canaryConfigId)) { throw new IllegalArgumentException("Canary config with name '" + canaryConfigName + "' already exists in the scope of applications " + applications + "."); } }
private void addScopeFilter(CanaryScope canaryScope, StringBuilder sb) { String scope = canaryScope.getScope(); if (scope != null) { String[] scopeParts = validateAndExtractScope(scope); sb.append(" AND "); sb.append(scopeParts[0] + "='" + scopeParts[1] +"'"); } }
@VisibleForTesting public static CanaryConfig escapeTemplates(CanaryConfig canaryConfig) { if (!CollectionUtils.isEmpty(canaryConfig.getTemplates())) { Map<String, String> escapedTemplates = canaryConfig.getTemplates() .entrySet() .stream() .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().replace("${", "$\\{"))); canaryConfig = canaryConfig.toBuilder().templates(escapedTemplates).build(); } return canaryConfig; }
@Override public void processCompletedPipelineExecution(Execution execution) { CanaryExecutionStatusResponse canaryExecutionStatusResponse = executionMapper.fromExecution(execution); CanaryExecutionCompletedEvent canaryExecutionCompletedEvent = new CanaryExecutionCompletedEvent(this, canaryExecutionStatusResponse); applicationEventPublisher.publishEvent(canaryExecutionCompletedEvent); } }
private CanaryScopeFactory getScopeFactoryForServiceType(String serviceType) { return canaryScopeFactories .stream() .filter((f) -> f.handles(serviceType)).findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to resolve canary scope factory for '" + serviceType + "'.")); }
@Override public CanaryScope buildCanaryScope(CanaryScope canaryScope){ PrometheusCanaryScope prometheusCanaryScope = new PrometheusCanaryScope(); prometheusCanaryScope.setScope(canaryScope.getScope()); prometheusCanaryScope.setLocation(canaryScope.getLocation()); prometheusCanaryScope.setStart(canaryScope.getStart()); prometheusCanaryScope.setEnd(canaryScope.getEnd()); prometheusCanaryScope.setStep(canaryScope.getStep()); prometheusCanaryScope.setExtendedScopeParams(canaryScope.getExtendedScopeParams()); Map<String, String> extendedScopeParams = prometheusCanaryScope.getExtendedScopeParams(); if (extendedScopeParams != null) { if (extendedScopeParams.containsKey("project")) { prometheusCanaryScope.setProject(extendedScopeParams.get("project")); } if (extendedScopeParams.containsKey("resourceType")) { prometheusCanaryScope.setResourceType(extendedScopeParams.get("resourceType")); } } return prometheusCanaryScope; } }
private void checkForDuplicateCanaryConfig(CanaryConfig canaryConfig, String canaryConfigId, ConfigBinNamedAccountCredentials credentials) { String canaryConfigName = canaryConfig.getName(); List<String> applications = canaryConfig.getApplications(); String existingCanaryConfigId = canaryConfigIndex.getIdFromName(credentials, canaryConfigName, applications); // We want to avoid creating a naming collision due to the renaming of an existing canary config. if (!StringUtils.isEmpty(existingCanaryConfigId) && !existingCanaryConfigId.equals(canaryConfigId)) { throw new IllegalArgumentException("Canary config with name '" + canaryConfigName + "' already exists in the scope of applications " + applications + "."); } }
@ApiOperation(value = "Retrieve status and results for a canary run") @RequestMapping(value = "/{canaryExecutionId:.+}", method = RequestMethod.GET) public CanaryExecutionStatusResponse getCanaryResults(@RequestParam(required = false) final String storageAccountName, @PathVariable String canaryExecutionId) { String resolvedStorageAccountName = CredentialsHelper.resolveAccountByNameOrType(storageAccountName, AccountCredentials.Type.OBJECT_STORE, accountCredentialsRepository); Execution pipeline = executionRepository.retrieve(Execution.ExecutionType.PIPELINE, canaryExecutionId); return executionMapper.fromExecution(resolvedStorageAccountName, pipeline); }
@Override public CanaryScope buildCanaryScope(CanaryScope canaryScope) { Map<String, String> extendedParameters = Optional.ofNullable(canaryScope.getExtendedScopeParams()) .orElseThrow(() -> new IllegalArgumentException("New Relic requires extended parameters")); NewRelicCanaryScope newRelicCanaryScope = new NewRelicCanaryScope(); newRelicCanaryScope.setScope(canaryScope.getScope()); newRelicCanaryScope.setStart(canaryScope.getStart()); newRelicCanaryScope.setEnd(canaryScope.getEnd()); newRelicCanaryScope.setStep(canaryScope.getStep()); newRelicCanaryScope.setExtendedScopeParams(extendedParameters); newRelicCanaryScope.setScopeKey(getRequiredExtendedParam(SCOPE_KEY_KEY, extendedParameters)); return newRelicCanaryScope; }
private void checkForDuplicateCanaryConfig(CanaryConfig canaryConfig, String canaryConfigId, GoogleNamedAccountCredentials credentials) { String canaryConfigName = canaryConfig.getName(); List<String> applications = canaryConfig.getApplications(); String existingCanaryConfigId = canaryConfigIndex.getIdFromName(credentials, canaryConfigName, applications); // We want to avoid creating a naming collision due to the renaming of an existing canary config. if (!StringUtils.isEmpty(existingCanaryConfigId) && !existingCanaryConfigId.equals(canaryConfigId)) { throw new IllegalArgumentException("Canary config with name '" + canaryConfigName + "' already exists in the scope of applications " + applications + "."); } }
@Override public CanaryScope buildCanaryScope(CanaryScope canaryScope){ StackdriverCanaryScope stackdriverCanaryScope = new StackdriverCanaryScope(); stackdriverCanaryScope.setScope(canaryScope.getScope()); stackdriverCanaryScope.setLocation(canaryScope.getLocation()); stackdriverCanaryScope.setStart(canaryScope.getStart()); stackdriverCanaryScope.setEnd(canaryScope.getEnd()); stackdriverCanaryScope.setStep(canaryScope.getStep()); stackdriverCanaryScope.setExtendedScopeParams(canaryScope.getExtendedScopeParams());
@Override public CanaryScope buildCanaryScope(CanaryScope canaryScope){ AtlasCanaryScope atlasCanaryScope = new AtlasCanaryScope(); atlasCanaryScope.setScope(canaryScope.getScope()); atlasCanaryScope.setLocation(canaryScope.getLocation()); atlasCanaryScope.setStart(canaryScope.getStart()); atlasCanaryScope.setEnd(canaryScope.getEnd()); atlasCanaryScope.setStep(canaryScope.getStep()); atlasCanaryScope.setExtendedScopeParams(canaryScope.getExtendedScopeParams()); Map<String, String> extendedScopeParams = atlasCanaryScope.getExtendedScopeParams(); if (extendedScopeParams == null) { extendedScopeParams = Collections.emptyMap(); } atlasCanaryScope.setType(extendedScopeParams.getOrDefault("type", "cluster")); atlasCanaryScope.setDeployment(extendedScopeParams.getOrDefault("deployment", "main")); atlasCanaryScope.setDataset(extendedScopeParams.getOrDefault("dataset", "regional")); atlasCanaryScope.setEnvironment(extendedScopeParams.getOrDefault("environment", "test")); return atlasCanaryScope; } }