Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new metrics for tracking bytes received and processed by KDS #5237

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sb2k16
Copy link
Member

@sb2k16 sb2k16 commented Dec 2, 2024

Description

This PR is to add two new metrics for KDS source plugin named bytesReceived and bytesProcessed to track the size of throughput being ingested from Kinesis Data Streams.

Issues Resolved

Resolves #1082

Check List

  • New functionality includes testing.
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@@ -177,6 +191,7 @@ public void processRecords(ProcessRecordsInput processRecordsInput) {
// Flush buffer at the end
bufferAccumulator.flush();
recordsProcessed.increment(eventCount);
bytesProcessedSummary.record(recordBytes.stream().mapToLong(Integer::longValue).sum());
Copy link
Member

Choose a reason for hiding this comment

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

These two metrics are the same. We should remove the bytesReceived and keep only bytesProcessed.

@@ -177,6 +191,7 @@ public void processRecords(ProcessRecordsInput processRecordsInput) {
// Flush buffer at the end
bufferAccumulator.flush();
recordsProcessed.increment(eventCount);
bytesProcessedSummary.record(recordBytes.stream().mapToLong(Integer::longValue).sum());
Copy link
Member

Choose a reason for hiding this comment

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

I think we should record each record independently. This will allow us to know the record size as well.

processRecordsInput.records()
  .stream()
  .map(kinesisClientRecord.data().remaining())
  .map(Integer::longValue)
  .forEach(bytesProcessedSummary::record);

@AllArgsConstructor
public class KinesisInputOutputRecord {
private Record<Event> dataPrepperRecord;
private KinesisClientRecord kinesisClientRecord;
Copy link
Member

Choose a reason for hiding this comment

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

Rather than passing this entire record I think you could just provide it as the byte size.

private long recordBytesCount;

Event event = record.getData();
for (KinesisInputOutputRecord kinesisInputOutputRecord: kinesisOutputRecords) {
Record<Event> dataPrepperRecord = kinesisInputOutputRecord.getDataPrepperRecord();
int incomingRecordSizeBytes = kinesisInputOutputRecord.getKinesisClientRecord().data().position();
Copy link
Member

Choose a reason for hiding this comment

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

Can you use ByteBuffer's capacity instead?

https://docs.oracle.com/javase/8/docs/api/java/nio/Buffer.html#capacity--

Per my comment above, you could calculate this elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

@dlvenable - It looks like capacity is the total size of the buffer. To get KCL record bytes, it might not be using the entire capacity. However, position returns the offset upto which the data has been read.

dlvenable
dlvenable previously approved these changes Dec 13, 2024
Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

Thank you!

Signed-off-by: Souvik Bose <souvbose@amazon.com>
Signed-off-by: Souvik Bose <souvbose@amazon.com>
Signed-off-by: Souvik Bose <souvbose@amazon.com>
@sb2k16 sb2k16 force-pushed the kinesis-bytes-metrics branch from e7138ac to d271864 Compare December 14, 2024 00:51
acknowledgementSetOpt.ifPresent(acknowledgementSet -> acknowledgementSet.add(event));

bufferAccumulator.add(record);
bufferAccumulator.add(dataPrepperRecord);
bytesProcessedSummary.record(incomingRecordSizeBytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

you have this line repeated in line number 180 as well? Not sure if this is intentional

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.

Support AWS Kinesis Data Streams as a Source
6 participants