Skip to content

Commit

Permalink
Convert configuration options to correct data types
Browse files Browse the repository at this point in the history
  • Loading branch information
beevee committed Dec 13, 2017
1 parent 3eb214b commit f5c83fa
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 92 deletions.
2 changes: 1 addition & 1 deletion checker/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (triggerChecker *TriggerChecker) getTimeSeriesState(triggerTimeSeries *trig

func (triggerChecker *TriggerChecker) cleanupMetricsValues(metrics []string, until int64) {
if len(metrics) > 0 {
if err := triggerChecker.Database.RemoveMetricsValues(metrics, until-triggerChecker.Config.MetricsTTL); err != nil {
if err := triggerChecker.Database.RemoveMetricsValues(metrics, until-triggerChecker.Config.MetricsTTLSeconds); err != nil {
triggerChecker.Logger.Error(err.Error())
}
}
Expand Down
14 changes: 7 additions & 7 deletions checker/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func TestCheckErrors(t *testing.T) {
Database: dataBase,
Logger: logger,
Config: &Config{
MetricsTTL: 10,
MetricsTTLSeconds: 10,
},
Metrics: metrics.ConfigureCheckerMetrics("checker"),
From: 17,
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestHandleTrigger(t *testing.T) {
Database: dataBase,
Logger: logger,
Config: &Config{
MetricsTTL: 3600,
MetricsTTLSeconds: 3600,
},
From: 3617,
Until: 3667,
Expand All @@ -493,7 +493,7 @@ func TestHandleTrigger(t *testing.T) {
dataBase.EXPECT().GetMetricsValues([]string{metric}, triggerChecker.From, triggerChecker.Until).Return(dataList, nil)
var val float64
var val1 float64 = 4
dataBase.EXPECT().RemoveMetricsValues([]string{metric}, triggerChecker.Until-triggerChecker.Config.MetricsTTL)
dataBase.EXPECT().RemoveMetricsValues([]string{metric}, triggerChecker.Until-triggerChecker.Config.MetricsTTLSeconds)
dataBase.EXPECT().PushNotificationEvent(&moira.NotificationEvent{
TriggerID: triggerChecker.TriggerID,
Timestamp: 3617,
Expand Down Expand Up @@ -538,7 +538,7 @@ func TestHandleTrigger(t *testing.T) {
dataBase.EXPECT().GetPatternMetrics(pattern).Return([]string{metric}, nil)
dataBase.EXPECT().GetMetricRetention(metric).Return(retention, nil)
dataBase.EXPECT().GetMetricsValues([]string{metric}, triggerChecker.From, triggerChecker.Until).Return(dataList, nil)
dataBase.EXPECT().RemoveMetricsValues([]string{metric}, triggerChecker.Until-triggerChecker.Config.MetricsTTL)
dataBase.EXPECT().RemoveMetricsValues([]string{metric}, triggerChecker.Until-triggerChecker.Config.MetricsTTLSeconds)
checkData, err := triggerChecker.handleTrigger()
So(err, ShouldBeNil)
var val1 float64 = 4
Expand All @@ -565,7 +565,7 @@ func TestHandleTrigger(t *testing.T) {
dataBase.EXPECT().GetPatternMetrics(pattern).Return([]string{metric}, nil)
dataBase.EXPECT().GetMetricRetention(metric).Return(retention, nil)
dataBase.EXPECT().GetMetricsValues([]string{metric}, triggerChecker.From, triggerChecker.Until).Return(dataList, nil)
dataBase.EXPECT().RemoveMetricsValues([]string{metric}, triggerChecker.Until-triggerChecker.Config.MetricsTTL)
dataBase.EXPECT().RemoveMetricsValues([]string{metric}, triggerChecker.Until-triggerChecker.Config.MetricsTTLSeconds)
dataBase.EXPECT().PushNotificationEvent(&moira.NotificationEvent{
TriggerID: triggerChecker.TriggerID,
Timestamp: lastCheck.Timestamp - triggerChecker.ttl,
Expand Down Expand Up @@ -621,7 +621,7 @@ func TestHandleTrigger(t *testing.T) {
Database: dataBase,
Logger: logger,
Config: &Config{
MetricsTTL: 3600,
MetricsTTLSeconds: 3600,
},
From: 3617,
Until: 3667,
Expand Down Expand Up @@ -675,7 +675,7 @@ func TestHandleTrigger(t *testing.T) {
dataBase.EXPECT().GetPatternMetrics(pattern).Return([]string{metric}, nil)
dataBase.EXPECT().GetMetricRetention(metric).Return(retention, nil)
dataBase.EXPECT().GetMetricsValues([]string{metric}, triggerChecker.From, triggerChecker.Until).Return(dataList, nil)
dataBase.EXPECT().RemoveMetricsValues([]string{metric}, triggerChecker.Until-triggerChecker.Config.MetricsTTL)
dataBase.EXPECT().RemoveMetricsValues([]string{metric}, triggerChecker.Until-triggerChecker.Config.MetricsTTLSeconds)
dataBase.EXPECT().RemovePatternsMetrics(triggerChecker.trigger.Patterns).Return(nil)
checkData, err := triggerChecker.handleTrigger()
So(err, ShouldBeNil)
Expand Down
16 changes: 8 additions & 8 deletions checker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import "time"

// Config represent checker config
type Config struct {
Enabled bool
NoDataCheckInterval time.Duration
CheckInterval time.Duration
MetricsTTL int64
StopCheckingInterval int64
MaxParallelChecks int
LogFile string
LogLevel string
Enabled bool
NoDataCheckInterval time.Duration
CheckInterval time.Duration
MetricsTTLSeconds int64
StopCheckingIntervalSeconds int64
MaxParallelChecks int
LogFile string
LogLevel string
}
2 changes: 1 addition & 1 deletion checker/worker/nodata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (worker *Checker) noDataChecker() error {

func (worker *Checker) checkNoData() error {
now := time.Now().UTC().Unix()
if worker.lastData+worker.Config.StopCheckingInterval < now {
if worker.lastData+worker.Config.StopCheckingIntervalSeconds < now {
worker.Logger.Infof("Checking NoData disabled. No metrics for %v seconds", now-worker.lastData)
} else {
worker.Logger.Info("Checking NoData")
Expand Down
6 changes: 3 additions & 3 deletions cmd/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ type config struct {

type apiConfig struct {
Listen string `yaml:"listen"`
EnableCORS string `yaml:"enable_cors"`
EnableCORS bool `yaml:"enable_cors"`
WebConfigPath string `yaml:"web_config_path"`
}

func (config *apiConfig) getSettings() *api.Config {
return &api.Config{
Listen: config.Listen,
EnableCORS: cmd.ToBool(config.EnableCORS),
EnableCORS: config.EnableCORS,
}
}

Expand All @@ -38,7 +38,7 @@ func getDefault() config {
API: apiConfig{
Listen: ":8081",
WebConfigPath: "/etc/moira/web.json",
EnableCORS: "true",
EnableCORS: false,
},
Pprof: cmd.ProfilerConfig{
Listen: "",
Expand Down
24 changes: 12 additions & 12 deletions cmd/checker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type config struct {
type checkerConfig struct {
NoDataCheckInterval string `yaml:"nodata_check_interval"`
CheckInterval string `yaml:"check_interval"`
MetricsTTL int64 `yaml:"metrics_ttl"`
StopCheckingInterval int64 `yaml:"stop_checking_interval"`
MetricsTTL string `yaml:"metrics_ttl"`
StopCheckingInterval string `yaml:"stop_checking_interval"`
MaxParallelChecks int `yaml:"max_parallel_checks"`
}

Expand All @@ -29,11 +29,11 @@ func (config *checkerConfig) getSettings() *checker.Config {
config.MaxParallelChecks = runtime.NumCPU()
}
return &checker.Config{
MetricsTTL: config.MetricsTTL,
CheckInterval: to.Duration(config.CheckInterval),
NoDataCheckInterval: to.Duration(config.NoDataCheckInterval),
StopCheckingInterval: config.StopCheckingInterval,
MaxParallelChecks: config.MaxParallelChecks,
MetricsTTLSeconds: int64(to.Duration(config.MetricsTTL).Seconds()),
CheckInterval: to.Duration(config.CheckInterval),
NoDataCheckInterval: to.Duration(config.NoDataCheckInterval),
StopCheckingIntervalSeconds: int64(to.Duration(config.StopCheckingInterval).Seconds()),
MaxParallelChecks: config.MaxParallelChecks,
}
}

Expand All @@ -48,16 +48,16 @@ func getDefault() config {
LogLevel: "debug",
},
Checker: checkerConfig{
NoDataCheckInterval: "60s0ms",
CheckInterval: "5s0ms",
MetricsTTL: 3600,
StopCheckingInterval: 30,
NoDataCheckInterval: "60s",
CheckInterval: "5s",
MetricsTTL: "1h",
StopCheckingInterval: "30s",
MaxParallelChecks: 0,
},
Graphite: cmd.GraphiteConfig{
URI: "localhost:2003",
Prefix: "DevOps.Moira",
Interval: "60s0ms",
Interval: "60s",
},
Pprof: cmd.ProfilerConfig{
Listen: "",
Expand Down
14 changes: 2 additions & 12 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"io/ioutil"
"strings"

"gopkg.in/yaml.v2"
"menteslibres.net/gosexy/to"
Expand All @@ -30,7 +29,7 @@ func (config *RedisConfig) GetSettings() redis.Config {

// GraphiteConfig is graphite metrics config, which are taken on the start of moira
type GraphiteConfig struct {
Enabled string `yaml:"enabled"`
Enabled bool `yaml:"enabled"`
URI string `yaml:"uri"`
Prefix string `yaml:"prefix"`
Interval string `yaml:"interval"`
Expand All @@ -39,7 +38,7 @@ type GraphiteConfig struct {
// GetSettings return graphite metrics config parsed from moira config files
func (graphiteConfig *GraphiteConfig) GetSettings() graphite.Config {
return graphite.Config{
Enabled: ToBool(graphiteConfig.Enabled),
Enabled: graphiteConfig.Enabled,
URI: graphiteConfig.URI,
Prefix: graphiteConfig.Prefix,
Interval: to.Duration(graphiteConfig.Interval),
Expand Down Expand Up @@ -75,12 +74,3 @@ func PrintConfig(config interface{}) {
d, _ := yaml.Marshal(&config)
fmt.Println(string(d))
}

// ToBool is simple func witch parse popular bool interpretation to golang bool value
func ToBool(str string) bool {
switch strings.ToLower(str) {
case "1", "true", "t", "yes", "y":
return true
}
return false
}
2 changes: 1 addition & 1 deletion cmd/filter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func getDefault() config {
Graphite: cmd.GraphiteConfig{
URI: "localhost:2003",
Prefix: "DevOps.Moira",
Interval: "60s0ms",
Interval: "60s",
},
Pprof: cmd.ProfilerConfig{
Listen: "",
Expand Down
38 changes: 19 additions & 19 deletions cmd/notifier/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ type notifierConfig struct {
}

type selfStateConfig struct {
Enabled string `yaml:"enabled"`
RedisDisconnectDelay int64 `yaml:"redis_disconect_delay"`
LastMetricReceivedDelay int64 `yaml:"last_metric_received_delay"`
LastCheckDelay int64 `yaml:"last_check_delay"`
Enabled bool `yaml:"enabled"`
RedisDisconnectDelay string `yaml:"redis_disconect_delay"`
LastMetricReceivedDelay string `yaml:"last_metric_received_delay"`
LastCheckDelay string `yaml:"last_check_delay"`
Contacts []map[string]string `yaml:"contacts"`
NoticeInterval int64 `yaml:"notice_interval"`
NoticeInterval string `yaml:"notice_interval"`
}

func getDefault() config {
Expand All @@ -47,23 +47,23 @@ func getDefault() config {
Graphite: cmd.GraphiteConfig{
URI: "localhost:2003",
Prefix: "DevOps.Moira",
Interval: "60s0ms",
Interval: "60s",
},
Logger: cmd.LoggerConfig{
LogFile: "stdout",
LogLevel: "debug",
},
Notifier: notifierConfig{
SenderTimeout: "10s0ms",
SenderTimeout: "10s",
ResendingTimeout: "24:00",
SelfState: selfStateConfig{
Enabled: "false",
RedisDisconnectDelay: 30,
LastMetricReceivedDelay: 60,
LastCheckDelay: 60,
NoticeInterval: 300,
Enabled: false,
RedisDisconnectDelay: "30s",
LastMetricReceivedDelay: "60s",
LastCheckDelay: "60s",
NoticeInterval: "300s",
},
FrontURI: "http:// localhost",
FrontURI: "http://localhost",
Timezone: "UTC",
},
Pprof: cmd.ProfilerConfig{
Expand Down Expand Up @@ -92,11 +92,11 @@ func (config *notifierConfig) getSettings(logger moira.Logger) notifier.Config {

func (config *selfStateConfig) getSettings() selfstate.Config {
return selfstate.Config{
Enabled: cmd.ToBool(config.Enabled),
RedisDisconnectDelay: config.RedisDisconnectDelay,
LastMetricReceivedDelay: config.LastMetricReceivedDelay,
LastCheckDelay: config.LastCheckDelay,
Contacts: config.Contacts,
NoticeInterval: config.NoticeInterval,
Enabled: config.Enabled,
RedisDisconnectDelaySeconds: int64(to.Duration(config.RedisDisconnectDelay).Seconds()),
LastMetricReceivedDelaySeconds: int64(to.Duration(config.LastMetricReceivedDelay).Seconds()),
LastCheckDelaySeconds: int64(to.Duration(config.LastCheckDelay).Seconds()),
Contacts: config.Contacts,
NoticeIntervalSeconds: int64(to.Duration(config.NoticeInterval).Seconds()),
}
}
12 changes: 6 additions & 6 deletions notifier/selfstate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

// Config is representation of self state worker settings like moira admins contacts and threshold values for checked services
type Config struct {
Enabled bool
RedisDisconnectDelay int64
LastMetricReceivedDelay int64
LastCheckDelay int64
Contacts []map[string]string
NoticeInterval int64
Enabled bool
RedisDisconnectDelaySeconds int64
LastMetricReceivedDelaySeconds int64
LastCheckDelaySeconds int64
Contacts []map[string]string
NoticeIntervalSeconds int64
}

func (config *Config) checkConfig(senders map[string]bool) error {
Expand Down
18 changes: 9 additions & 9 deletions notifier/selfstate/selfstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,25 @@ func (selfCheck *SelfCheckWorker) check(nowTS int64, lastMetricReceivedTS, redis
}
}
if *nextSendErrorMessage < nowTS {
if *redisLastCheckTS < nowTS-selfCheck.Config.RedisDisconnectDelay {
if *redisLastCheckTS < nowTS-selfCheck.Config.RedisDisconnectDelaySeconds {
interval := nowTS - *redisLastCheckTS
selfCheck.Log.Errorf("Redis disconnected more %ds. Send message.", interval)
selfCheck.sendErrorMessages("Redis disconnected", interval, selfCheck.Config.RedisDisconnectDelay)
*nextSendErrorMessage = nowTS + selfCheck.Config.NoticeInterval
selfCheck.sendErrorMessages("Redis disconnected", interval, selfCheck.Config.RedisDisconnectDelaySeconds)
*nextSendErrorMessage = nowTS + selfCheck.Config.NoticeIntervalSeconds
return
}
if *lastMetricReceivedTS < nowTS-selfCheck.Config.LastMetricReceivedDelay && err == nil {
if *lastMetricReceivedTS < nowTS-selfCheck.Config.LastMetricReceivedDelaySeconds && err == nil {
interval := nowTS - *lastMetricReceivedTS
selfCheck.Log.Errorf("Moira-Filter does not received new metrics more %ds. Send message.", interval)
selfCheck.sendErrorMessages("Moira-Filter does not received new metrics", interval, selfCheck.Config.LastMetricReceivedDelay)
*nextSendErrorMessage = nowTS + selfCheck.Config.NoticeInterval
selfCheck.sendErrorMessages("Moira-Filter does not received new metrics", interval, selfCheck.Config.LastMetricReceivedDelaySeconds)
*nextSendErrorMessage = nowTS + selfCheck.Config.NoticeIntervalSeconds
return
}
if *lastCheckTS < nowTS-selfCheck.Config.LastCheckDelay && err == nil {
if *lastCheckTS < nowTS-selfCheck.Config.LastCheckDelaySeconds && err == nil {
interval := nowTS - *lastCheckTS
selfCheck.Log.Errorf("Moira-Checker does not checks triggers more %ds. Send message.", interval)
selfCheck.sendErrorMessages("Moira-Checker does not checks triggers", interval, selfCheck.Config.LastCheckDelay)
*nextSendErrorMessage = nowTS + selfCheck.Config.NoticeInterval
selfCheck.sendErrorMessages("Moira-Checker does not checks triggers", interval, selfCheck.Config.LastCheckDelaySeconds)
*nextSendErrorMessage = nowTS + selfCheck.Config.NoticeIntervalSeconds
}
}
}
Expand Down
Loading

0 comments on commit f5c83fa

Please sign in to comment.