@Override public AccountCredentials save(String name, AccountCredentials credentials) { return accountNameToCredentialsMap.put(credentials.getName(), credentials); } }
public static String resolveAccountByNameOrType(String accountName, AccountCredentials.Type accountType, AccountCredentialsRepository accountCredentialsRepository) { AccountCredentials credentials; if (StringUtils.hasLength(accountName)) { credentials = accountCredentialsRepository .getOne(accountName) .orElseThrow(() -> new IllegalArgumentException("Unable to resolve account " + accountName + ".")); } else { credentials = accountCredentialsRepository .getOne(accountType) .orElseThrow(() -> new IllegalArgumentException("Unable to resolve account of type " + accountType + ".")); } return credentials.getName(); }
public void startPendingUpdate(AccountCredentials credentials, String updatedTimestamp, CanaryConfigIndexAction action, String correlationId, String canaryConfigSummaryJson) { String accountName = credentials.getName(); String mapPendingUpdatesByApplicationKey = buildMapPendingUpdatesByApplicationKey(credentials, accountName); try (Jedis jedis = jedisPool.getResource()) { jedis.rpush(mapPendingUpdatesByApplicationKey, updatedTimestamp + ":" + action + ":start:" + correlationId + ":" + canaryConfigSummaryJson); } }
public void removeFailedPendingUpdate(AccountCredentials credentials, String updatedTimestamp, CanaryConfigIndexAction action, String correlationId, String canaryConfigSummaryJson) { String accountName = credentials.getName(); String mapPendingUpdatesByApplicationKey = buildMapPendingUpdatesByApplicationKey(credentials, accountName); try (Jedis jedis = jedisPool.getResource()) { jedis.lrem(mapPendingUpdatesByApplicationKey, 1, updatedTimestamp + ":" + action + ":start:" + correlationId + ":" + canaryConfigSummaryJson); } }
public void finishPendingUpdate(AccountCredentials credentials, CanaryConfigIndexAction action, String correlationId) { String accountName = credentials.getName(); String mapPendingUpdatesByApplicationKey = buildMapPendingUpdatesByApplicationKey(credentials, accountName); try (Jedis jedis = jedisPool.getResource()) { jedis.rpush(mapPendingUpdatesByApplicationKey, getRedisTime() + ":" + action + ":finish:" + correlationId); } }
@Bean @DependsOn({"registerGoogleCredentials"}) MetricsService stackdriverMetricsService(AccountCredentialsRepository accountCredentialsRepository) { StackdriverMetricsService.StackdriverMetricsServiceBuilder stackdriverMetricsServiceBuilder = StackdriverMetricsService.builder(); accountCredentialsRepository .getAll() .stream() .filter(c -> c instanceof GoogleNamedAccountCredentials) .filter(c -> c.getSupportedTypes().contains(AccountCredentials.Type.METRICS_STORE)) .map(c -> c.getName()) .forEach(stackdriverMetricsServiceBuilder::accountName); StackdriverMetricsService stackdriverMetricsService = stackdriverMetricsServiceBuilder.build(); log.info("Populated StackdriverMetricsService with {} Google accounts.", stackdriverMetricsService.getAccountNames().size()); return stackdriverMetricsService; } }
@Bean @DependsOn({"registerGoogleCredentials"}) public GcsStorageService gcsStorageService(AccountCredentialsRepository accountCredentialsRepository) { GcsStorageService.GcsStorageServiceBuilder gcsStorageServiceBuilder = GcsStorageService.builder(); accountCredentialsRepository .getAll() .stream() .filter(c -> c instanceof GoogleNamedAccountCredentials) .filter(c -> c.getSupportedTypes().contains(AccountCredentials.Type.OBJECT_STORE)) .map(c -> c.getName()) .forEach(gcsStorageServiceBuilder::accountName); GcsStorageService gcsStorageService = gcsStorageServiceBuilder.build(); log.info("Populated GcsStorageService with {} Google accounts.", gcsStorageService.getAccountNames().size()); return gcsStorageService; } }
@Bean @DependsOn({"registerAwsCredentials"}) public S3StorageService s3StorageService(AccountCredentialsRepository accountCredentialsRepository) { AmazonObjectMapperConfigurer.configure(kayentaObjectMapper); kayentaObjectMapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, true); S3StorageService.S3StorageServiceBuilder s3StorageServiceBuilder = S3StorageService.builder(); accountCredentialsRepository .getAll() .stream() .filter(c -> c instanceof AwsNamedAccountCredentials) .filter(c -> c.getSupportedTypes().contains(AccountCredentials.Type.OBJECT_STORE)) .map(c -> c.getName()) .forEach(s3StorageServiceBuilder::accountName); S3StorageService s3StorageService = s3StorageServiceBuilder.objectMapper(kayentaObjectMapper).build(); log.info("Populated S3StorageService with {} AWS accounts.", s3StorageService.getAccountNames().size()); return s3StorageService; } }
/** * Generates warnings that will be propigated in the aggregated results. */ protected List<String> getResultsWarnings(MonitorKayentaCanaryContext context, CanaryExecutionStatusResponse statusResponse) { List<String> warnings = new LinkedList<>(); String credentialType = ""; if (context.getMetricsAccountName() != null) { Set<? extends AccountCredentials> allCredentials = accountCredentialsRepository.getAll(); Optional<? extends AccountCredentials> credential = allCredentials.stream() .filter(cred -> cred.getName().equals(context.getMetricsAccountName())) .findAny(); if (credential.isPresent()) { credentialType = credential.get().getType(); } } // Datadog doesn't return data points in the same way as other metrics providers // and so are excluded here. See this Github comment for more information: // https://github.com/spinnaker/kayenta/issues/283#issuecomment-397346975 final ObjectMapper om = new ObjectMapper(); if (! credentialType.equals("datadog") && statusResponse.getResult().getJudgeResult().getResults().stream() .anyMatch(canaryAnalysisResult -> om.convertValue(canaryAnalysisResult.getControlMetadata().get("stats"), Stats.class).getCount() < 50)) { warnings.add("One of the metrics returned fewer than 50 data points, which can reduce confidence in the final canary score."); } return warnings; } }
@ApiOperation(value = "Retrieve a list of all configured metrics services") @RequestMapping(method = RequestMethod.GET) List<MetricsServiceDetail> list() { Set<AccountCredentials> metricAccountCredentials = CredentialsHelper.getAllAccountsOfType(METRICS_STORE, accountCredentialsRepository); return metricAccountCredentials .stream() .map(account -> MetricsServiceDetail .builder() .name(account.getName()) .type(account.getType()) .locations(account.getLocations()) .recommendedLocations(account.getRecommendedLocations()) .build()) .collect(Collectors.toList()); } }
String accountName = credentials.getName();
public Set<Map<String, Object>> getCanaryConfigSummarySet(AccountCredentials credentials, List<String> applications) { String accountName = credentials.getName(); String mapByApplicationKey = "kayenta:" + credentials.getType() + ":" + accountName + MAP_BY_APPLICATION_KEY_SUFFIX; Set<Map<String, Object>> canaryConfigSummarySet = new HashSet<>(); try (Jedis jedis = jedisPool.getResource()) { if (jedis.exists(mapByApplicationKey)) { if (applications != null && applications.size() > 0) { // If any applications were specified, populate the response with all of the canary configs scoped to those applications. for (String application : applications) { String appScopedCanaryConfigListJson = jedis.hget(mapByApplicationKey, application); populateCanaryConfigSummarySet(mapByApplicationKey, canaryConfigSummarySet, appScopedCanaryConfigListJson); } } else { // No applications were specified so populate the response with all persisted canary configs. List<String> allAppScopedCanaryConfigListJson = jedis.hvals(mapByApplicationKey); for (String appScopedCanaryConfigListJson : allAppScopedCanaryConfigListJson) { populateCanaryConfigSummarySet(mapByApplicationKey, canaryConfigSummarySet, appScopedCanaryConfigListJson); } } } else { throw new IllegalArgumentException("Canary config index not ready."); } populateWithPendingUpdates(credentials, accountName, jedis, canaryConfigSummarySet, applications); } return canaryConfigSummarySet; }
String accountName = credentials.getName(); String mapByApplicationKey = "kayenta:" + credentials.getType() + ":" + accountName + MAP_BY_APPLICATION_KEY_SUFFIX;
@Override public AccountCredentials save(String name, AccountCredentials credentials) { return accountNameToCredentialsMap.put(credentials.getName(), credentials); } }
public static String resolveAccountByNameOrType(String accountName, AccountCredentials.Type accountType, AccountCredentialsRepository accountCredentialsRepository) { AccountCredentials credentials; if (StringUtils.hasLength(accountName)) { credentials = accountCredentialsRepository .getOne(accountName) .orElseThrow(() -> new IllegalArgumentException("Unable to resolve account " + accountName + ".")); } else { credentials = accountCredentialsRepository .getOne(accountType) .orElseThrow(() -> new IllegalArgumentException("Unable to resolve account of type " + accountType + ".")); } return credentials.getName(); }
public void startPendingUpdate(AccountCredentials credentials, String updatedTimestamp, CanaryConfigIndexAction action, String correlationId, String canaryConfigSummaryJson) { String accountName = credentials.getName(); String mapPendingUpdatesByApplicationKey = buildMapPendingUpdatesByApplicationKey(credentials, accountName); try (Jedis jedis = jedisPool.getResource()) { jedis.rpush(mapPendingUpdatesByApplicationKey, updatedTimestamp + ":" + action + ":start:" + correlationId + ":" + canaryConfigSummaryJson); } }
public void removeFailedPendingUpdate(AccountCredentials credentials, String updatedTimestamp, CanaryConfigIndexAction action, String correlationId, String canaryConfigSummaryJson) { String accountName = credentials.getName(); String mapPendingUpdatesByApplicationKey = buildMapPendingUpdatesByApplicationKey(credentials, accountName); try (Jedis jedis = jedisPool.getResource()) { jedis.lrem(mapPendingUpdatesByApplicationKey, 1, updatedTimestamp + ":" + action + ":start:" + correlationId + ":" + canaryConfigSummaryJson); } }
public void finishPendingUpdate(AccountCredentials credentials, CanaryConfigIndexAction action, String correlationId) { String accountName = credentials.getName(); String mapPendingUpdatesByApplicationKey = buildMapPendingUpdatesByApplicationKey(credentials, accountName); try (Jedis jedis = jedisPool.getResource()) { jedis.rpush(mapPendingUpdatesByApplicationKey, getRedisTime() + ":" + action + ":finish:" + correlationId); } }
@Bean @DependsOn({"registerGoogleCredentials"}) MetricsService stackdriverMetricsService(AccountCredentialsRepository accountCredentialsRepository) { StackdriverMetricsService.StackdriverMetricsServiceBuilder stackdriverMetricsServiceBuilder = StackdriverMetricsService.builder(); accountCredentialsRepository .getAll() .stream() .filter(c -> c instanceof GoogleNamedAccountCredentials) .filter(c -> c.getSupportedTypes().contains(AccountCredentials.Type.METRICS_STORE)) .map(c -> c.getName()) .forEach(stackdriverMetricsServiceBuilder::accountName); StackdriverMetricsService stackdriverMetricsService = stackdriverMetricsServiceBuilder.build(); log.info("Populated StackdriverMetricsService with {} Google accounts.", stackdriverMetricsService.getAccountNames().size()); return stackdriverMetricsService; } }
@Bean @DependsOn({"registerAwsCredentials"}) public S3StorageService s3StorageService(AccountCredentialsRepository accountCredentialsRepository) { AmazonObjectMapperConfigurer.configure(kayentaObjectMapper); kayentaObjectMapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, true); S3StorageService.S3StorageServiceBuilder s3StorageServiceBuilder = S3StorageService.builder(); accountCredentialsRepository .getAll() .stream() .filter(c -> c instanceof AwsNamedAccountCredentials) .filter(c -> c.getSupportedTypes().contains(AccountCredentials.Type.OBJECT_STORE)) .map(c -> c.getName()) .forEach(s3StorageServiceBuilder::accountName); S3StorageService s3StorageService = s3StorageServiceBuilder.objectMapper(kayentaObjectMapper).build(); log.info("Populated S3StorageService with {} AWS accounts.", s3StorageService.getAccountNames().size()); return s3StorageService; } }