github.com/aavshr/aws-sdk-go@v1.41.3/awstesting/integration/performance/s3GetObject/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 "strings" 11 "time" 12 ) 13 14 type Config struct { 15 RequestDuration time.Duration 16 RequestCount int64 17 RequestDelay time.Duration 18 19 Endpoint string 20 Bucket, Key string 21 22 SDK SDKConfig 23 Client ClientConfig 24 } 25 26 func (c *Config) SetupFlags(prefix string, flagset *flag.FlagSet) { 27 flagset.DurationVar(&c.RequestDuration, "duration", 0, 28 "The duration to make requests for. Use instead of count for specific running duration.") 29 flagset.Int64Var(&c.RequestCount, "count", 0, 30 "The total `number` of requests to make. Use instead of duration for specific count.") 31 flagset.DurationVar(&c.RequestDelay, "delay", 0, 32 "The detail between sequential requests.") 33 flagset.StringVar(&c.Endpoint, prefix+"endpoint", "", 34 "Optional overridden endpoint S3 client will connect to.") 35 flagset.StringVar(&c.Bucket, "bucket", "", 36 "The S3 bucket `name` to request the object from.") 37 flagset.StringVar(&c.Key, "key", "", 38 "The S3 object key `name` to request the object from.") 39 40 c.SDK.SetupFlags(prefix, flagset) 41 c.Client.SetupFlags(prefix, flagset) 42 } 43 44 func (c *Config) Validate() error { 45 var errs Errors 46 47 if c.RequestDuration != 0 && c.RequestCount != 0 { 48 errs = append(errs, fmt.Errorf("duration and count canot be used together")) 49 } 50 if c.RequestDuration == 0 && c.RequestCount == 0 { 51 errs = append(errs, fmt.Errorf("duration or count must be provided")) 52 } 53 if len(c.Bucket) == 0 || len(c.Key) == 0 { 54 errs = append(errs, fmt.Errorf("bucket and key are required")) 55 } 56 57 if err := c.SDK.Validate(); err != nil { 58 errs = append(errs, err) 59 } 60 if err := c.Client.Validate(); err != nil { 61 errs = append(errs, err) 62 } 63 64 if len(errs) != 0 { 65 return errs 66 } 67 68 return nil 69 } 70 71 type SDKConfig struct { 72 Anonymous bool 73 ExpectContinue bool 74 } 75 76 func (c *SDKConfig) SetupFlags(prefix string, flagset *flag.FlagSet) { 77 prefix += "sdk." 78 79 flagset.BoolVar(&c.Anonymous, prefix+"anonymous", false, 80 "Specifies if the SDK will make requests anonymously, and unsigned.") 81 82 c.ExpectContinue = true 83 // flagset.BoolVar(&c.ExpectContinue, prefix+"100-continue", true, 84 // "Specifies if the SDK requests will wait for the 100 continue response before sending request payload.") 85 } 86 87 func (c *SDKConfig) Validate() error { 88 return nil 89 } 90 91 type ClientConfig struct { 92 KeepAlive bool 93 Timeouts Timeouts 94 } 95 96 func (c *ClientConfig) SetupFlags(prefix string, flagset *flag.FlagSet) { 97 prefix += "client." 98 99 flagset.BoolVar(&c.KeepAlive, prefix+"http-keep-alive", true, 100 "Specifies if HTTP keep alive is enabled.") 101 102 c.Timeouts.SetupFlags(prefix, flagset) 103 } 104 105 func (c *ClientConfig) Validate() error { 106 var errs Errors 107 108 if err := c.Timeouts.Validate(); err != nil { 109 errs = append(errs, err) 110 } 111 112 if len(errs) != 0 { 113 return errs 114 } 115 return nil 116 } 117 118 type Timeouts struct { 119 Connect time.Duration 120 TLSHandshake time.Duration 121 ExpectContinue time.Duration 122 ResponseHeader time.Duration 123 } 124 125 func (c *Timeouts) SetupFlags(prefix string, flagset *flag.FlagSet) { 126 prefix += "timeout." 127 128 flagset.DurationVar(&c.Connect, prefix+"connect", 30*time.Second, 129 "The `timeout` connecting to the remote host.") 130 131 defTR := http.DefaultTransport.(*http.Transport) 132 133 flagset.DurationVar(&c.TLSHandshake, prefix+"tls", defTR.TLSHandshakeTimeout, 134 "The `timeout` waiting for the TLS handshake to complete.") 135 136 c.ExpectContinue = defTR.ExpectContinueTimeout 137 // flagset.DurationVar(&c.ExpectContinue, prefix+"expect-continue", defTR.ExpectContinueTimeout, 138 // "The `timeout` waiting for the TLS handshake to complete.") 139 140 flagset.DurationVar(&c.ResponseHeader, prefix+"response-header", defTR.ResponseHeaderTimeout, 141 "The `timeout` waiting for the TLS handshake to complete.") 142 } 143 144 func (c *Timeouts) Validate() error { 145 return nil 146 } 147 148 type Errors []error 149 150 func (es Errors) Error() string { 151 var buf strings.Builder 152 for _, e := range es { 153 buf.WriteString(e.Error()) 154 } 155 156 return buf.String() 157 }