Skip to content

Added AWS SDK metrics to s3 and sqs clients via micrometer#6237

Closed
mzurita-amz wants to merge 1 commit into
opensearch-project:mainfrom
mzurita-amz:add-s3-sqs-throttling-metrics
Closed

Added AWS SDK metrics to s3 and sqs clients via micrometer#6237
mzurita-amz wants to merge 1 commit into
opensearch-project:mainfrom
mzurita-amz:add-s3-sqs-throttling-metrics

Conversation

@mzurita-amz

@mzurita-amz mzurita-amz commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Description

  • Added common AWSSdkMetrics class so it can be reused in different modules
  • Added integration tests to ensure remote calls generate metrics prefixed with the service name

Issues Resolved

N/A

### Testing

Sample metric emitted by EMF Meter Registry

Metric: aws.s3.marshallingduration Type: StepCounter Value: [Measurement{statistic='COUNT', value=0.0}]

Metric: aws.sqs.marshallingduration Type: StepCounter Value: [Measurement{statistic='COUNT', value=0.0}]

Check List

  • New functionality includes testing.
  • [-] New functionality has a documentation issue. Please link to it in this PR.
    • [-] New functionality has javadoc added
  • 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.

@viquer viquer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@dlvenable dlvenable left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the contribution, @mzurita-amz !

} else if (ex.statusCode() == HttpStatusCode.FORBIDDEN) {
s3ObjectPluginMetrics.getS3ObjectsFailedAccessDeniedCounter().increment();
} else if (ex.statusCode() == HttpStatusCode.THROTTLING) {
s3ObjectPluginMetrics.getS3ObjectsThrottledCounter().increment();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need the throttling metric? This can come from the AWS SDK if we wire the metrics up for Micrometer.

static final String SQS_MESSAGES_RECEIVED_METRIC_NAME = "sqsMessagesReceived";
static final String SQS_RECEIVE_MESSAGES_FAILED_METRIC_NAME = "sqsReceiveMessageFailed";
static final String SQS_RECEIVE_MESSAGES_ACCESS_DENIED_METRIC_NAME = "sqsReceiveMessagesAccessDenied";
static final String SQS_RECEIVE_MESSAGES_THROTTLED_METRIC_NAME = "sqsReceiveMessagesThrottled";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar comment as with S3. Do we really need throttling?

@Test
void processSqsMessages_should_increment_throttled_counter_when_SqsException_with_throttling() {
SqsException exception = (SqsException) SqsException.builder()
.message("Throttled")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two comments on these Exceptions.

  1. You should be able to mock these. We can avoid the builder and any changes on the AWS SDK in this regard.
  2. Including the message hints that we may be reading it. But, the main code is not (which I'm glad of). There is no need to set the message. Certainly not with mocking. If you must use the SDK, just give a random UUID.

@mzurita-amz mzurita-amz force-pushed the add-s3-sqs-throttling-metrics branch 2 times, most recently from c357351 to 0879edb Compare November 4, 2025 14:23
@mzurita-amz mzurita-amz changed the title Added metrics to S3 source Added AWS SDK metrics to s3 and sqs clients via micrometer Nov 4, 2025
@mzurita-amz

Copy link
Copy Markdown
Contributor Author

Addressed comments by just using micrometer with SDK integration.

Comment on lines +49 to +54
Thread.sleep(2000);

assertTrue(meterRegistry.getMeters().stream()
.anyMatch(meter -> meter.getId().getName().startsWith("aws.s3.")),
"Expected S3 metrics to be generated");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does it make sense to use awaitability to wait for the solution instead of a fixed time?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, we should avoid sleeps in our tests. They already take a long time.

Could you use mocks instead?

*/
public static MetricPublisher createMetricPublisher(final String servicePrefix) {
final MeterRegistry meterRegistry = Metrics.globalRegistry;
return new MetricPublisher() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we use instead the same model that we have here, what does this path give us as extra rather than use MicrometerMetricPublisher ?

@mzurita-amz mzurita-amz force-pushed the add-s3-sqs-throttling-metrics branch from 0879edb to c4e0104 Compare November 4, 2025 15:25
Comment on lines +49 to +54
Thread.sleep(2000);

assertTrue(meterRegistry.getMeters().stream()
.anyMatch(meter -> meter.getId().getName().startsWith("aws.s3.")),
"Expected S3 metrics to be generated");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, we should avoid sleeps in our tests. They already take a long time.

Could you use mocks instead?

@mzurita-amz mzurita-amz force-pushed the add-s3-sqs-throttling-metrics branch from c4e0104 to 7c2ba56 Compare November 4, 2025 16:32
- Added common AWSSdkMetrics class so it can be reused in different modules
- Added integration tests to ensure remote calls generate metrics prefixed with the service name

Signed-off-by: Manuel Mangas Zurita <mzurita@amazon.com>
@mzurita-amz mzurita-amz force-pushed the add-s3-sqs-throttling-metrics branch 2 times, most recently from 2b985a4 to 9377b2f Compare November 4, 2025 17:02
@mzurita-amz

Copy link
Copy Markdown
Contributor Author

Discarding this PR in favor of explicitly adding metrics to the catch blocks.

@mzurita-amz mzurita-amz closed this Nov 5, 2025
@mzurita-amz mzurita-amz deleted the add-s3-sqs-throttling-metrics branch November 5, 2025 15:16
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