diff --git a/logging/telemetryCommon.go b/logging/telemetryCommon.go index 969b4ae239..c8c10538b4 100644 --- a/logging/telemetryCommon.go +++ b/logging/telemetryCommon.go @@ -55,6 +55,8 @@ type TelemetryConfig struct { FilePath string // Path to file on disk, if any ChainID string `json:"-"` SessionGUID string `json:"-"` + UserName string + Password string } type asyncTelemetryHook struct { diff --git a/logging/telemetryConfig.go b/logging/telemetryConfig.go index 0b5f1323e6..f232aa77e9 100644 --- a/logging/telemetryConfig.go +++ b/logging/telemetryConfig.go @@ -32,10 +32,6 @@ import ( var loggingFilename = "logging.config" -// these credentials have the minimum privilege set required to write to elasticsearch -var userName = "telemetry-v9" -var password = "oq%$FA1TOJ!yYeMEcJ7D688eEOE#MGCu" - func elasticsearchEndpoint() string { return "https://1ae9f9654b25441090fe5c48c833b95a.us-east-1.aws.found.io:9243" } @@ -70,6 +66,8 @@ func createTelemetryConfig() TelemetryConfig { MinLogLevel: logrus.WarnLevel, ReportHistoryLevel: logrus.WarnLevel, LogHistoryDepth: 100, + UserName: "telemetry-v9", + Password: "oq%$FA1TOJ!yYeMEcJ7D688eEOE#MGCu", } } diff --git a/logging/telemetryConfig_test.go b/logging/telemetryConfig_test.go new file mode 100644 index 0000000000..24da62fb1b --- /dev/null +++ b/logging/telemetryConfig_test.go @@ -0,0 +1,92 @@ +// Copyright (C) 2019 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package logging + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_loadTelemetryConfig(t *testing.T) { + + sample := TelemetryConfig{ + Enable: true, + GUID: "guid", + URI: "elastic.algorand.com", + MinLogLevel: 4, + ReportHistoryLevel: 4, + LogHistoryDepth: 100, + UserName: "telemetry-v9", + Password: "oq%$FA1TOJ!yYeMEcJ7D688eEOE#MGCu", + } + + a := require.New(t) + ourPath, err := os.Getwd() + a.NoError(err) + configsPath := filepath.Join(ourPath, "../test/testdata/configs/logging/logging.config.example") + + config, err := loadTelemetryConfig(configsPath) + a.NoError(err) + + a.Equal(sample.Enable, config.Enable) + a.Equal(sample.GUID, config.GUID) + a.Equal(sample.URI, config.URI) + a.Equal(sample.MinLogLevel, config.MinLogLevel) + a.Equal(sample.ReportHistoryLevel, config.ReportHistoryLevel) + a.Equal(sample.UserName, config.UserName) + a.Equal(sample.Password, config.Password) + +} + +func Test_CreateSaveLoadTelemetryConfig(t *testing.T) { + + testDir := os.Getenv("TESTDIR") + + if testDir == "" { + testDir, _ = ioutil.TempDir("", "tmp") + } + + a := require.New(t) + + configsPath := filepath.Join(testDir, "logging.config") + config1 := createTelemetryConfig() + + err := config1.Save(configsPath) + a.NoError(err) + + config2, err := loadTelemetryConfig(configsPath) + a.NoError(err) + + a.Equal(config1.Enable, config2.Enable) + a.Equal(config1.URI, config2.URI) + a.Equal(config1.Name, config2.Name) + a.Equal(config1.GUID, config2.GUID) + a.Equal(config1.MinLogLevel, config2.MinLogLevel) + a.Equal(config1.ReportHistoryLevel, config2.ReportHistoryLevel) + a.Equal(config1.LogHistoryDepth, config2.LogHistoryDepth) + a.Equal(config1.FilePath, "") + a.Equal(configsPath, config2.FilePath) + a.Equal(config1.ChainID, config2.ChainID) + a.Equal(config1.SessionGUID, config2.SessionGUID) + a.Equal(config1.UserName, config2.UserName) + a.Equal(config1.Password, config2.Password) + +} diff --git a/logging/telemetryhook.go b/logging/telemetryhook.go index 4e2ef3974b..017835cdec 100644 --- a/logging/telemetryhook.go +++ b/logging/telemetryhook.go @@ -123,7 +123,7 @@ func (hook *asyncTelemetryHook) Flush() { func createElasticHook(cfg TelemetryConfig) (hook logrus.Hook, err error) { client, err := elastic.NewClient(elastic.SetURL(cfg.URI), - elastic.SetBasicAuth(userName, password), + elastic.SetBasicAuth(cfg.UserName, cfg.Password), elastic.SetSniff(false), elastic.SetGzip(true)) if err != nil { diff --git a/test/testdata/configs/logging/logging.config.example b/test/testdata/configs/logging/logging.config.example new file mode 100644 index 0000000000..ba5642e8c0 --- /dev/null +++ b/test/testdata/configs/logging/logging.config.example @@ -0,0 +1,10 @@ +{ + "Enable": true, + "GUID": "guid", + "URI": "elastic.algorand.com", + "MinLogLevel": 4, + "ReportHistoryLevel": 4, + "LogHistoryDepth": 100, + "UserName": "telemetry-v9", + "Password": "oq%$FA1TOJ!yYeMEcJ7D688eEOE#MGCu" +}