pvillard31 commented on code in PR #11945:
URL: https://github.com/apache/nifi/pull/11945#discussion_r4652172179


##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ControlRate.java:
##########
@@ -424,10 +481,10 @@ private void clearExpiredThrottles(final ProcessContext 
context) {
         // Throttle ourselves to see if we should actually clear old throttles
         if (lastClearTime < throttleExpirationMillis) {
             if (lastThrottleClearTime.compareAndSet(lastClearTime, 
getCurrentTimeMillis())) {
-                if (dataThrottleRequired()) {
+                if (configuration.dataThrottleRequired) {
                     removeExpiredThrottles(dataThrottleMap, 
throttleExpirationMillis);
                 }
-                if (countThrottleRequired()) {
+                if (configuration.dataThrottleRequired) {

Review Comment:
   Should this second check be configuration.countThrottleRequired? As written, 
expired count throttles are never removed for flowfile rate or attribute rate.



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ControlRate.java:
##########
@@ -470,56 +527,26 @@ protected long getCurrentTimeMillis() {
      * flowfile attribute, the specified attribute must be present and must be 
a long integer.
      */
     private boolean isRateAttributeValid(FlowFile flowFile) {
-        if (rateControlCriteria == RateControlCriteria.ATTRIBUTE_RATE) {
-            final String attributeValue = 
flowFile.getAttribute(rateControlAttribute);
+        if (configuration.rateControlCriteria == 
RateControlCriteria.ATTRIBUTE_RATE) {
+            final String attributeValue = 
flowFile.getAttribute(configuration.rateControlAttribute);
             return attributeValue != null && 
POSITIVE_LONG_PATTERN.matcher(attributeValue).matches();
         }
         return true;
     }
 
-    /*
-     * Determine the amount this FlowFile will incur against the maximum 
allowed rate.
-     * This is applicable to data size accrual only
-     */
-    private long getDataSizeAccrual(FlowFile flowFile) {
-        return flowFile.getSize();
-    }
-
-    /*
-     * Determine the amount this FlowFile will incur against the maximum 
allowed rate.
-     * This is applicable to counting accruals, FlowFiles or attributes
-     */
-    private long getCountAccrual(FlowFile flowFile) {
-        return switch (rateControlCriteria) {
-            case DATA_RATE -> DEFAULT_ACCRUAL_COUNT;
-            case FLOWFILE_RATE, DATA_OR_FLOWFILE_RATE -> 1;
-            case ATTRIBUTE_RATE -> {
-                final String attributeValue = 
flowFile.getAttribute(rateControlAttribute);
-                if (attributeValue == null) {
-                    yield DEFAULT_ACCRUAL_COUNT;
-                }
-
-                if (!POSITIVE_LONG_PATTERN.matcher(attributeValue).matches()) {
-                    yield DEFAULT_ACCRUAL_COUNT;
-                }
-                yield Long.parseLong(attributeValue);
-            }
-        };
-    }
-
-    private boolean dataThrottleRequired() {
-        return rateControlCriteria != null && switch (rateControlCriteria) {
-            case DATA_RATE, DATA_OR_FLOWFILE_RATE -> true;
-            default -> false;
-        };
-    }
-
-    private boolean countThrottleRequired() {
-        return rateControlCriteria != null && switch (rateControlCriteria) {
-            case FLOWFILE_RATE, DATA_OR_FLOWFILE_RATE, ATTRIBUTE_RATE -> true;
-            default -> false;
-        };
-    }
+    private record ThrottleConfiguration(
+        RateControlCriteria rateControlCriteria,
+        boolean dataThrottleRequired,
+        boolean countThrottleRequired,
+        long maximumDataRate,
+        long maximumCountRate,
+        String rateControlAttribute,
+        String groupingAttributeName,
+        int timePeriodSeconds,
+        long timePeriodMillis,

Review Comment:
   Is timePeriodMillis needed in the record? It does not seem to be read 
anywhere.



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ControlRate.java:
##########
@@ -424,10 +481,10 @@ private void clearExpiredThrottles(final ProcessContext 
context) {
         // Throttle ourselves to see if we should actually clear old throttles
         if (lastClearTime < throttleExpirationMillis) {
             if (lastThrottleClearTime.compareAndSet(lastClearTime, 
getCurrentTimeMillis())) {
-                if (dataThrottleRequired()) {
+                if (configuration.dataThrottleRequired) {

Review Comment:
   Could we strengthen an existing TestControlRate expiry test so it checks 
that the count throttle map is cleared with the flowfile rate criteria? That 
test would have caught the condition just below.



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