Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions logging/telemetryCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions logging/telemetryConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -70,6 +66,8 @@ func createTelemetryConfig() TelemetryConfig {
MinLogLevel: logrus.WarnLevel,
ReportHistoryLevel: logrus.WarnLevel,
LogHistoryDepth: 100,
UserName: "telemetry-v9",
Password: "oq%$FA1TOJ!yYeMEcJ7D688eEOE#MGCu",
}
}

Expand Down
92 changes: 92 additions & 0 deletions logging/telemetryConfig_test.go
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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)

}
2 changes: 1 addition & 1 deletion logging/telemetryhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions test/testdata/configs/logging/logging.config.example
Original file line number Diff line number Diff line change
@@ -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"
}