diff --git a/authenticator/authenticator.go b/authenticator/authenticator.go index 047468a..7680754 100644 --- a/authenticator/authenticator.go +++ b/authenticator/authenticator.go @@ -29,11 +29,12 @@ var ( // Init initializes the chosen authenticator func Init() error { - var err error - var u *url.URL - u, err = url.Parse(config.AuthAddress) + u, err := url.Parse(config.AuthAddress) if err != nil { - return fmt.Errorf("Failed to parse db connection - %s", err) + u, err = url.Parse("boltdb://" + config.AuthAddress) + if err != nil { + return fmt.Errorf("Failed to parse auth connection - %s", err) + } } switch u.Scheme { case "boltdb": diff --git a/config/config.go b/config/config.go index 6c4fbe1..4961bd8 100644 --- a/config/config.go +++ b/config/config.go @@ -34,6 +34,7 @@ var ( Insecure = false // whether or not to start insecure Server = false // whether or not to start logvac as a server Version = false // whether or not to print version info and exit + CleanFreq = 60 // how often to clean log database ) // AddFlags adds cli flags to logvac @@ -60,6 +61,8 @@ func AddFlags(cmd *cobra.Command) { cmd.Flags().BoolVarP(&Server, "server", "s", Server, "Run as server") cmd.Flags().BoolVarP(&Insecure, "insecure", "i", Insecure, "Don't use TLS (used for testing)") cmd.Flags().BoolVarP(&Version, "version", "v", Version, "Print version info and exit") + cmd.Flags().IntVar(&CleanFreq, "clean-frequency", CleanFreq, "How often to clean log database") + cmd.Flags().MarkHidden("clean-frequency") Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR")) } diff --git a/drain/boltdb.go b/drain/boltdb.go index 640f315..54ba61d 100644 --- a/drain/boltdb.go +++ b/drain/boltdb.go @@ -17,11 +17,6 @@ import ( "github.com/nanopack/logvac/core" ) -var ( - // How often to clean, exported for testing - CleanFreq = 60 -) - type ( // BoltArchive is a boltDB archiver BoltArchive struct { @@ -180,12 +175,16 @@ func (a BoltArchive) Expire() { var logKeep map[string]interface{} err := json.Unmarshal([]byte(config.LogKeep), &logKeep) if err != nil { - config.Log.Fatal("Bad JSON syntax for log-keep - %s", err) - os.Exit(1) // maybe not? + config.Log.Fatal("Bad JSON syntax for log-keep - %s, saving logs indefinitely", err) + return + } + + if config.CleanFreq < 1 { + config.CleanFreq = 60 } // clean up every minute // todo: maybe 5mins? - tick := time.Tick(time.Duration(CleanFreq) * time.Second) + tick := time.Tick(time.Duration(config.CleanFreq) * time.Second) for { select { case <-tick: diff --git a/drain/boltdb_test.go b/drain/boltdb_test.go index 014da19..b41224a 100644 --- a/drain/boltdb_test.go +++ b/drain/boltdb_test.go @@ -111,7 +111,7 @@ func TestExpire(t *testing.T) { // manually configure and start internals func initialize() error { var err error - drain.CleanFreq = 1 + config.CleanFreq = 1 config.LogKeep = `{"app": "1s", "deploy":0}` config.LogKeep = `{"app": "1s", "deploy":0, "a":"1m", "aa":"1h", "b":"1d", "c":"1w", "d":"1y", "e":"1"}` config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR")) diff --git a/drain/drain.go b/drain/drain.go index e6b7390..a5963b6 100644 --- a/drain/drain.go +++ b/drain/drain.go @@ -60,7 +60,10 @@ func Init() error { func archiveInit() error { u, err := url.Parse(config.DbAddress) if err != nil { - return fmt.Errorf("Failed to parse db connection - %s", err) + u, err = url.Parse("boltdb://" + config.DbAddress) + if err != nil { + return fmt.Errorf("Failed to parse db connection - %s", err) + } } switch u.Scheme { case "boltdb": @@ -98,7 +101,10 @@ func archiveInit() error { func publishInit() error { u, err := url.Parse(config.PubAddress) if err != nil { - return fmt.Errorf("Failed to parse publisher connection - %s", err) + u, err = url.Parse("mist://" + config.PubAddress) // hard requirement for scheme in go 1.8 (with ip:port only) + if err != nil { + return fmt.Errorf("Failed to parse publisher connection - %s", err) + } } switch u.Scheme { case "mist": diff --git a/drain/mist_test.go b/drain/mist_test.go index 2f1c434..dad3763 100644 --- a/drain/mist_test.go +++ b/drain/mist_test.go @@ -59,7 +59,7 @@ func TestPublish(t *testing.T) { // manually configure and start internals func mistInitialize() error { var err error - drain.CleanFreq = 1 + config.CleanFreq = 1 config.LogKeep = `{"app": "1s", "deploy":0}` config.LogKeep = `{"app": "1s", "deploy":0, "a":"1m", "aa":"1h", "b":"1d", "c":"1w", "d":"1y", "e":"1"}` config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))