Skip to content

Added API metrics to SQS common worker#6248

Merged
dlvenable merged 1 commit into
opensearch-project:mainfrom
mzurita-amz:sqs-error-metrics
Nov 11, 2025
Merged

Added API metrics to SQS common worker#6248
dlvenable merged 1 commit into
opensearch-project:mainfrom
mzurita-amz:sqs-error-metrics

Conversation

@mzurita-amz

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

Copy link
Copy Markdown
Contributor

Description

tl;dr; AWS SQS emits some of their exceptions without the matching HTTP code. As we want to generate an aggregate version of these exceptions, we have to explicitly catch the type alongside the status code for the ones that leverage the status code (i.e. InvalidAddressException).

Issues Resolved

N/A

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.


public void recordSqsException(final AwsServiceException e) {
if ((e instanceof SqsException && ((SqsException) e).statusCode() == 403) ||
e instanceof KmsAccessDeniedException) {

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.

Currently OSIS does not perform any client-side encryption of KMS keys. Only SQS performs this. Because this Java exception comes from the AWS SDK in response to an SQS API request, there should be no KMS exceptions directly. All exceptions should be SqsException.

This code can be simplified with that as well since e instanceof SqsException can be used before all of these status code checks.

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.

I see that these KmsXYZ exceptions do come from SQS. I should have looked at the imports.

import software.amazon.awssdk.services.sqs.model.KmsAccessDeniedException;

So this does get thrown, right?

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.

yeah, if the notification queue has been defined with KMS encryption, the ReceiveMessages call can throw these exceptions if the caller role has not enough permissions to interact with the KMS key.

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.

but let me fix some of these casts... I mistakenly added them from a previous revision and are not needed.


@BeforeEach
void setUp() {
prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);

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.

Does this require having a Prometheus server running?

If so, please add a README.md to the sqs-source project describing the setup needed.

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.

There is no need for Prometheus server. This registry only exposes a scrape method that returns Prometheus metrics in plain-text.

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.

We don't need an IT for this. We can fix later though.

Signed-off-by: Manuel Mangas Zurita <mzurita@amazon.com>

@BeforeEach
void setUp() {
prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);

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.

We don't need an IT for this. We can fix later though.

@dlvenable dlvenable merged commit f266312 into opensearch-project:main Nov 11, 2025
46 of 47 checks passed
@mzurita-amz mzurita-amz deleted the sqs-error-metrics branch November 13, 2025 22:23
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