Search in sources :

Example 1 with SCRAPE_REGION_LABEL

use of ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL in project aws-cloudwatch-exporter by asserts.

the class LBToECSRoutingBuilder method getRoutings.

public Set<ResourceRelation> getRoutings(EcsClient ecsClient, Resource cluster, List<Resource> services) {
    Set<ResourceRelation> routing = new HashSet<>();
    log.info("Updating Resource Relation for ECS Cluster {}", cluster);
    try {
        String api = "EcsClient/describeServices";
        DescribeServicesResponse response = rateLimiter.doWithRateLimit(api, ImmutableSortedMap.of(SCRAPE_REGION_LABEL, cluster.getRegion(), SCRAPE_ACCOUNT_ID_LABEL, cluster.getAccount(), SCRAPE_OPERATION_LABEL, api), () -> ecsClient.describeServices(DescribeServicesRequest.builder().cluster(cluster.getArn()).services(services.stream().map(Resource::getArn).collect(Collectors.toList())).build()));
        if (response.hasServices()) {
            response.services().stream().filter(service -> resourceMapper.map(service.serviceArn()).isPresent()).forEach(service -> {
                Optional<Resource> servResOpt = resourceMapper.map(service.serviceArn());
                servResOpt.ifPresent(servRes -> routing.addAll(service.loadBalancers().stream().map(loadBalancer -> resourceMapper.map(loadBalancer.targetGroupArn())).filter(Optional::isPresent).map(Optional::get).map(tg -> targetGroupLBMapProvider.getTgToLB().get(tg)).filter(Objects::nonNull).map(lb -> ResourceRelation.builder().from(lb).to(servRes).name("ROUTES_TO").build()).collect(Collectors.toSet())));
            });
        }
    } catch (Exception e) {
        log.error("Failed to build resource relations", e);
    }
    return routing;
}
Also used : ResourceRelation(ai.asserts.aws.resource.ResourceRelation) SCRAPE_ACCOUNT_ID_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_ACCOUNT_ID_LABEL) Set(java.util.Set) ResourceMapper(ai.asserts.aws.resource.ResourceMapper) Resource(ai.asserts.aws.resource.Resource) Collectors(java.util.stream.Collectors) SCRAPE_REGION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL) HashSet(java.util.HashSet) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) RateLimiter(ai.asserts.aws.RateLimiter) DescribeServicesRequest(software.amazon.awssdk.services.ecs.model.DescribeServicesRequest) SCRAPE_OPERATION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL) EcsClient(software.amazon.awssdk.services.ecs.EcsClient) Optional(java.util.Optional) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) DescribeServicesResponse(software.amazon.awssdk.services.ecs.model.DescribeServicesResponse) ResourceRelation(ai.asserts.aws.resource.ResourceRelation) Optional(java.util.Optional) Resource(ai.asserts.aws.resource.Resource) Objects(java.util.Objects) DescribeServicesResponse(software.amazon.awssdk.services.ecs.model.DescribeServicesResponse) HashSet(java.util.HashSet)

Example 2 with SCRAPE_REGION_LABEL

use of ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL in project aws-cloudwatch-exporter by asserts.

the class LBToLambdaRoutingBuilder method getRoutings.

