Search in sources :

Example 1 with DescribeRulesResponse

use of software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesResponse in project aws-cloudwatch-exporter by asserts.

the class TargetGroupLBMapProvider method mapListener.

@VisibleForTesting
void mapListener(ElasticLoadBalancingV2Client lbClient, SortedMap<String, String> labels, Resource lbResource, Listener listener) {
    SortedMap<String, String> telemetryLabels = new TreeMap<>(labels);
    telemetryLabels.put(SCRAPE_OPERATION_LABEL, "ElasticLoadBalancingClientV2/describeRules");
    DescribeRulesResponse dLR = rateLimiter.doWithRateLimit("ElasticLoadBalancingClientV2/describeRules", telemetryLabels, () -> lbClient.describeRules(DescribeRulesRequest.builder().listenerArn(listener.listenerArn()).build()));
    if (dLR.hasRules()) {
        dLR.rules().stream().filter(rule -> !isEmpty(rule.actions())).flatMap(rule -> rule.actions().stream()).filter(action -> action.targetGroupArn() != null).map(action -> resourceMapper.map(action.targetGroupArn())).filter(Optional::isPresent).map(Optional::get).forEach(tg -> tgToLB.put(tg, lbResource));
    }
}
Also used : CollectionUtils.isEmpty(org.springframework.util.CollectionUtils.isEmpty) DescribeRulesRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesRequest) Getter(lombok.Getter) AWSClientProvider(ai.asserts.aws.AWSClientProvider) ScrapeConfigProvider(ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider) DescribeRulesResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesResponse) DescribeListenersResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersResponse) ResourceMapper(ai.asserts.aws.resource.ResourceMapper) SCRAPE_REGION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL) ScrapeConfig(ai.asserts.aws.cloudwatch.config.ScrapeConfig) LoadBalancer(software.amazon.awssdk.services.elasticloadbalancingv2.model.LoadBalancer) RateLimiter(ai.asserts.aws.RateLimiter) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) DescribeLoadBalancersResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeLoadBalancersResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Resource(ai.asserts.aws.resource.Resource) ElasticLoadBalancingV2Client(software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) TreeMap(java.util.TreeMap) Listener(software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener) SCRAPE_OPERATION_LABEL(ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AllArgsConstructor(lombok.AllArgsConstructor) DescribeListenersRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest) SortedMap(java.util.SortedMap) Optional(java.util.Optional) DescribeRulesResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesResponse) TreeMap(java.util.TreeMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with DescribeRulesResponse

use of software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesResponse in project aws-cloudwatch-exporter by asserts.

the class TargetGroupLBMapProviderTest method mapListener.

@Test
public void mapListener() {
    Resource lbResource = Resource.builder().arn("lb-arn").build();
    Resource tgResource = Resource.builder().arn("tg-arn").build();
    Listener listener = Listener.builder().listenerArn("listener-arn").build();
    DescribeRulesRequest request = DescribeRulesRequest.builder().listenerArn("listener-arn").build();
    DescribeRulesResponse response = DescribeRulesResponse.builder().rules(Rule.builder().actions(Action.builder().targetGroupArn("tg-arn").build()).build()).build();
    expect(lbClient.describeRules(request)).andReturn(response);
    metricCollector.recordLatency(eq(SCRAPE_LATENCY_METRIC), anyObject(SortedMap.class), anyLong());
    expect(resourceMapper.map("tg-arn")).andReturn(Optional.of(tgResource));
    TargetGroupLBMapProvider testClass = new TargetGroupLBMapProvider(scrapeConfigProvider, awsClientProvider, resourceMapper, new RateLimiter(metricCollector));
    replayAll();
    assertTrue(testClass.getTgToLB().isEmpty());
    testClass.mapListener(lbClient, new TreeMap<>(), lbResource, listener);
    assertEquals(ImmutableMap.of(tgResource, lbResource), testClass.getTgToLB());
    verifyAll();
}
Also used : DescribeRulesRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesRequest) Listener(software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap) Resource(ai.asserts.aws.resource.Resource) DescribeRulesResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesResponse) RateLimiter(ai.asserts.aws.RateLimiter) Test(org.junit.jupiter.api.Test)

Aggregations

RateLimiter (ai.asserts.aws.RateLimiter)2 Resource (ai.asserts.aws.resource.Resource)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)2 SortedMap (java.util.SortedMap)2 DescribeRulesRequest (software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesRequest)2 DescribeRulesResponse (software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeRulesResponse)2 Listener (software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener)2 AWSClientProvider (ai.asserts.aws.AWSClientProvider)1 SCRAPE_OPERATION_LABEL (ai.asserts.aws.MetricNameUtil.SCRAPE_OPERATION_LABEL)1 SCRAPE_REGION_LABEL (ai.asserts.aws.MetricNameUtil.SCRAPE_REGION_LABEL)1 ScrapeConfig (ai.asserts.aws.cloudwatch.config.ScrapeConfig)1 ScrapeConfigProvider (ai.asserts.aws.cloudwatch.config.ScrapeConfigProvider)1 ResourceMapper (ai.asserts.aws.resource.ResourceMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Map (java.util.Map)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Getter (lombok.Getter)1