use of ai.asserts.aws.resource.ResourceMapper in project aws-cloudwatch-exporter by asserts.
the class LBToASGRelationBuilder method updateRouting.
public void updateRouting() {
log.info("Updating LB to ASG Routing relations");
Set<ResourceRelation> newConfigs = new HashSet<>();
scrapeConfigProvider.getScrapeConfig().getRegions().forEach(region -> {
String api = "AutoScalingClient/describeAutoScalingGroups";
try (AutoScalingClient autoScalingClient = rateLimiter.doWithRateLimit(api, ImmutableSortedMap.of(SCRAPE_REGION_LABEL, region, SCRAPE_OPERATION_LABEL, api), () -> awsClientProvider.getAutoScalingClient(region))) {
DescribeAutoScalingGroupsResponse resp = autoScalingClient.describeAutoScalingGroups();
List<AutoScalingGroup> groups = resp.autoScalingGroups();
if (!isEmpty(groups)) {
groups.forEach(asg -> resourceMapper.map(asg.autoScalingGroupARN()).ifPresent(asgRes -> {
if (!isEmpty(asg.targetGroupARNs())) {
asg.targetGroupARNs().stream().map(resourceMapper::map).filter(Optional::isPresent).map(Optional::get).filter(tg -> targetGroupLBMapProvider.getTgToLB().containsKey(tg)).map(tg -> targetGroupLBMapProvider.getTgToLB().get(tg)).forEach(lb -> newConfigs.add(ResourceRelation.builder().from(lb).to(asgRes).name("ROUTES_TO").build()));
}
}));
}
} catch (Exception e) {
log.error("Failed to build LB to ASG relationship", e);
}
});
routingConfigs = newConfigs;
}
use of ai.asserts.aws.resource.ResourceMapper in project aws-cloudwatch-exporter by asserts.
the class LambdaInvokeConfigExporterTest method setup.
@BeforeEach
public void setup() {
fnScraper = mock(LambdaFunctionScraper.class);
awsClientProvider = mock(AWSClientProvider.class);
lambdaClient = mock(LambdaClient.class);
metricNameUtil = mock(MetricNameUtil.class);
ScrapeConfigProvider scrapeConfigProvider = mock(ScrapeConfigProvider.class);
ScrapeConfig scrapeConfig = mock(ScrapeConfig.class);
NamespaceConfig namespaceConfig = mock(NamespaceConfig.class);
resourceMapper = mock(ResourceMapper.class);
resource = mock(Resource.class);
metricSampleBuilder = mock(MetricSampleBuilder.class);
sample = mock(Collector.MetricFamilySamples.Sample.class);
metricCollector = mock(BasicMetricCollector.class);
testClass = new LambdaInvokeConfigExporter(fnScraper, awsClientProvider, metricNameUtil, scrapeConfigProvider, resourceMapper, metricSampleBuilder, new RateLimiter(metricCollector));
expect(scrapeConfig.getLambdaConfig()).andReturn(Optional.of(namespaceConfig));
expect(scrapeConfigProvider.getScrapeConfig()).andReturn(scrapeConfig);
expect(metricNameUtil.getMetricPrefix(CWNamespace.lambda.getNamespace())).andReturn("prefix");
}
use of ai.asserts.aws.resource.ResourceMapper in project aws-cloudwatch-exporter by asserts.
the class LBToLambdaRoutingBuilderTest method setup.
@BeforeEach
public void setup() {
AccountIDProvider accountIDProvider = mock(AccountIDProvider.class);
ScrapeConfigProvider scrapeConfigProvider = mock(ScrapeConfigProvider.class);
ScrapeConfig scrapeConfig = mock(ScrapeConfig.class);
AWSClientProvider awsClientProvider = mock(AWSClientProvider.class);
TargetGroupLBMapProvider targetGroupLBMapProvider = mock(TargetGroupLBMapProvider.class);
metricCollector = mock(BasicMetricCollector.class);
elbV2Client = mock(ElasticLoadBalancingV2Client.class);
resourceMapper = mock(ResourceMapper.class);
targetResource = mock(Resource.class);
lbRsource = mock(Resource.class);
lambdaResource = mock(Resource.class);
testClass = new LBToLambdaRoutingBuilder(accountIDProvider, scrapeConfigProvider, awsClientProvider, new RateLimiter(metricCollector), resourceMapper, targetGroupLBMapProvider);
expect(accountIDProvider.getAccountId()).andReturn("account").anyTimes();
expect(scrapeConfigProvider.getScrapeConfig()).andReturn(scrapeConfig).anyTimes();
expect(scrapeConfig.getRegions()).andReturn(ImmutableSet.of("region")).anyTimes();
expect(awsClientProvider.getELBV2Client("region")).andReturn(elbV2Client).anyTimes();
expect(targetGroupLBMapProvider.getTgToLB()).andReturn(ImmutableMap.of(targetResource, lbRsource));
}
use of ai.asserts.aws.resource.ResourceMapper in project aws-cloudwatch-exporter by asserts.
the class LambdaEventSourceExporterTest method setup.
@BeforeEach
public void setup() {
metricNameUtil = mock(MetricNameUtil.class);
lambdaClient = mock(LambdaClient.class);
resourceMapper = mock(ResourceMapper.class);
fnResource = mock(Resource.class);
sourceResource = mock(Resource.class);
resourceTagHelper = mock(ResourceTagHelper.class);
sampleBuilder = mock(MetricSampleBuilder.class);
sample = mock(Sample.class);
familySamples = mock(Collector.MetricFamilySamples.class);
metricCollector = mock(BasicMetricCollector.class);
namespaceConfig = mock(NamespaceConfig.class);
ScrapeConfigProvider scrapeConfigProvider = mock(ScrapeConfigProvider.class);
expect(namespaceConfig.getName()).andReturn("AWS/Lambda").anyTimes();
expect(scrapeConfigProvider.getScrapeConfig()).andReturn(ScrapeConfig.builder().regions(ImmutableSet.of("region1")).namespaces(ImmutableList.of(namespaceConfig)).build()).anyTimes();
AWSClientProvider awsClientProvider = mock(AWSClientProvider.class);
expect(awsClientProvider.getLambdaClient("region1")).andReturn(lambdaClient).anyTimes();
testClass = new LambdaEventSourceExporter(scrapeConfigProvider, awsClientProvider, metricNameUtil, resourceMapper, resourceTagHelper, sampleBuilder, new RateLimiter(metricCollector));
}
use of ai.asserts.aws.resource.ResourceMapper in project aws-cloudwatch-exporter by asserts.
the class ECSServiceDiscoveryExporterTest method setup.
@BeforeEach
public void setup() {
scrapeConfigProvider = mock(ScrapeConfigProvider.class);
scrapeConfig = mock(ScrapeConfig.class);
awsClientProvider = mock(AWSClientProvider.class);
ecsClient = mock(EcsClient.class);
resourceMapper = mock(ResourceMapper.class);
resource = mock(Resource.class);
ecsTaskUtil = mock(ECSTaskUtil.class);
metricCollector = mock(BasicMetricCollector.class);
objectMapperFactory = mock(ObjectMapperFactory.class);
objectMapper = mock(ObjectMapper.class);
objectWriter = mock(ObjectWriter.class);
mockStaticConfig = mock(StaticConfig.class);
lbToECSRoutingBuilder = mock(LBToECSRoutingBuilder.class);
mockRelation = mock(ResourceRelation.class);
rateLimiter = new RateLimiter(metricCollector);
resetAll();
}
Aggregations