public Set<ResourceRelation> getRoutings() {
    log.info("LB To Lambda routing relation builder about to build relations");
    Set<ResourceRelation> routing = new HashSet<>();
    scrapeConfigProvider.getScrapeConfig().getRegions().forEach(region -> {
        try (ElasticLoadBalancingV2Client elbV2Client = awsClientProvider.getELBV2Client(region)) {
            Map<Resource, Resource> tgToLB = targetGroupLBMapProvider.getTgToLB();
            tgToLB.keySet().forEach(tg -> {
                try {
                    String api = "ElasticLoadBalancingV2Client/describeTargetHealth";
                    DescribeTargetHealthResponse response = rateLimiter.doWithRateLimit(api, ImmutableSortedMap.of(SCRAPE_REGION_LABEL, region, SCRAPE_ACCOUNT_ID_LABEL, accountIDProvider.getAccountId(), SCRAPE_OPERATION_LABEL, api), () -> elbV2Client.describeTargetHealth(DescribeTargetHealthRequest.builder().targetGroupArn(tg.getArn()).build()));
                    if (!isEmpty(response.targetHealthDescriptions())) {
                        response.targetHealthDescriptions().stream().map(tH -> resourceMapper.map(tH.target().id())).filter(opt -> opt.isPresent() && opt.get().getType().equals(LambdaFunction)).map(Optional::get).forEach(lambda -> routing.add(ResourceRelation.builder().from(tgToLB.get(tg)).to(lambda).name("ROUTES_TO").build()));
                    }
                } catch (Exception e) {
                    log.error("Failed to build resource relations", e);
                }
            });
        }
    });
    return routing;
}
Also used : LambdaFunction(ai.asserts.aws.resource.ResourceType.LambdaFunction) CollectionUtils.isEmpty(org.springframework.util.CollectionUtils.isEmpty) DescribeTargetHealthResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeTargetHealthResponse) ResourceRelation(ai.asserts.aws.resource.ResourceRelation) SCRAPE_ACCOUNT_ID_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_ACCOUNT_ID_LABEL) AWSClientProvider(ai.asserts.aws.AWSClientProvider) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) Set(java.util.Set) ResourceMapper(ai.asserts.aws.resource.ResourceMapper) Resource(ai.asserts.aws.resource.Resource) ElasticLoadBalancingV2Client(software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client) SCRAPE_REGION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL) HashSet(java.util.HashSet) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) RateLimiter(ai.asserts.aws.RateLimiter) Map(java.util.Map) SCRAPE_OPERATION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL) Optional(java.util.Optional) DescribeTargetHealthRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) AllArgsConstructor(lombok.AllArgsConstructor) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ResourceRelation(ai.asserts.aws.resource.ResourceRelation) Resource(ai.asserts.aws.resource.Resource) ElasticLoadBalancingV2Client(software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client) DescribeTargetHealthResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeTargetHealthResponse) HashSet(java.util.HashSet)

Example 3 with SCRAPE_REGION_LABEL

use of ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL in project aws-cloudwatch-exporter by asserts.

the class LambdaCapacityExporter method getMetrics.

private List<MetricFamilySamples> getMetrics() {
    ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig();
    Optional<NamespaceConfig> optional = scrapeConfig.getLambdaConfig();
    String availableMetric = metricNameUtil.getLambdaMetric("available_concurrency");
    String requestedMetric = metricNameUtil.getLambdaMetric("requested_concurrency");
    String allocatedMetric = metricNameUtil.getLambdaMetric("allocated_concurrency");
    String reservedMetric = metricNameUtil.getLambdaMetric("reserved_concurrency");
    String timeoutMetric = metricNameUtil.getLambdaMetric("timeout_seconds");
    String memoryLimit = metricNameUtil.getLambdaMetric("memory_limit_mb");
    String accountLimitMetric = metricNameUtil.getLambdaMetric("account_limit");
    Map<String, List<MetricFamilySamples.Sample>> samples = new TreeMap<>();
    optional.ifPresent(lambdaConfig -> functionScraper.getFunctions().forEach((region, functions) -> {
        log.info(" - Getting Lambda account and provisioned concurrency for region {}", region);
        try (LambdaClient lambdaClient = awsClientProvider.getLambdaClient(region)) {
            GetAccountSettingsResponse accountSettings = rateLimiter.doWithRateLimit("LambdaClient/getAccountSettings", ImmutableSortedMap.of(SCRAPE_REGION_LABEL, region, SCRAPE_OPERATION_LABEL, "getAccountSettings", SCRAPE_NAMESPACE_LABEL, "AWS/Lambda"), lambdaClient::getAccountSettings);
            MetricFamilySamples.Sample sample = sampleBuilder.buildSingleSample(accountLimitMetric, ImmutableMap.of("region", region, "cw_namespace", lambda.getNormalizedNamespace(), "type", "concurrent_executions"), accountSettings.accountLimit().concurrentExecutions() * 1.0D);
            samples.computeIfAbsent(accountLimitMetric, k -> new ArrayList<>()).add(sample);
            sample = sampleBuilder.buildSingleSample(accountLimitMetric, ImmutableMap.of("region", region, "cw_namespace", lambda.getNormalizedNamespace(), "type", "unreserved_concurrent_executions"), accountSettings.accountLimit().unreservedConcurrentExecutions() * 1.0D);
            samples.computeIfAbsent(accountLimitMetric, k -> new ArrayList<>()).add(sample);
            Set<Resource> fnResources = resourceTagHelper.getFilteredResources(region, lambdaConfig);
            functions.forEach((functionArn, lambdaFunction) -> {
                GetFunctionConcurrencyResponse fCResponse = rateLimiter.doWithRateLimit("LambdaClient/getFunctionConcurrency", ImmutableSortedMap.of(SCRAPE_REGION_LABEL, region, SCRAPE_OPERATION_LABEL, "getFunctionConcurrency", SCRAPE_NAMESPACE_LABEL, "AWS/Lambda"), () -> lambdaClient.getFunctionConcurrency(GetFunctionConcurrencyRequest.builder().functionName(lambdaFunction.getArn()).build()));
                if (fCResponse.reservedConcurrentExecutions() != null) {
                    MetricFamilySamples.Sample reserved = sampleBuilder.buildSingleSample(reservedMetric, ImmutableMap.of("region", region, "cw_namespace", lambda.getNormalizedNamespace(), "d_function_name", lambdaFunction.getName(), "job", lambdaFunction.getName(), SCRAPE_ACCOUNT_ID_LABEL, lambdaFunction.getAccount()), fCResponse.reservedConcurrentExecutions().doubleValue());
                    samples.computeIfAbsent(reservedMetric, k -> new ArrayList<>()).add(reserved);
                }
                Optional<Resource> fnResourceOpt = fnResources.stream().filter(resource -> functionArn.equals(resource.getArn())).findFirst();
                Map<String, String> labels = new TreeMap<>();
                fnResourceOpt.ifPresent(fnResource -> fnResource.addEnvLabel(labels, metricNameUtil));
                labels.put("region", region);
                labels.put("cw_namespace", lambda.getNormalizedNamespace());
                labels.put("d_function_name", lambdaFunction.getName());
                labels.put("job", lambdaFunction.getName());
                labels.put(SCRAPE_ACCOUNT_ID_LABEL, lambdaFunction.getAccount());
                // Export timeout
                double timeout = lambdaFunction.getTimeoutSeconds() * 1.0D;
                samples.computeIfAbsent(timeoutMetric, k -> new ArrayList<>()).add(sampleBuilder.buildSingleSample(timeoutMetric, labels, timeout));
                samples.computeIfAbsent(memoryLimit, k -> new ArrayList<>()).add(sampleBuilder.buildSingleSample(memoryLimit, labels, lambdaFunction.getMemoryMB() * 1.0D));
                ListProvisionedConcurrencyConfigsRequest request = ListProvisionedConcurrencyConfigsRequest.builder().functionName(lambdaFunction.getName()).build();
                ListProvisionedConcurrencyConfigsResponse response = rateLimiter.doWithRateLimit("LambdaClient/listProvisionedConcurrencyConfigs", ImmutableSortedMap.of(SCRAPE_REGION_LABEL, region, SCRAPE_OPERATION_LABEL, "listProvisionedConcurrencyConfigs", SCRAPE_NAMESPACE_LABEL, "AWS/Lambda"), () -> lambdaClient.listProvisionedConcurrencyConfigs(request));
                if (response.hasProvisionedConcurrencyConfigs()) {
                    response.provisionedConcurrencyConfigs().forEach(config -> {
                        // Capacity is always provisioned at alias or version level
                        String[] parts = config.functionArn().split(":");
                        String level = Character.isDigit(parts[parts.length - 1].charAt(0)) ? "d_executed_version" : "d_resource";
                        labels.put(level, parts[parts.length - 1]);
                        Integer available = config.availableProvisionedConcurrentExecutions();
                        samples.computeIfAbsent(availableMetric, k -> new ArrayList<>()).add(sampleBuilder.buildSingleSample(availableMetric, labels, available.doubleValue()));
                        Integer requested = config.requestedProvisionedConcurrentExecutions();
                        samples.computeIfAbsent(requestedMetric, k -> new ArrayList<>()).add(sampleBuilder.buildSingleSample(requestedMetric, labels, requested.doubleValue()));
                        Integer allocated = config.allocatedProvisionedConcurrentExecutions();
                        samples.computeIfAbsent(allocatedMetric, k -> new ArrayList<>()).add(sampleBuilder.buildSingleSample(allocatedMetric, labels, allocated.doubleValue()));
                    });
                }
            });
        } catch (Exception e) {
            log.error("Failed to get lambda provisioned capacity for region " + region, e);
        }
    }));
    return samples.values().stream().map(sampleBuilder::buildFamily).collect(Collectors.toList());
}
Also used : NamespaceConfig(ai.asserts.aws.cloudwatch.config.NamespaceConfig) NamespaceConfig(ai.asserts.aws.cloudwatch.config.NamespaceConfig) AWSClientProvider(ai.asserts.aws.AWSClientProvider) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) ListProvisionedConcurrencyConfigsResponse(software.amazon.awssdk.services.lambda.model.ListProvisionedConcurrencyConfigsResponse) GetFunctionConcurrencyResponse(software.amazon.awssdk.services.lambda.model.GetFunctionConcurrencyResponse) ArrayList(java.util.ArrayList) SCRAPE_REGION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig) LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) RateLimiter(ai.asserts.aws.RateLimiter) Map(java.util.Map) CWNamespace.lambda(ai.asserts.aws.cloudwatch.model.CWNamespace.lambda) LambdaFunctionScraper(ai.asserts.aws.lambda.LambdaFunctionScraper) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SCRAPE_ACCOUNT_ID_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_ACCOUNT_ID_LABEL) SCRAPE_NAMESPACE_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_NAMESPACE_LABEL) ImmutableMap(com.google.common.collect.ImmutableMap) GetAccountSettingsResponse(software.amazon.awssdk.services.lambda.model.GetAccountSettingsResponse) GetFunctionConcurrencyRequest(software.amazon.awssdk.services.lambda.model.GetFunctionConcurrencyRequest) Set(java.util.Set) ResourceTagHelper(ai.asserts.aws.resource.ResourceTagHelper) Resource(ai.asserts.aws.resource.Resource) Collectors(java.util.stream.Collectors) MetricNameUtil(ai.asserts.aws.MetricNameUtil) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) Collector(io.prometheus.client.Collector) TreeMap(java.util.TreeMap) SCRAPE_OPERATION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL) Optional(java.util.Optional) ListProvisionedConcurrencyConfigsRequest(software.amazon.awssdk.services.lambda.model.ListProvisionedConcurrencyConfigsRequest) Set(java.util.Set) Optional(java.util.Optional) TreeMap(java.util.TreeMap) ListProvisionedConcurrencyConfigsResponse(software.amazon.awssdk.services.lambda.model.ListProvisionedConcurrencyConfigsResponse) ListProvisionedConcurrencyConfigsRequest(software.amazon.awssdk.services.lambda.model.ListProvisionedConcurrencyConfigsRequest) GetFunctionConcurrencyResponse(software.amazon.awssdk.services.lambda.model.GetFunctionConcurrencyResponse) GetAccountSettingsResponse(software.amazon.awssdk.services.lambda.model.GetAccountSettingsResponse) LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) TreeMap(java.util.TreeMap) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig)

