Skip to content

Commit

Permalink
cmd/bosun: skiplast cmdline switch for development (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebrandt committed May 6, 2016
1 parent 2a899e7 commit c5de652
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/bosun/conf/conf.go
Expand Up @@ -63,6 +63,7 @@ type Conf struct {
Lookups map[string]*Lookup
Squelch Squelches `json:"-"`
Quiet bool
SkipLast bool
NoSleep bool
ShortURLKey string
InternetProxy string
Expand Down
4 changes: 4 additions & 0 deletions cmd/bosun/main.go
Expand Up @@ -68,6 +68,7 @@ var (
flagQuiet = flag.Bool("q", false, "quiet-mode: don't send any notifications except from the rule test page")
flagNoChecks = flag.Bool("n", false, "no-checks: don't run the checks at the run interval")
flagDev = flag.Bool("dev", false, "enable dev mode: use local resources; no syslog")
flagSkipLast = flag.Bool("skiplast", false, "skip loading last datapoints from and to redis: useful for speeding up bosun startup time during development")
flagVersion = flag.Bool("version", false, "Prints the version and exits")

mains []func()
Expand Down Expand Up @@ -100,6 +101,9 @@ func main() {
if err := metadata.Init(httpListen, false); err != nil {
slog.Fatal(err)
}
if *flagSkipLast {
c.SkipLast = true
}
if err := sched.Load(c); err != nil {
slog.Fatal(err)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/bosun/sched/sched.go
Expand Up @@ -87,7 +87,7 @@ func (s *Schedule) Init(c *conf.Conf) error {
}
}
if s.Search == nil {
s.Search = search.NewSearch(s.DataAccess)
s.Search = search.NewSearch(s.DataAccess, c.SkipLast)
}
if c.StateFile != "" {
s.db, err = bolt.Open(c.StateFile, 0600, nil)
Expand Down Expand Up @@ -511,6 +511,9 @@ func Close() {
}

func (s *Schedule) Close() {
if s.Conf.SkipLast {
return
}
err := s.Search.BackupLast()
if err != nil {
slog.Error(err)
Expand Down
10 changes: 6 additions & 4 deletions cmd/bosun/search/search.go
Expand Up @@ -36,16 +36,18 @@ func init() {
metadata.AddMetricMeta("bosun.search.dropped", metadata.Counter, metadata.Count, "Number of datapoints discarded without being saved to redis")
}

func NewSearch(data database.DataAccess) *Search {
func NewSearch(data database.DataAccess, skipLast bool) *Search {
s := Search{
DataAccess: data,
last: make(map[string]map[string]*database.LastInfo),
indexQueue: make(chan *opentsdb.DataPoint, 300000),
}
collect.Set("search.index_queue", opentsdb.TagSet{}, func() interface{} { return len(s.indexQueue) })
s.loadLast()
go s.redisIndex(s.indexQueue)
go s.backupLoop()
if !skipLast {
s.loadLast()
go s.redisIndex(s.indexQueue)
go s.backupLoop()
}
return &s
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/bosun/search/search_test.go
Expand Up @@ -14,7 +14,7 @@ var testSearch *Search

func TestMain(m *testing.M) {
testData, closeF := dbtest.StartTestRedis(9990)
testSearch = NewSearch(testData)
testSearch = NewSearch(testData, false)
status := m.Run()
closeF()
os.Exit(status)
Expand Down

0 comments on commit c5de652

Please sign in to comment.