Skip to content

NIFI-6889 - Create RulesRecordProcessor #3912

Closed
YolandaMDavis wants to merge 2 commits intoapache:masterfrom
YolandaMDavis:NIFI-6889
Closed

NIFI-6889 - Create RulesRecordProcessor #3912
YolandaMDavis wants to merge 2 commits intoapache:masterfrom
YolandaMDavis:NIFI-6889

Conversation

@YolandaMDavis
Copy link
Contributor

NIFI-6889 - reorganizing rules bundle and nar

NIFI-6889 - created RulesRecordProcessor

NIFI-6889 - rat check and checkstyle fixes

NIFI-6889 - added processor in resources, processor corrections

NIFI-6889 - fix issue when transferring original flowfile

Thank you for submitting a contribution to Apache NiFi.

Please provide a short description of the PR here:

Description of PR

Enables X functionality; fixes bug NIFI-YYYY.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically master)?

  • Is your initial contribution a single, squashed commit? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not squash or use --force when pushing to allow for clean monitoring of changes.

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit tests to verify your changes?
  • Have you verified that the full build is successful on both JDK 8 and JDK 11?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
  • If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.

NIFI-6889 - created RulesRecordProcessor

NIFI-6889 - rat check and checkstyle fixes

NIFI-6889 - added processor in resources, processor corrections

NIFI-6889 - fix issue when transferring original flowfile
@WritesAttribute(attribute = "mime.type", description = "The MIME Type that the configured Record Writer indicates is appropriate"),
})
@CapabilityDescription("Submits record values to a rules engine and returns actions determined by the engine as records ")
public class RulesRecordProcessor extends AbstractProcessor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current convention is to not have Processor in the name of the processor, rather some kind of verb that says what it does. How about EvaluateRulesRecord or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, let's go with that 👍

"fields": [
{"name": "type", "type": "string"},
{"name": "attributes", "type": {"type": "map", "values": "string"}},
{"name": "metrics", "type": {"type": "map", "values": "string"}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have the metrics values be double rather than string? Would make subsequent operations (arithmetic functions via QueryRecord for example) easier and avoids a necessary conversion downstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this should be corrected to say facts and not metrics and those could be either string or numeric value.

static final PropertyDescriptor RULES_ENGINE = new PropertyDescriptor.Builder()
.name("rules-engine-service")
.displayName("Rules Engine Service")
.description("Specifies the Controller Service to use for applying rules to metrics.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this read facts instead of metrics? Just want to make sure the terminology is consistent throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it should read facts (same with the schema as mentioned previously)

static final PropertyDescriptor ACTION_RECORD_WRITER = new PropertyDescriptor.Builder()
.name("action-record-writer")
.displayName("Action Record Writer")
.description("Specifies the Controller Service to use for writing out action records")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should mention here that Inherit Schema on the RecordWriter will allow it to use the generated/static schema provided by the processor. The user could still override it (to include/exclude fields) but might be helpful to point out that Inherit Schema wouldn't inherit the reader schema, but the provided one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

*/
package org.apache.nifi.rules.processors;

import com.google.common.collect.Lists;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need Guava here? Maybe use Arrays.asList() instead, since I don't think Guava is an explicit dependency of this module (must be transitive)

Copy link
Contributor Author

@YolandaMDavis YolandaMDavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattyb149 thanks for the review. I'll work on incorporating changes. One other note is the Processor currently will emit records even if there are no actions. I'm thinking I need to add an option for includeZeroResults as well.

@YolandaMDavis
Copy link
Contributor Author

@mattyb149 I pushed the changes you suggested for your review. Also I was thinking more about excluding empty results and am now rethinking that, especially since even though no actions are returned it still has provenance information associated with it (so technically the flow file may still have value). I'm thinking about leaving it as is but wanted to get your thoughts?

@mattyb149
Copy link
Contributor

@YolandaMDavis I like the idea of a property to configure whether to send a flowfile on zero results, it's more flexible and supports both use cases. Whichever default value is fine with me.

@joewitt The processor takes the "facts" (field values) and runs them through a rules engine which returns a set of actions to take (but it doesn't do the actions, just passes them along). Maybe now that record-based processors are becoming the norm we don't need Record in the name (there won't ever be a non-record-based one), so maybe we name the processor something like EvaluateRulesToActions?

@YolandaMDavis
Copy link
Contributor Author

Not clear if this is generic enough for community adoption so closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants