Skip to content

NIFI-16380 Add Records Metrics to ConsumeKinesis - #11712

Open
exceptionfactory wants to merge 2 commits into
apache:mainfrom
exceptionfactory:NIFI-16380
Open

exceptionfactory wants to merge 2 commits into
apache:mainfrom
exceptionfactory:NIFI-16380

Conversation

@exceptionfactory

Copy link
Copy Markdown
Contributor

Summary

NIFI-16380 Adds the following metrics to the ConsumeKinesis Processor:

  • kinesis.bytes.consumed
    • Type: Counter
  • kinesis.records.consumed
    • Type: Counter
  • kinesis.consumer.milliseconds.behind
    • Type: Gauge
  • kinesis.records.parsed.errors
    • Type: Counter

The implementation follows the pattern of NIFI-16375 adding similar metrics to the ConsumeKafka Processor. The primary difference is the consumer.milliseconds.behind, which tracks the MillisBehindLatest from AWS Kinesis, providing a rough gauge of latency depending on the expected behavior of the Kinesis stream.

The implementation includes the Stream Name and Shard ID as attributes, using the same attribute names already used for FlowFiles.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000
  • Pull request contains commits signed with a registered key indicating Verified status

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using ./mvnw clean install -P contrib-check
    • JDK 21
    • JDK 25

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

}
}

if (recordCount == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should the lag gauge be recorded independently of recordCount, using the shard lag observations, so an empty successful poll can update a previously positive lag to zero?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, will adjust to always report the milliseconds behind regardless of record count

final Map<String, String> attributes = getMetricAttributes(streamName, shardId);
session.adjustCounter(KinesisMetricName.RECORDS_CONSUMED.getMetricName(), recordCount, attributes, CommitTiming.NOW);
session.adjustCounter(KinesisMetricName.BYTES_CONSUMED.getMetricName(), bytesConsumed, attributes, CommitTiming.NOW);
// Kinesis uses -1 when millisBehindLatest is absent so record that as 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should an absent MillisBehindLatest value skip the gauge instead of converting the -1 sentinel to zero?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I considered that approach, but decided to set 0 as a definitive indicator. With this approach, the milliseconds behind is always reported with everything else, and 0 indicates that the consumer is not behind, versus having to infer it from the lack of a change. Are there reasons you think not reporting would be better?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My concern is that AWS defines 0 as an observed caught-up state, while -1 means no MillisBehindLatest value was provided. Converting unknown to zero would report that the consumer is caught up without evidence, so I think the gauge should be skipped until a real value is observed. But, to be fair, this should be an exceptional situation (I assume) so I don't feel strongly about it and would be OK with the current approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that makes sense. On balance, it seems better to mirror the indicator that AWS provides, so I will switch this to check for -1 and not report if found

}

@Test
void testEmptyConsumeDoesNotRecordMetrics() throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a test where lag changes from positive to zero on an empty successful response, to verify that the gauge reports the caught-up state?

@exceptionfactory

Copy link
Copy Markdown
Contributor Author

Thanks for the review @pvillard31, I pushed an update to record millisBehindLatest more consistently when available, and added tests

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.

2 participants