Example 4 with SCRAPE_REGION_LABEL

use of ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL in project aws-cloudwatch-exporter by asserts.

the class LambdaEventSourceExporter method getMappings.

private List<MetricFamilySamples> getMappings() {
    Map<String, List<Sample>> samples = new TreeMap<>();
    Map<String, List<EventSourceMappingConfiguration>> byRegion = new TreeMap<>();
    ScrapeConfig scrapeConfig = scrapeConfigProvider.getScrapeConfig();
    scrapeConfig.getLambdaConfig().ifPresent(namespaceConfig -> scrapeConfig.getRegions().forEach(region -> {
        try (LambdaClient client = awsClientProvider.getLambdaClient(region)) {
            // Get all event source mappings
            log.info("Discovering Lambda event source mappings for region={}", region);
            String nextToken = null;
            do {
                ListEventSourceMappingsRequest req = ListEventSourceMappingsRequest.builder().marker(nextToken).build();
                ListEventSourceMappingsResponse response = rateLimiter.doWithRateLimit("LambdaClient/listEventSourceMappings", ImmutableSortedMap.of(SCRAPE_REGION_LABEL, region, SCRAPE_OPERATION_LABEL, "listEventSourceMappings", SCRAPE_NAMESPACE_LABEL, "AWS/Lambda"), () -> client.listEventSourceMappings(req));
                if (response.hasEventSourceMappings()) {
                    byRegion.computeIfAbsent(region, k -> new ArrayList<>()).addAll(response.eventSourceMappings().stream().filter(mapping -> resourceMapper.map(mapping.functionArn()).isPresent()).collect(Collectors.toList()));
                }
                nextToken = response.nextMarker();
            } while (StringUtils.hasText(nextToken));
            Set<Resource> fnResources = resourceTagHelper.getFilteredResources(region, namespaceConfig);
            byRegion.computeIfAbsent(region, k -> new ArrayList<>()).forEach(mappingConfiguration -> {
                Optional<Resource> fnResource = Optional.ofNullable(fnResources.stream().filter(r -> r.getArn().equals(mappingConfiguration.functionArn())).findFirst().orElse(resourceMapper.map(mappingConfiguration.functionArn()).orElse(null)));
                Optional<Resource> eventResourceOpt = resourceMapper.map(mappingConfiguration.eventSourceArn());
                eventResourceOpt.ifPresent(eventResource -> fnResource.ifPresent(fn -> buildSample(region, fn, eventResource, samples)));
            });
        } catch (Exception e) {
            log.info("Failed to discover event source mappings", e);
        }
    }));
    return samples.values().stream().map(sampleBuilder::buildFamily).collect(Collectors.toList());
}
Also used : AWSClientProvider(ai.asserts.aws.AWSClientProvider) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) ListEventSourceMappingsResponse(software.amazon.awssdk.services.lambda.model.ListEventSourceMappingsResponse) ResourceMapper(ai.asserts.aws.resource.ResourceMapper) Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) ArrayList(java.util.ArrayList) SCRAPE_REGION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig) LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) RateLimiter(ai.asserts.aws.RateLimiter) Map(java.util.Map) CWNamespace.lambda(ai.asserts.aws.cloudwatch.model.CWNamespace.lambda) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SCRAPE_ACCOUNT_ID_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_ACCOUNT_ID_LABEL) SCRAPE_NAMESPACE_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_NAMESPACE_LABEL) Set(java.util.Set) EventSourceMappingConfiguration(software.amazon.awssdk.services.lambda.model.EventSourceMappingConfiguration) ResourceTagHelper(ai.asserts.aws.resource.ResourceTagHelper) Resource(ai.asserts.aws.resource.Resource) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) MetricNameUtil(ai.asserts.aws.MetricNameUtil) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) Collector(io.prometheus.client.Collector) TreeMap(java.util.TreeMap) SCRAPE_OPERATION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL) Optional(java.util.Optional) ListEventSourceMappingsRequest(software.amazon.awssdk.services.lambda.model.ListEventSourceMappingsRequest) StringUtils(org.springframework.util.StringUtils) Set(java.util.Set) Optional(java.util.Optional) TreeMap(java.util.TreeMap) ListEventSourceMappingsResponse(software.amazon.awssdk.services.lambda.model.ListEventSourceMappingsResponse) ListEventSourceMappingsRequest(software.amazon.awssdk.services.lambda.model.ListEventSourceMappingsRequest) LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) ArrayList(java.util.ArrayList) List(java.util.List) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig)

