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;
});
});
}
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();
}
Aggregations