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