Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/monitor peers flag #7672

Merged
merged 16 commits into from
Aug 4, 2023
Prev Previous commit
Next Next commit
Fixing default value setting
  • Loading branch information
Tyler Morgan committed Aug 2, 2023
commit e415386e8d48e7ae97e9d18722c4ea81669a5fa8
4 changes: 4 additions & 0 deletions tc-health-client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ const DefaultMarkdownMinIntervalMS = 5000
// Users should create and pass a copy of Cfg if changes on error are not acceptable.
func LoadConfig(cfg *Cfg) (bool, error) {
configFile := cfg.HealthClientConfigFile.Filename
// Load default value for strategies.yaml
cfg.MonitorStrategiesPeers = true
modTime, err := util.GetFileModificationTime(configFile)
if err != nil {
return false, errors.New(err.Error())
Expand All @@ -349,7 +351,9 @@ func LoadConfig(cfg *Cfg) (bool, error) {
if err != nil {
return false, errors.New(err.Error())
}
log.Infof("Value for monitoring strategies peers: %v", cfg.MonitorStrategiesPeers)
err = json.Unmarshal(content, cfg)
log.Infof("Value for monitoring strategies peers after loading json: %v", cfg.MonitorStrategiesPeers)
if err != nil {
return false, fmt.Errorf("config parsing failed: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions tc-health-client/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package config

import (
"os"
"strconv"
"testing"

"github.com/apache/trafficcontrol/tc-health-client/util"
Expand Down Expand Up @@ -112,6 +113,12 @@ func TestLoadConfig(t *testing.T) {
if bindir != expect {
t.Fatalf("expected '%s', got %s\n", expect, bindir)
}

expect = "true"
monitorStrategisPeers := cfg.MonitorStrategiesPeers
if expect != strconv.FormatBool(monitorStrategisPeers) {
t.Fatalf("expected '%s', got %v\n", expect, monitorStrategisPeers)
}
}

func TestGetCredentialsFromFile(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tc-health-client/tmagent/tmagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func TestReadStrategiesDotYaml(t *testing.T) {
cfg := &config.Cfg{
HealthClientConfigFile: cf,
TrafficServerConfigDir: "test_files/etc/",
MonitorStrategiesPeers: true,
}
parents := util.ConfigFile{
Filename: filepath.Join(cfg.TrafficServerConfigDir, ParentsFile),
Expand All @@ -102,6 +101,7 @@ func TestReadStrategiesDotYaml(t *testing.T) {
TrafficServerBinDir: cfg.TrafficServerBinDir,
TrafficServerConfigDir: cfg.TrafficServerConfigDir,
}
t.Logf("Monitoring peers value: %v", cfg.MonitorStrategiesPeers)

if err := pi.readStrategies(cfg.MonitorStrategiesPeers); err != nil {
t.Fatalf("failed readStrategies(): %s\n", err.Error())
Expand Down