Example 5 with SCRAPE_REGION_LABEL

use of ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL in project aws-cloudwatch-exporter by asserts.

the class EC2ToEBSVolumeExporter method update.

public void update() {
    Set<ResourceRelation> newAttachedVolumes = new HashSet<>();
    try {
        scrapeConfigProvider.getScrapeConfig().getRegions().forEach(region -> {
            Ec2Client ec2Client = awsClientProvider.getEc2Client(region);
            SortedMap<String, String> telemetryLabels = new TreeMap<>();
            String api = "Ec2Client/describeVolumes";
            telemetryLabels.put(SCRAPE_OPERATION_LABEL, api);
            telemetryLabels.put(SCRAPE_REGION_LABEL, region);
            String accountId = accountIDProvider.getAccountId();
            telemetryLabels.put(SCRAPE_ACCOUNT_ID_LABEL, accountId);
            AtomicReference<String> nextToken = new AtomicReference<>();
            do {
                DescribeVolumesResponse resp = rateLimiter.doWithRateLimit(api, telemetryLabels, () -> ec2Client.describeVolumes(DescribeVolumesRequest.builder().nextToken(nextToken.get()).build()));
                if (!CollectionUtils.isEmpty(resp.volumes())) {
                    newAttachedVolumes.addAll(resp.volumes().stream().flatMap(volume -> volume.attachments().stream()).map(volumeAttachment -> ResourceRelation.builder().from(Resource.builder().account(accountId).region(region).type(EBSVolume).name(volumeAttachment.volumeId()).build()).to(Resource.builder().account(accountId).region(region).type(EC2Instance).name(volumeAttachment.instanceId()).build()).name("ATTACHED_TO").build()).collect(Collectors.toSet()));
                }
                nextToken.set(resp.nextToken());
            } while (nextToken.get() != null);
        });
    } catch (Exception e) {
        log.error("Failed to fetch ec2 ebs volumes relation", e);
    }
    attachedVolumes = newAttachedVolumes;
}
Also used : ResourceRelation(ai.asserts.aws.resource.ResourceRelation) Getter(lombok.Getter) SCRAPE_ACCOUNT_ID_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_ACCOUNT_ID_LABEL) AWSClientProvider(ai.asserts.aws.AWSClientProvider) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) EC2Instance(ai.asserts.aws.resource.ResourceType.EC2Instance) Set(java.util.Set) Resource(ai.asserts.aws.resource.Resource) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) SCRAPE_REGION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL) HashSet(java.util.HashSet) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) TreeMap(java.util.TreeMap) RateLimiter(ai.asserts.aws.RateLimiter) CollectionUtils(org.springframework.util.CollectionUtils) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client) DescribeVolumesRequest(software.amazon.awssdk.services.ec2.model.DescribeVolumesRequest) SCRAPE_OPERATION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL) EBSVolume(ai.asserts.aws.resource.ResourceType.EBSVolume) DescribeVolumesResponse(software.amazon.awssdk.services.ec2.model.DescribeVolumesResponse) SortedMap(java.util.SortedMap) ResourceRelation(ai.asserts.aws.resource.ResourceRelation) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client) AtomicReference(java.util.concurrent.atomic.AtomicReference) DescribeVolumesResponse(software.amazon.awssdk.services.ec2.model.DescribeVolumesResponse) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Aggregations

SCRAPE_OPERATION_LABEL (ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL)12 SCRAPE_REGION_LABEL (ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL)12 RateLimiter (ai.asserts.aws.RateLimiter)12 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)11 Slf4j (lombok.extern.slf4j.Slf4j)11 Component (org.springframework.stereotype.Component)11 AWSClientProvider (ai.asserts.aws.AWSClientProvider)10 ScrapeConfigProvider (ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider)9 List (java.util.List)9 Map (java.util.Map)9 Optional (java.util.Optional)9 Set (java.util.Set)9 TreeMap (java.util.TreeMap)8 Resource (ai.asserts.aws.resource.Resource)7 ResourceMapper (ai.asserts.aws.resource.ResourceMapper)7 Collectors (java.util.stream.Collectors)7 SCRAPE_ACCOUNT_ID_LABEL (ai.asserts.aws.MetricNameUtil.SCRAPE_ACCOUNT_ID_LABEL)6 SCRAPE_NAMESPACE_LABEL (ai.asserts.aws.MetricNameUtil.SCRAPE_NAMESPACE_LABEL)6 ScrapeConfig (ai.asserts.aws.cloudwatch.config.ScrapeConfig)6 ArrayList (java.util.ArrayList)6