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