diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | config/config.go | 23 | ||||
| -rw-r--r-- | datalogger/logger.go | 4 | ||||
| -rw-r--r-- | lgc/lgc.go | 13 | ||||
| -rw-r--r-- | rpm/rpm.go | 1 | ||||
| -rw-r--r-- | traceable/traceable_test.go | 5 | ||||
| -rw-r--r-- | utilities/utilities.go | 4 |
7 files changed, 34 insertions, 18 deletions
@@ -1 +1 @@ -networkQuality
\ No newline at end of file +/networkQuality diff --git a/config/config.go b/config/config.go index 8d9eaa5..f223ec5 100644 --- a/config/config.go +++ b/config/config.go @@ -19,7 +19,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -59,7 +58,16 @@ func (c *Config) Get(configHost string, configPath string, keyLogger io.Writer) configPath = "/" + configPath } c.Source = fmt.Sprintf("https://%s%s", configHost, configPath) - resp, err := configClient.Get(c.Source) + req, err := http.NewRequest("GET", c.Source, nil) + if err != nil { + return fmt.Errorf( + "Error: Could not create request for configuration host %s: %v\n", + configHost, + err, + ) + } + + resp, err := configClient.Do(req) if err != nil { return fmt.Errorf( "could not connect to configuration host %s: %v", @@ -67,8 +75,17 @@ func (c *Config) Get(configHost string, configPath string, keyLogger io.Writer) err, ) } + defer resp.Body.Close() + + if resp.StatusCode != 200 { + return fmt.Errorf( + "Error: Configuration host %s returned %d for config request\n", + configHost, + resp.StatusCode, + ) + } - jsonConfig, err := ioutil.ReadAll(resp.Body) + jsonConfig, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf( "could not read configuration content downloaded from %s: %v", diff --git a/datalogger/logger.go b/datalogger/logger.go index 249a059..1f9c2d6 100644 --- a/datalogger/logger.go +++ b/datalogger/logger.go @@ -112,13 +112,13 @@ func (logger *CSVDataLogger[T]) Export() bool { visibleFields := reflect.VisibleFields(reflect.TypeOf((*T)(nil)).Elem()) for i, v := range visibleFields { description, success := v.Tag.Lookup("Description") - columnName := fmt.Sprintf("%s", v.Name) + columnName := v.Name if success { if description == "[OMIT]" { toOmit = append(toOmit, i) continue } - columnName = fmt.Sprintf("%s", description) + columnName = description } logger.destination.Write([]byte(fmt.Sprintf("%s, ", columnName))) } @@ -19,7 +19,6 @@ import ( "crypto/tls" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptrace" "sync" @@ -346,7 +345,7 @@ func (lgd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) { return } cr := &countingReader{n: &lgd.downloaded, ctx: ctx, readable: get.Body} - _, _ = io.Copy(ioutil.Discard, cr) + _, _ = io.Copy(io.Discard, cr) get.Body.Close() if debug.IsDebug(lgd.debug) { fmt.Printf("Ending a load-generating download.\n") @@ -373,12 +372,12 @@ func (lgu *LoadGeneratingConnectionUpload) ClientId() uint64 { return lgu.clientId } -func (lgd *LoadGeneratingConnectionUpload) TransferredInInterval() (uint64, time.Duration) { - transferred := atomic.SwapUint64(&lgd.uploaded, 0) - newIntervalEnd := (time.Now().Sub(lgd.uploadStartTime)).Nanoseconds() - previousIntervalEnd := atomic.SwapInt64(&lgd.lastIntervalEnd, newIntervalEnd) +func (lgu *LoadGeneratingConnectionUpload) TransferredInInterval() (uint64, time.Duration) { + transferred := atomic.SwapUint64(&lgu.uploaded, 0) + newIntervalEnd := (time.Now().Sub(lgu.uploadStartTime)).Nanoseconds() + previousIntervalEnd := atomic.SwapInt64(&lgu.lastIntervalEnd, newIntervalEnd) intervalLength := time.Duration(newIntervalEnd - previousIntervalEnd) - if debug.IsDebug(lgd.debug) { + if debug.IsDebug(lgu.debug) { fmt.Printf("upload: Transferred: %v bytes in %v.\n", transferred, intervalLength) } return transferred, intervalLength @@ -11,6 +11,7 @@ * You should have received a copy of the GNU General Public License along * with Go Responsiveness. If not, see <https://www.gnu.org/licenses/>. */ + package rpm import ( diff --git a/traceable/traceable_test.go b/traceable/traceable_test.go index 1ba6f51..e9d5a74 100644 --- a/traceable/traceable_test.go +++ b/traceable/traceable_test.go @@ -18,7 +18,6 @@ import ( "context" "crypto/tls" "io" - "io/ioutil" "net/http" "net/http/httptrace" "sync" @@ -141,7 +140,7 @@ func TestDuplicativeTraceables(t *testing.T) { if err != nil { return } - _, _ = io.Copy(ioutil.Discard, get.Body) + _, _ = io.Copy(io.Discard, get.Body) get.Body.Close() }() go func() { @@ -150,7 +149,7 @@ func TestDuplicativeTraceables(t *testing.T) { if err != nil { return } - _, _ = io.Copy(ioutil.Discard, get.Body) + _, _ = io.Copy(io.Discard, get.Body) get.Body.Close() }() diff --git a/utilities/utilities.go b/utilities/utilities.go index 538889c..57b4a90 100644 --- a/utilities/utilities.go +++ b/utilities/utilities.go @@ -180,9 +180,9 @@ func OrTimeout(f func(), timeout time.Duration) { return completed }() select { - case _ = <-completeChannel: + case <-completeChannel: break - case _ = <-time.After(timeout): + case <-time.After(timeout): break } } |
