davsclaus commented on code in PR #28036:
URL: https://github.com/apache/camel/pull/28036#discussion_r4306093653
##########
components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/vault/CloudTrailReloadTriggerTask.java:
##########
@@ -273,26 +285,43 @@ public void run() {
if (!useSqsNotification) {
try {
- LookupEventsRequest.Builder eventsRequestBuilder =
LookupEventsRequest.builder()
- .maxResults(100)
-
.lookupAttributes(LookupAttribute.builder().attributeKey(LookupAttributeKey.EVENT_SOURCE)
-
.attributeValue(SECRETSMANAGER_AMAZONAWS_COM).build());
-
- if (lastTime != null) {
- eventsRequestBuilder.startTime(lastTime.plusMillis(1000));
- }
-
- LookupEventsRequest lookupEventsRequest =
eventsRequestBuilder.build();
-
- LookupEventsResponse response =
cloudTrailClient.lookupEvents(lookupEventsRequest);
- List<Event> events = response.events();
-
- if (!events.isEmpty()) {
- lastTime = events.get(0).eventTime();
- }
+ // read every page of the events since the last check, so that
an update is not left behind when
+ // there are more events (such as GetSecretValue calls) than
fit in one page
+ List<Event> events = new ArrayList<>();
+ String nextToken = null;
+ do {
+ LookupEventsRequest.Builder eventsRequestBuilder =
LookupEventsRequest.builder()
+ .maxResults(LOOKUP_MAX_RESULTS)
+
.lookupAttributes(LookupAttribute.builder().attributeKey(LookupAttributeKey.EVENT_SOURCE)
+
.attributeValue(SECRETSMANAGER_AMAZONAWS_COM).build());
Review Comment:
This filter returns every Secrets Manager call (mostly `GetSecretValue`
reads), so the pages grow with read traffic and share the 2 requests/s
LookupEvents limit with the whole account. Filtering with
`LookupAttributeKey.EVENT_NAME` on `PutSecretValue` and on `UpdateSecret` (two
lookups, because only one lookup attribute is allowed) from the same
`lastTime`, then running the merged events through the loop below, would read
only updates and keep this to about 2 requests per check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]