use of com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest in project datarouter by hotpads.
the class ElbService method getTargetGroupsArn.
public List<String> getTargetGroupsArn(String loadBalancerArn) {
var request = new DescribeListenersRequest().withLoadBalancerArn(loadBalancerArn);
int randomSleepMs = RandomTool.getRandomIntBetweenTwoNumbers(0, 3_000);
return RetryableTool.tryNTimesWithBackoffAndRandomInitialDelayUnchecked(() -> amazonElasticLoadBalancing.get().describeListeners(request).getListeners().stream().map(Listener::getDefaultActions).flatMap(List::stream).map(Action::getTargetGroupArn).filter(// remove action that have no tg (like redirect)
Objects::nonNull).distinct().collect(Collectors.toList()), NUM_ATTEMPTS, randomSleepMs, true);
}
use of com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest 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 com.amazonaws.services.elasticloadbalancingv2.model.DescribeListenersRequest 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