gnodet-bot commented on code in PR #28198:
URL: https://github.com/apache/camel/pull/28198#discussion_r4333480670


##########
components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/NewIssuesConsumer.java:
##########
@@ -129,16 +129,19 @@ protected int doPoll() throws Exception {
      * @return queue of new issues
      */
     private Queue<Issue> getNewIssues() {
-        String jqlFilter;
+        Queue<Issue> issues;
         // If we have processed an issue before, use its timestamp to get only 
the newer ones
         if (latestIssue != null) {
-            jqlFilter = String.format(NEW_ISSUES_JQL_FORMAT, 
getServerTimestamp(), getEndpoint().getJql());
+            String jqlFilter = String.format(NEW_ISSUES_JQL_FORMAT, 
getServerTimestamp(), getEndpoint().getJql());
+            // all of them: the newest one becomes the latest issue, so a new 
issue left out by maxResults would never
+            // be returned again; maxResults is the page size here
+            int maxResults = getEndpoint().getMaxResults();
+            int pageSize = maxResults > 0 ? Math.min(maxResults, 
SEARCH_MAX_PER_QUERY) : SEARCH_MAX_PER_QUERY;
+            issues = getIssues(jqlFilter, SEARCH_START_AT, pageSize, 
Integer.MAX_VALUE);

Review Comment:
   💡 **Behavioural change worth documenting**: the user-configured `maxResults` 
is used here only as `pageSize`; the actual result cap is `Integer.MAX_VALUE`. 
The previous code capped the total at `maxResults`. The comment explains the 
rationale, but this change is non-obvious from the parameter name — a Javadoc 
note on `JiraConfiguration.getMaxResults()` clarifying its dual role (page size 
for `newIssues`, total cap for other consumers) would help future readers.



##########
components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java:
##########
@@ -155,6 +151,27 @@ protected Queue<Issue> getIssues(String jql, int start, 
int maxPerQuery, int max
         return new LinkedList<>(issues);
     }
 
+    /**
+     * Jira Cloud cannot page by startAt: its search client throws 
UnsupportedOperationException for a startAt other
+     * than 0. The pages are read with the next page token of the previous 
page instead, from the first issue, until the
+     * last page (no next page token) or maxResults (ignored if it's <= 0).
+     */
+    private Queue<Issue> getCloudIssues(
+            AsynchronousCloudSearchRestClient searchRestClient, String jql, 
int maxPerQuery, int maxResults) {
+        Set<Issue> issues = new LinkedHashSet<>();
+        String nextPageToken = null;
+        do {
+            SearchResult searchResult
+                    = searchRestClient.enhancedSearchJql(jql, maxPerQuery, 
nextPageToken, Set.of("*navigable"), null).claim();
+            for (Issue issue : searchResult.getIssues()) {
+                issues.add(issue);
+            }
+            nextPageToken = searchResult.getNextPageToken();
+        } while (nextPageToken != null && !(maxResults > 0 && issues.size() >= 
maxResults));

Review Comment:
   ⚠️ **Unbounded memory accumulation**: when `maxResults = Integer.MAX_VALUE` 
(as passed from `NewIssuesConsumer`), the `issues.size() >= maxResults` guard 
never fires. After a long outage or a large import, all new issues are 
accumulated in-heap before any exchange is routed. Consider logging a WARN at a 
threshold (e.g. every 10 000 issues) so runaway polls are visible in the logs.



##########
components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java:
##########
@@ -122,6 +122,10 @@ protected Queue<Issue> getIssues(String jql, int start, 
int maxPerQuery, int max
             maxPerQuery = maxResults;
         }
 
+        if (endpoint.getClient().getSearchClient() instanceof 
AsynchronousCloudSearchRestClient cloudSearchRestClient) {
+            return getCloudIssues(cloudSearchRestClient, jql, maxPerQuery, 
maxResults);

Review Comment:
   ℹ️ **Broader scope than the PR title suggests**: this `instanceof` dispatch 
sits in `AbstractJiraConsumer.getIssues()`, which is shared by 
`NewCommentsConsumer` and `WatcherConsumer` as well. Those consumers now 
silently switch to token-based Cloud paging too. Worth a note in the PR 
description and ideally in the method Javadoc so maintainers know this is an 
intentional cross-consumer change.



-- 
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]

Reply via email to