diff --git a/buildnumber.dat b/buildnumber.dat index 573541ac97..d00491fd7e 100644 --- a/buildnumber.dat +++ b/buildnumber.dat @@ -1 +1 @@ -0 +1 diff --git a/cmd/diagcfg/telemetry.go b/cmd/diagcfg/telemetry.go index a54289e268..c7df1bc83c 100644 --- a/cmd/diagcfg/telemetry.go +++ b/cmd/diagcfg/telemetry.go @@ -55,7 +55,7 @@ func maybeUpdateDataDirFromEnv() { func readTelemetryConfigOrExit() logging.TelemetryConfig { maybeUpdateDataDirFromEnv() - cfg, err := logging.ReadTelemetryConfigOrDefault(&dataDir, "") + cfg, err := logging.ReadTelemetryConfigOrDefault(dataDir, "") if err != nil { fmt.Fprintf(os.Stderr, telemetryConfigReadError, err) os.Exit(1) @@ -112,7 +112,7 @@ var telemetryStatusCmd = &cobra.Command{ Long: `Print the node's telemetry status`, Run: func(cmd *cobra.Command, args []string) { maybeUpdateDataDirFromEnv() - cfg, err := logging.ReadTelemetryConfigOrDefault(&dataDir, "") + cfg, err := logging.ReadTelemetryConfigOrDefault(dataDir, "") // If error loading config, can't disable / no need to disable if err != nil { diff --git a/logging/telemetry.go b/logging/telemetry.go index 50be5a0ca8..7258b9ca61 100644 --- a/logging/telemetry.go +++ b/logging/telemetry.go @@ -90,13 +90,14 @@ func makeTelemetryState(cfg TelemetryConfig, hookFactory hookFactory) (*telemetr } // ReadTelemetryConfigOrDefault reads telemetry config from file or defaults if no config file found. -func ReadTelemetryConfigOrDefault(dataDir *string, genesisID string) (cfg TelemetryConfig, err error) { +func ReadTelemetryConfigOrDefault(dataDir string, genesisID string) (cfg TelemetryConfig, err error) { err = nil - if dataDir != nil && *dataDir != "" { - configPath := filepath.Join(*dataDir, TelemetryConfigFilename) + dataDirProvided := dataDir != "" + if dataDirProvided { + configPath := filepath.Join(dataDir, TelemetryConfigFilename) cfg, err = LoadTelemetryConfig(configPath) } - if err != nil && os.IsNotExist(err) { + if (err != nil && os.IsNotExist(err)) || !dataDirProvided { var configPath string configPath, err = config.GetConfigFilePath(TelemetryConfigFilename) if err != nil { diff --git a/logging/telemetryConfig.go b/logging/telemetryConfig.go index 7fa2254261..0e3818c444 100644 --- a/logging/telemetryConfig.go +++ b/logging/telemetryConfig.go @@ -133,8 +133,9 @@ func loadTelemetryConfig(path string) (TelemetryConfig, error) { return createTelemetryConfig(), err } defer f.Close() - cfg := createTelemetryConfig() + var cfg TelemetryConfig var marshaledConfig MarshalingTelemetryConfig + marshaledConfig.TelemetryConfig = createTelemetryConfig() dec := json.NewDecoder(f) err = dec.Decode(&marshaledConfig) cfg = marshaledConfig.TelemetryConfig diff --git a/logging/telemetryConfig_test.go b/logging/telemetryConfig_test.go index 65ee74261b..362ecd6577 100644 --- a/logging/telemetryConfig_test.go +++ b/logging/telemetryConfig_test.go @@ -107,3 +107,15 @@ func Test_SanitizeTelemetryString(t *testing.T) { require.Equal(t, test.expected, SanitizeTelemetryString(test.input, test.parts)) } } + +func TestLoadTelemetryConfig(t *testing.T) { + testLoggingConfigFileName := "../test/testdata/configs/logging/logging.config.test1" + tc, err := loadTelemetryConfig(testLoggingConfigFileName) + require.NoError(t, err) + require.Equal(t, true, tc.Enable) + // make sure the user name was loaded from the specified file + require.Equal(t, "test-user-name", tc.UserName) + // ensure we know how to default correctly if some of the fields in the configuration field aren't specified. + require.Equal(t, createTelemetryConfig().Password, tc.Password) + +} diff --git a/logging/telemetry_test.go b/logging/telemetry_test.go index dbfa04c0fc..fce2e6d9e1 100644 --- a/logging/telemetry_test.go +++ b/logging/telemetry_test.go @@ -18,13 +18,16 @@ package logging import ( "fmt" + "os" "testing" "time" - "github.com/algorand/go-deadlock" "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" + "github.com/algorand/go-deadlock" + + "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/logging/telemetryspec" ) @@ -315,3 +318,21 @@ func TestLogHistoryLevels(t *testing.T) { a.Nil(data[5]["log"]) // Panic - this is stack trace a.NotNil(data[6]["log"]) // Panic } + +func TestReadTelemetryConfigOrDefaultNoDataDir(t *testing.T) { + a := require.New(t) + tempDir := os.TempDir() + originalGlobalConfigFileRoot, _ := config.GetGlobalConfigFileRoot() + config.SetGlobalConfigFileRoot(tempDir) + + cfg, err := ReadTelemetryConfigOrDefault("", "") + defaultCfgSettings := createTelemetryConfig() + config.SetGlobalConfigFileRoot(originalGlobalConfigFileRoot) + + a.Nil(err) + a.NotNil(cfg) + a.NotEqual(TelemetryConfig{}, cfg) + a.Equal(defaultCfgSettings.UserName, cfg.UserName) + a.Equal(defaultCfgSettings.Password, cfg.Password) + a.Equal(len(defaultCfgSettings.GUID), len(cfg.GUID)) +} diff --git a/scripts/travis/deploy_packages.sh b/scripts/travis/deploy_packages.sh index d4dbccc48c..c98b957304 100755 --- a/scripts/travis/deploy_packages.sh +++ b/scripts/travis/deploy_packages.sh @@ -12,10 +12,6 @@ set -e SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" -if ! "${SCRIPTPATH}/../check_golang_version.sh" -then - exit 1 -fi # Get the go build version. GOLANG_VERSION=$("${SCRIPTPATH}/../get_golang_version.sh") @@ -23,6 +19,11 @@ curl -sL -o ~/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gim chmod +x ~/gimme eval "$(~/gimme "${GOLANG_VERSION}")" +if ! "${SCRIPTPATH}/../check_golang_version.sh" +then + exit 1 +fi + scripts/travis/build.sh export RELEASE_GENESIS_PROCESS=true diff --git a/test/testdata/configs/logging/logging.config.test1 b/test/testdata/configs/logging/logging.config.test1 new file mode 100644 index 0000000000..8e9e46fd35 --- /dev/null +++ b/test/testdata/configs/logging/logging.config.test1 @@ -0,0 +1,4 @@ +{ + "Enable": true, + "UserName": "test-user-name" +}