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

aws/retry: Update Retry middleware to save last attempt ResultMetadata #1345

Merged
merged 3 commits into from
Jul 17, 2021

Conversation

jasdel
Copy link
Contributor

@jasdel jasdel commented Jul 16, 2021

Previously all attempt metadata was being nested into the AttemptResults key and a new metadata was being returned with only that item. This change ensures that the returned metadata includes all keys from the last attempt's metadata, along with the AttemptResults.

Depends on aws/smithy-go#318

Fixes #1154

Example usage of GetRawResponse to get the smithyhttp.Response value from the metadata.

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/aws/middleware"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/s3"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

func main() {
	var bucket, key string
	flag.StringVar(&bucket, "b", "", "The bucket name")
	flag.StringVar(&key, "k", "", "The key name")
	flag.Parse()

	cfg, err := config.LoadDefaultConfig(context.Background())
	if err != nil {
		log.Fatalf("expect no error, %v", err)
	}

	client := s3.NewFromConfig(cfg)

	headObjResp, err := client.HeadObject(context.Background(), &s3.HeadObjectInput{
		Bucket: &bucket,
		Key:    &key,
	})
	if err != nil {
		log.Fatalf("expect no error, %v", err)
	}

	rawResp := middleware.GetRawResponse(headObjResp.ResultMetadata)
	httpResp, ok := rawResp.(*smithyhttp.Response)
	if !ok {
		log.Fatalf("expect http response, got %T, %#v", rawResp, rawResp)
	}

	log.Printf("tagging count: %v", httpResp.Header.Get("X-Amz-Tagging-Count"))
}

Previously all attempt metadata was being nested into the AttemptResults
key and a new metadata was being returned with only that item. This
change ensures that the returned metadata includes all keys from the
last attempt's metadata, along with the AttemptResults.
@jasdel jasdel force-pushed the fixup/AttemptResultsMetadata branch from 066a786 to 725d019 Compare July 16, 2021 22:38
@jasdel jasdel merged commit a785d93 into aws:main Jul 17, 2021
@jasdel jasdel deleted the fixup/AttemptResultsMetadata branch July 17, 2021 03:34
jrichard8 pushed a commit to jrichard8/aws-sdk-go-v2 that referenced this pull request Feb 14, 2022
aws#1345)

Previously all attempt metadata was being nested into the AttemptResults
key and a new metadata was being returned with only that item. This
change ensures that the returned metadata includes all keys from the
last attempt's metadata, along with the AttemptResults.
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.

middleware retry breaks passing metadata up
3 participants