Search in sources :

Example 1 with RateLimiter

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

the class LambdaCapacityExporterTest method setup.

@BeforeEach
public void setup() {
    ScrapeConfigProvider scrapeConfigProvider = mock(ScrapeConfigProvider.class);
    ScrapeConfig scrapeConfig = mock(ScrapeConfig.class);
    namespaceConfig = mock(NamespaceConfig.class);
    awsClientProvider = mock(AWSClientProvider.class);
    lambdaClient = mock(LambdaClient.class);
    metricNameUtil = mock(MetricNameUtil.class);
    metricCollector = mock(BasicMetricCollector.class);
    functionScraper = mock(LambdaFunctionScraper.class);
    resourceTagHelper = mock(ResourceTagHelper.class);
    resource = mock(Resource.class);
    sampleBuilder = mock(MetricSampleBuilder.class);
    sample = mock(Sample.class);
    familySamples = mock(Collector.MetricFamilySamples.class);
    resetAll();
    testClass = new LambdaCapacityExporter(scrapeConfigProvider, awsClientProvider, metricNameUtil, sampleBuilder, functionScraper, resourceTagHelper, new RateLimiter(metricCollector));
    expect(scrapeConfigProvider.getScrapeConfig()).andReturn(scrapeConfig);
    expect(scrapeConfig.getLambdaConfig()).andReturn(Optional.of(namespaceConfig));
    expect(metricNameUtil.getLambdaMetric("available_concurrency")).andReturn("available");
    expect(metricNameUtil.getLambdaMetric("requested_concurrency")).andReturn("requested");
    expect(metricNameUtil.getLambdaMetric("allocated_concurrency")).andReturn("allocated");
    expect(metricNameUtil.getLambdaMetric("timeout_seconds")).andReturn("timeout");
    expect(metricNameUtil.getLambdaMetric("memory_limit_mb")).andReturn("memory_limit");
    expect(metricNameUtil.getLambdaMetric("account_limit")).andReturn("limit");
    expect(metricNameUtil.getLambdaMetric("reserved_concurrency")).andReturn("reserved");
    fn1 = LambdaFunction.builder().account("account1").region("region1").arn("arn1").name("fn1").memoryMB(128).timeoutSeconds(120).build();
    fn1Labels = ImmutableMap.of("region", "region1", "d_function_name", "fn1", "job", "fn1", "cw_namespace", "AWS/Lambda", SCRAPE_ACCOUNT_ID_LABEL, "account1");
    fn1VersionLabels = new HashMap<>(ImmutableMap.of("region", "region1", "d_function_name", "fn1", "d_executed_version", "1", "job", "fn1", "cw_namespace", "AWS/Lambda"));
    fn1VersionLabels.put(SCRAPE_ACCOUNT_ID_LABEL, "account1");
    fn2 = LambdaFunction.builder().account("account2").region("region2").arn("arn2").name("fn2").memoryMB(128).timeoutSeconds(60).build();
    fn2Labels = ImmutableMap.of("region", "region2", "d_function_name", "fn2", "job", "fn2", "cw_namespace", "AWS/Lambda", SCRAPE_ACCOUNT_ID_LABEL, "account2");
    fn2ResourceLabels = new HashMap<>(ImmutableMap.of("region", "region2", "d_function_name", "fn2", "d_resource", "green", "job", "fn2", "cw_namespace", "AWS/Lambda"));
    fn2ResourceLabels.put(SCRAPE_ACCOUNT_ID_LABEL, "account2");
}
Also used : NamespaceConfig(ai.asserts.aws.cloudwatch.config.NamespaceConfig) Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) Resource(ai.asserts.aws.resource.Resource) AWSClientProvider(ai.asserts.aws.AWSClientProvider) LambdaFunctionScraper(ai.asserts.aws.lambda.LambdaFunctionScraper) RateLimiter(ai.asserts.aws.RateLimiter) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) MetricNameUtil(ai.asserts.aws.MetricNameUtil) ResourceTagHelper(ai.asserts.aws.resource.ResourceTagHelper) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with RateLimiter

use of ai.asserts.aws.RateLimiter 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");
}
Also used : NamespaceConfig(ai.asserts.aws.cloudwatch.config.NamespaceConfig) Resource(ai.asserts.aws.resource.Resource) AWSClientProvider(ai.asserts.aws.AWSClientProvider) LambdaFunctionScraper(ai.asserts.aws.lambda.LambdaFunctionScraper) RateLimiter(ai.asserts.aws.RateLimiter) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) ResourceMapper(ai.asserts.aws.resource.ResourceMapper) Collector(io.prometheus.client.Collector) MetricNameUtil(ai.asserts.aws.MetricNameUtil) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with RateLimiter

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

the class EC2ToEBSVolumeExporterTest method setup.

