github.com/aavshr/aws-sdk-go@v1.41.3/awstesting/integration/performance/s3UploadManager/config.go (about)

     1  //go:build integration && perftest
     2  // +build integration,perftest
     3  
     4  package main
     5  
     6  import (
     7  	"flag"
     8  	"fmt"
     9  	"net/http"
    10  	"os"
    11  	"strings"
    12  	"time"
    13  
    14  	"github.com/aavshr/aws-sdk-go/service/s3/s3manager"
    15  )
    16  
    17  type Config struct {
    18  	Bucket     string
    19  	Filename   string
    20  	Size       int64
    21  	TempDir    string
    22  	LogVerbose bool
    23  
    24  	SDK    SDKConfig
    25  	Client ClientConfig
    26  }
    27  
    28  func (c *Config) SetupFlags(prefix string, flagset *flag.FlagSet) {
    29  	flagset.StringVar(&c.Bucket, "bucket", "",
    30  		"The S3 bucket `name` to upload the object to.")
    31  	flagset.StringVar(&c.Filename, "file", "",
    32  		"The `path` of the local file to upload.")
    33  	flagset.Int64Var(&c.Size, "size", 0,
    34  		"The S3 object size in bytes to upload")
    35  	flagset.StringVar(&c.TempDir, "temp", os.TempDir(), "location to create temporary files")
    36  	flagset.BoolVar(&c.LogVerbose, "verbose", false,
    37  		"The output log will include verbose request information")
    38  
    39  	c.SDK.SetupFlags(prefix, flagset)
    40  	c.Client.SetupFlags(prefix, flagset)
    41  }
    42  
    43  func (c *Config) Validate() error {
    44  	var errs Errors
    45  
    46  	if len(c.Bucket) == 0 || (c.Size <= 0 && c.Filename == "") {
    47  		errs = append(errs, fmt.Errorf("bucket and filename/size are required"))
    48  	}
    49  
    50  	if err := c.SDK.Validate(); err != nil {
    51  		errs = append(errs, err)
    52  	}
    53  	if err := c.Client.Validate(); err != nil {
    54  		errs = append(errs, err)
    55  	}
    56  
    57  	if len(errs) != 0 {
    58  		return errs
    59  	}
    60  
    61  	return nil
    62  }
    63  
    64  type SDKConfig struct {
    65  	PartSize            int64
    66  	Concurrency         int
    67  	WithUnsignedPayload bool
    68  	WithContentMD5      bool
    69  	ExpectContinue      bool
    70  	BufferProvider      s3manager.ReadSeekerWriteToProvider
    71  }
    72  
    73  func (c *SDKConfig) SetupFlags(prefix string, flagset *flag.FlagSet) {
    74  	prefix += "sdk."
    75  
    76  	flagset.Int64Var(&c.PartSize, prefix+"part-size", s3manager.DefaultUploadPartSize,
    77  		"Specifies the `size` of parts of the object to upload.")
    78  	flagset.IntVar(&c.Concurrency, prefix+"concurrency", s3manager.DefaultUploadConcurrency,
    79  		"Specifies the number of parts to upload `at once`.")
    80  	flagset.BoolVar(&c.WithUnsignedPayload, prefix+"unsigned", false,
    81  		"Specifies if the SDK will use UNSIGNED_PAYLOAD for part SHA256 in request signature.")
    82  	flagset.BoolVar(&c.WithContentMD5, prefix+"content-md5", true,
    83  		"Specifies if the SDK should compute the content md5 header for S3 uploads.")
    84  
    85  	flagset.BoolVar(&c.ExpectContinue, prefix+"100-continue", true,
    86  		"Specifies if the SDK requests will wait for the 100 continue response before sending request payload.")
    87  }
    88  
    89  func (c *SDKConfig) Validate() error {
    90  	return nil
    91  }
    92  
    93  type ClientConfig struct {
    94  	KeepAlive bool
    95  	Timeouts  Timeouts
    96  
    97  	MaxIdleConns        int
    98  	MaxIdleConnsPerHost int
    99  }
   100  
   101  func (c *ClientConfig) SetupFlags(prefix string, flagset *flag.FlagSet) {
   102  	prefix += "client."
   103  
   104  	flagset.BoolVar(&c.KeepAlive, prefix+"http-keep-alive", true,
   105  		"Specifies if HTTP keep alive is enabled.")
   106  
   107  	defTR := http.DefaultTransport.(*http.Transport)
   108  
   109  	flagset.IntVar(&c.MaxIdleConns, prefix+"idle-conns", defTR.MaxIdleConns,
   110  		"Specifies max idle connection pool size.")
   111  
   112  	flagset.IntVar(&c.MaxIdleConnsPerHost, prefix+"idle-conns-host", http.DefaultMaxIdleConnsPerHost,
   113  		"Specifies max idle connection pool per host, will be truncated by idle-conns.")
   114  
   115  	c.Timeouts.SetupFlags(prefix, flagset)
   116  }
   117  
   118  func (c *ClientConfig) Validate() error {
   119  	var errs Errors
   120  
   121  	if err := c.Timeouts.Validate(); err != nil {
   122  		errs = append(errs, err)
   123  	}
   124  
   125  	if len(errs) != 0 {
   126  		return errs
   127  	}
   128  	return nil
   129  }
   130  
   131  type Timeouts struct {
   132  	Connect        time.Duration
   133  	TLSHandshake   time.Duration
   134  	ExpectContinue time.Duration
   135  	ResponseHeader time.Duration
   136  }
   137  
   138  func (c *Timeouts) SetupFlags(prefix string, flagset *flag.FlagSet) {
   139  	prefix += "timeout."
   140  
   141  	flagset.DurationVar(&c.Connect, prefix+"connect", 30*time.Second,
   142  		"The `timeout` connecting to the remote host.")
   143  
   144  	defTR := http.DefaultTransport.(*http.Transport)
   145  
   146  	flagset.DurationVar(&c.TLSHandshake, prefix+"tls", defTR.TLSHandshakeTimeout,
   147  		"The `timeout` waiting for the TLS handshake to complete.")
   148  
   149  	flagset.DurationVar(&c.ExpectContinue, prefix+"expect-continue", defTR.ExpectContinueTimeout,
   150  		"The `timeout` waiting for the TLS handshake to complete.")
   151  
   152  	flagset.DurationVar(&c.ResponseHeader, prefix+"response-header", defTR.ResponseHeaderTimeout,
   153  		"The `timeout` waiting for the TLS handshake to complete.")
   154  }
   155  
   156  func (c *Timeouts) Validate() error {
   157  	return nil
   158  }
   159  
   160  type Errors []error
   161  
   162  func (es Errors) Error() string {
   163  	var buf strings.Builder
   164  	for _, e := range es {
   165  		buf.WriteString(e.Error())
   166  	}
   167  
   168  	return buf.String()
   169  }