log the request with body along with received response for put object

Signed-off-by: m.malygina <m.malygina@yadro.com>
This commit is contained in:
Maria Malygina 2023-07-24 16:50:33 +03:00 committed by m.malygina
parent 4ef3795e04
commit 82a02cc8d2

View file

@ -6,17 +6,18 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"strconv"
"time"
"git.frostfs.info/TrueCloudLab/xk6-frostfs/internal/stats"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/dop251/goja"
"go.k6.io/k6/js/modules"
"go.k6.io/k6/metrics"
"log"
"strconv"
"time"
)
type (
@ -52,15 +53,24 @@ type (
)
func (c *Client) Put(bucket, key string, payload goja.ArrayBuffer) PutResponse {
cfg, err := config.LoadDefaultConfig(c.vu.Context())
if err != nil {
log.Fatal(err)
}
// log the request with body along with received response
cfg.ClientLogMode = aws.LogRequestWithBody | aws.LogResponseWithBody
client := s3.NewFromConfig(cfg)
rdr := bytes.NewReader(payload.Bytes())
sz := rdr.Size()
start := time.Now()
_, err := c.cli.PutObject(c.vu.Context(), &s3.PutObjectInput{
_, err = client.PutObject(c.vu.Context(), &s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
Body: rdr,
})
if err != nil {
stats.Report(c.vu, objPutFails, 1)
return PutResponse{Success: false, Error: err.Error()}