GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Am I still able to intercept exceptions on retry to emit client side metrics? · Issue #2144 · aws/aws-sdk-java-v2

Am I still able to intercept exceptions on retry to emit client side metrics? #2144

New issue
Copy link
New issue
Copy link
Closed
Closed
Am I still able to intercept exceptions on retry to emit client side metrics?#2144
Copy link
Labels
closing-soonThis issue will close in 4 days unless further comments are made.guidanceQuestion that needs advice or information.

Description

@kevinrobayna
kevinrobayna
opened on Nov 12, 2020
Issue body actions

Describe the issue

In v1 I was able to add a lambda to intercept exceptions in client and emit metrics if desired, I'm struggling to do the same with v2.

import com.amazonaws.retry.PredefinedRetryPolicies;
import com.amazonaws.retry.RetryPolicy;

  private RetryPolicy buildRetryPolicy() {
    return new RetryPolicy(
        (originalRequest, exception, retriesAttempted) -> {
          LOGGER.info("AWS failed with exception {}", exception.getClass());
          if (exception instanceof ProvisionedThroughputExceededException) {
            metrics.getCounter(PROVIDER_EXCEPTION,Map.of("exception", "ProvisionedThroughputExceededException")).inc();
          }
          return PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry(
              originalRequest, exception, retriesAttempted);
        },
        PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY,
        PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY,
        false);
  }

Your Environment

  • AWS Java SDK version used: '2.15.26'
  • JDK version used: 11
  • Operating System and version: N/A

Activity

  1. kevinrobayna
    added
    guidanceQuestion that needs advice or information.
    needs-triageThis issue or PR still needs to be triaged.
    on Nov 12, 2020
  2. debora-ito commented on Nov 17, 2020

    @debora-ito
    debora-ito
    on Nov 17, 2020
    Member
    More actions

    RetryCondition is what you're looking for, here's a super quick code example:

    RetryPolicy policy =  RetryPolicy.builder()
                .retryCondition(
                    retryPolicyContext -> {
                        if (retryPolicyContext.exception() instanceof ProvisionedThroughputExceededException)
                             // add metrics
                        return false;
                    })
                .build();
  3. debora-ito
    added
    closing-soonThis issue will close in 4 days unless further comments are made.
    and removed
    needs-triageThis issue or PR still needs to be triaged.
    on Nov 17, 2020
  4. kevinrobayna commented on Nov 17, 2020

    @kevinrobayna
    kevinrobayna
    on Nov 17, 2020
    Author
    More actions

    That might be exactly what i need! Thanks! I'll try it out.

  5. github-actions
    removed
    closing-soonThis issue will close in 4 days unless further comments are made.
    on Nov 17, 2020
  6. kevinrobayna commented on Nov 18, 2020

    @kevinrobayna
    kevinrobayna
    on Nov 18, 2020
    Author
    More actions

    @debora-ito but this return false; that it won't be retried. I don't want to change the default way I just want to intercept the method to log the exceptions.

              return PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry(
                  originalRequest, exception, retriesAttempted);
    
  7. debora-ito commented on Nov 18, 2020

    @debora-ito
    debora-ito
    on Nov 18, 2020
    Member
    More actions

    You are correct, I just wanted to show a way to use the RetryCondition, you'd need to add your logic.

  8. debora-ito commented on Nov 18, 2020

    @debora-ito
    debora-ito
    on Nov 18, 2020
    Member
    More actions
    return RetryCondition.defaultRetryCondition().shouldRetry(RetryPolicyContext.builder().build());

    Let us know if this would help.

    Reacted by Kevin Robayna
  9. debora-ito
    added
    closing-soonThis issue will close in 4 days unless further comments are made.
    on Nov 18, 2020
  10. kevinrobayna commented on Nov 19, 2020

    @kevinrobayna
    kevinrobayna
    on Nov 19, 2020
    Author
    More actions

    Thanks! that worked. For anyone who reads this in the future.

                RetryPolicy.defaultRetryPolicy().toBuilder()
                    .retryCondition(
                        retryPolicyContext -> {
                          LOGGER.info("AWS failed with exception {}", retryPolicyContext.getClass());
                          // send metrics
                          return RetryCondition.defaultRetryCondition().shouldRetry(retryPolicyContext);
                        })
                    .build())
    
  11. kevinrobayna
    closed this as completedon Nov 19, 2020
  12. aws-sdk-java-automation
    added a commit that references this issue on Sep 13, 2022

    Merge pull request #2144 from aws/staging/51c6cb82-dbde-43cb-8e37-9d4…

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    closing-soonThis issue will close in 4 days unless further comments are made.guidanceQuestion that needs advice or information.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.