Skip to content

Commit

Permalink
Merge pull request #1851 from onetechnical/onetechnical/relbeta2.4.1
Browse files Browse the repository at this point in the history
go-algorand 2.4.1-beta
  • Loading branch information
algojohnlee authored Jan 20, 2021
2 parents 7594a3f + 3c07756 commit 7e8a395
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion buildnumber.dat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
1
4 changes: 2 additions & 2 deletions cmd/diagcfg/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions logging/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion logging/telemetryConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions logging/telemetryConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
23 changes: 22 additions & 1 deletion logging/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}
9 changes: 5 additions & 4 deletions scripts/travis/deploy_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ 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")

curl -sL -o ~/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
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
Expand Down
4 changes: 4 additions & 0 deletions test/testdata/configs/logging/logging.config.test1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Enable": true,
"UserName": "test-user-name"
}

0 comments on commit 7e8a395

Please sign in to comment.