Search in sources :

Example 1 with DescribeListenersResponse

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

the class TargetGroupLBMapProvider method mapLB.

@VisibleForTesting
void mapLB(ElasticLoadBalancingV2Client lbClient, SortedMap<String, String> labels, LoadBalancer lb) {
    String lbArn = lb.loadBalancerArn();
    resourceMapper.map(lbArn).ifPresent(lbResource -> {
        String api = "ElasticLoadBalancingV2Client/describeListeners";
        SortedMap<String, String> telemetryLabels = new TreeMap<>(labels);
        telemetryLabels.put(SCRAPE_OPERATION_LABEL, api);
        rateLimiter.doWithRateLimit(api, telemetryLabels, () -> {
            DescribeListenersRequest listenersRequest = DescribeListenersRequest.builder().loadBalancerArn(lbArn).build();
            DescribeListenersResponse listenersResponse = lbClient.describeListeners(listenersRequest);
            if (!isEmpty(listenersResponse.listeners())) {
                listenersResponse.listeners().forEach(listener -> mapListener(lbClient, labels, lbResource, listener));
            }
            return null;
        });
    });
}
Also used : DescribeListenersRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest) DescribeListenersResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersResponse) TreeMap(java.util.TreeMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with DescribeListenersResponse

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

the class TargetGroupLBMapProviderTest method mapLB.

@Test
public void mapLB() {
    Resource lbResource = Resource.builder().arn("lb-arn").build();
    LoadBalancer loadBalancer = LoadBalancer.builder().loadBalancerArn("lb-arn").build();
    Listener listener = Listener.builder().listenerArn("listener-arn").build();
    DescribeListenersRequest request = DescribeListenersRequest.builder().loadBalancerArn("lb-arn").build();
    DescribeListenersResponse response = DescribeListenersResponse.builder().listeners(listener).build();
    expect(resourceMapper.map(loadBalancer.loadBalancerArn())).andReturn(Optional.of(lbResource));
    expect(lbClient.describeListeners(request)).andReturn(response);
    metricCollector.recordLatency(eq(SCRAPE_LATENCY_METRIC), anyObject(SortedMap.class), anyLong());
    AtomicInteger sideEffect = new AtomicInteger();
    TargetGroupLBMapProvider testClass = new TargetGroupLBMapProvider(scrapeConfigProvider, awsClientProvider, resourceMapper, new RateLimiter(metricCollector)) {

        @Override
        void mapListener(ElasticLoadBalancingV2Client theClient, SortedMap<String, String> labels, Resource theResource, Listener theListener) {
            assertEquals(lbClient, theClient);
            assertEquals(lbResource, theResource);
            assertEquals(listener, theListener);
            sideEffect.incrementAndGet();
        }
    };
    replayAll();
    testClass.mapLB(lbClient, labels, loadBalancer);
    assertEquals(1, sideEffect.get());
    verifyAll();
}
Also used : Listener(software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener) DescribeListenersRequest(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap) Resource(ai.asserts.aws.resource.Resource) DescribeListenersResponse(software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersResponse) LoadBalancer(software.amazon.awssdk.services.elasticloadbalancingv2.model.LoadBalancer) ElasticLoadBalancingV2Client(software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client) RateLimiter(ai.asserts.aws.RateLimiter) Test(org.junit.jupiter.api.Test)

Aggregations

DescribeListenersRequest (software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersRequest)2 DescribeListenersResponse (software.amazon.awssdk.services.elasticloadbalancingv2.model.DescribeListenersResponse)2 RateLimiter (ai.asserts.aws.RateLimiter)1 Resource (ai.asserts.aws.resource.Resource)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.jupiter.api.Test)1 ElasticLoadBalancingV2Client (software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client)1 Listener (software.amazon.awssdk.services.elasticloadbalancingv2.model.Listener)1 LoadBalancer (software.amazon.awssdk.services.elasticloadbalancingv2.model.LoadBalancer)1