From 2d124a4dbe808fd288d204b714a36a10b44ca429 Mon Sep 17 00:00:00 2001 From: Gavin Chappell <2798739+g-a-c@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:24:20 +0100 Subject: [PATCH] fix(inputs.internet_speed): rename enable_file_download to match upstream intent (#11877) --- plugins/inputs/internet_speed/README.md | 11 +++++++++-- plugins/inputs/internet_speed/internet_speed.go | 15 ++++++++++++--- .../inputs/internet_speed/internet_speed_test.go | 8 ++++---- plugins/inputs/internet_speed/sample.conf | 4 ++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/plugins/inputs/internet_speed/README.md b/plugins/inputs/internet_speed/README.md index ae985acb3..000ec71b9 100644 --- a/plugins/inputs/internet_speed/README.md +++ b/plugins/inputs/internet_speed/README.md @@ -3,6 +3,13 @@ The `Internet Speed Monitor` collects data about the internet speed on the system. +On some systems, the default settings may cause speed tests to fail; if this +affects you then try enabling `memory_saving_mode`. This reduces the memory +requirements for the test, and may reduce the runtime of the test. However, +please be aware that this may also reduce the accuracy of the test for fast +(>30Mb/s) connections. This setting enables the upstream +[Memory Saving Mode](https://github.com/showwin/speedtest-go#memory-saving-mode) + ## Configuration ```toml @sample.conf @@ -13,8 +20,8 @@ system. ## demand on your internet connection. # interval = "60m" - ## Sets if runs file download test - # enable_file_download = false + ## Enable to reduce memory usage + # memory_saving_mode = false ## Caches the closest server location # cache = false diff --git a/plugins/inputs/internet_speed/internet_speed.go b/plugins/inputs/internet_speed/internet_speed.go index f517e5227..fc6821293 100644 --- a/plugins/inputs/internet_speed/internet_speed.go +++ b/plugins/inputs/internet_speed/internet_speed.go @@ -17,7 +17,8 @@ var sampleConfig string // InternetSpeed is used to store configuration values. type InternetSpeed struct { - EnableFileDownload bool `toml:"enable_file_download"` + EnableFileDownload bool `toml:"enable_file_download" deprecated:"1.25.0;use 'memory_saving_mode' instead"` + MemorySavingMode bool `toml:"memory_saving_mode"` Cache bool `toml:"cache"` Log telegraf.Logger `toml:"-"` serverCache *speedtest.Server @@ -29,6 +30,12 @@ func (*InternetSpeed) SampleConfig() string { return sampleConfig } +func (is *InternetSpeed) Init() error { + is.MemorySavingMode = is.MemorySavingMode || is.EnableFileDownload + + return nil +} + func (is *InternetSpeed) Gather(acc telegraf.Accumulator) error { // Get closest server s := is.serverCache @@ -58,13 +65,15 @@ func (is *InternetSpeed) Gather(acc telegraf.Accumulator) error { return fmt.Errorf("ping test failed: %v", err) } is.Log.Debug("Running Download...") - err = s.DownloadTest(is.EnableFileDownload) + err = s.DownloadTest(is.MemorySavingMode) if err != nil { + is.Log.Debug("try `memory_saving_mode = true` if this fails consistently") return fmt.Errorf("download test failed: %v", err) } is.Log.Debug("Running Upload...") - err = s.UploadTest(is.EnableFileDownload) + err = s.UploadTest(is.MemorySavingMode) if err != nil { + is.Log.Debug("try `memory_saving_mode = true` if this fails consistently") return fmt.Errorf("upload test failed failed: %v", err) } diff --git a/plugins/inputs/internet_speed/internet_speed_test.go b/plugins/inputs/internet_speed/internet_speed_test.go index ccc887d6c..4dbafe373 100644 --- a/plugins/inputs/internet_speed/internet_speed_test.go +++ b/plugins/inputs/internet_speed/internet_speed_test.go @@ -12,8 +12,8 @@ func TestGathering(t *testing.T) { t.Skip("Skipping network-dependent test in short mode.") } internetSpeed := &InternetSpeed{ - EnableFileDownload: true, - Log: testutil.Logger{}, + MemorySavingMode: true, + Log: testutil.Logger{}, } acc := &testutil.Accumulator{} @@ -26,8 +26,8 @@ func TestDataGen(t *testing.T) { t.Skip("Skipping network-dependent test in short mode.") } internetSpeed := &InternetSpeed{ - EnableFileDownload: true, - Log: testutil.Logger{}, + MemorySavingMode: true, + Log: testutil.Logger{}, } acc := &testutil.Accumulator{} diff --git a/plugins/inputs/internet_speed/sample.conf b/plugins/inputs/internet_speed/sample.conf index a51a88843..83296a88d 100644 --- a/plugins/inputs/internet_speed/sample.conf +++ b/plugins/inputs/internet_speed/sample.conf @@ -5,8 +5,8 @@ ## demand on your internet connection. # interval = "60m" - ## Sets if runs file download test - # enable_file_download = false + ## Enable to reduce memory usage + # memory_saving_mode = false ## Caches the closest server location # cache = false