@BeforeEach
public void setup() {
    AccountIDProvider accountIDProvider = mock(AccountIDProvider.class);
    AWSClientProvider awsClientProvider = mock(AWSClientProvider.class);
    ec2Client = mock(Ec2Client.class);
    ScrapeConfigProvider scrapeConfigProvider = mock(ScrapeConfigProvider.class);
    ScrapeConfig scrapeConfig = mock(ScrapeConfig.class);
    metricCollector = mock(BasicMetricCollector.class);
    testClass = new EC2ToEBSVolumeExporter(accountIDProvider, scrapeConfigProvider, awsClientProvider, new RateLimiter(metricCollector));
    expect(scrapeConfigProvider.getScrapeConfig()).andReturn(scrapeConfig);
    expect(scrapeConfig.getRegions()).andReturn(ImmutableSet.of("region"));
    expect(awsClientProvider.getEc2Client("region")).andReturn(ec2Client);
    expect(accountIDProvider.getAccountId()).andReturn("account").anyTimes();
}
Also used : AWSClientProvider(ai.asserts.aws.AWSClientProvider) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client) RateLimiter(ai.asserts.aws.RateLimiter) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with RateLimiter

use of ai.asserts.aws.RateLimiter 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));
}
Also used : ResourceMapper(ai.asserts.aws.resource.ResourceMapper) Resource(ai.asserts.aws.resource.Resource) AWSClientProvider(ai.asserts.aws.AWSClientProvider) ElasticLoadBalancingV2Client(software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client) RateLimiter(ai.asserts.aws.RateLimiter) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with RateLimiter

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

the class ScrapeConfigProviderTest method loadConfigFromS3.

@Test
void loadConfigFromS3() throws IOException {
    FileInputStream fis = new FileInputStream("src/test/resources/cloudwatch_scrape_config.yml");
    ScrapeConfig scrapeConfig = new ObjectMapperFactory().getObjectMapper().readValue(fis, new TypeReference<ScrapeConfig>() {
    });
    scrapeConfig.validateConfig();
    fis = new FileInputStream("src/test/resources/cloudwatch_scrape_config.yml");
    expect(s3Client.getObjectAsBytes(GetObjectRequest.builder().bucket("bucket").key("key").build())).andReturn(ResponseBytes.fromInputStream(GetObjectResponse.builder().build(), fis));
    metricCollector.recordLatency(anyString(), anyObject(), anyLong());
    s3Client.close();
    replayAll();
    ScrapeConfigProvider testClass = new ScrapeConfigProvider(new ObjectMapperFactory(), metricCollector, new RateLimiter(metricCollector), "src/test/resources/cloudwatch_scrape_config.yml", restTemplate) {

        @Override
        Map<String, String> getGetenv() {
            return ImmutableMap.of("CONFIG_S3_BUCKET", "bucket", "CONFIG_S3_KEY", "key");
        }

        @Override
        S3Client getS3Client() {
            return s3Client;
        }
    };
    assertEquals(scrapeConfig.toString(), testClass.getScrapeConfig().toString());
    verifyAll();
}
Also used : ObjectMapperFactory(ai.asserts.aws.ObjectMapperFactory) EasyMock.anyString(org.easymock.EasyMock.anyString) FileInputStream(java.io.FileInputStream) RateLimiter(ai.asserts.aws.RateLimiter) Test(org.junit.jupiter.api.Test)

Aggregations

RateLimiter (ai.asserts.aws.RateLimiter)21 AWSClientProvider (ai.asserts.aws.AWSClientProvider)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 ScrapeConfigProvider (ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider)11 Resource (ai.asserts.aws.resource.Resource)9 Test (org.junit.jupiter.api.Test)9 ScrapeConfig (ai.asserts.aws.cloudwatch.config.ScrapeConfig)8 ObjectMapperFactory (ai.asserts.aws.ObjectMapperFactory)6 ResourceMapper (ai.asserts.aws.resource.ResourceMapper)6 NamespaceConfig (ai.asserts.aws.cloudwatch.config.NamespaceConfig)5 MetricNameUtil (ai.asserts.aws.MetricNameUtil)4 SortedMap (java.util.SortedMap)4 ResourceTagHelper (ai.asserts.aws.resource.ResourceTagHelper)3 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 Sample (io.prometheus.client.Collector.MetricFamilySamples.Sample)3 EasyMock.anyString (org.easymock.EasyMock.anyString)3 ElasticLoadBalancingV2Client (software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client)3 LambdaClient (software.amazon.awssdk.services.lambda.LambdaClient)3 BasicMetricCollector (ai.asserts.aws.exporter.BasicMetricCollector)2 LambdaFunctionScraper (ai.asserts.aws.lambda.LambdaFunctionScraper)2