Skip to content

Commit

Permalink
making build status report more granular
Browse files Browse the repository at this point in the history
  • Loading branch information
captncraig committed Jul 2, 2015
1 parent 70b880b commit 32b4e0e
Show file tree
Hide file tree
Showing 30 changed files with 502 additions and 742 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ install:
- export GOPATH=$HOME/gopath #Fix gopath. Original has trailing :
- chmod +x $GOPATH/src/bosun.org/build/validate.sh
- go get golang.org/x/tools/cmd/vet
- go get github.com/captncraig/setStatus
- npm i -g typescript

script: $GOPATH/src/bosun.org/build/validate.sh
26 changes: 26 additions & 0 deletions build/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@
cd $GOPATH/src/bosun.org
DIRS=`find . -maxdepth 1 -type d -iregex './[^._].*'`

O=bosun-monitor
R=bosun
SHA=`git rev-parse ${TRAVIS_COMMIT}^2`
BUILDMSG=""
if [ "$TRAVIS" != '' ]; then
setStatus -o $O -r $R -s pending -c bosun -d="Running validation build in travis" -sha=$SHA
fi

echo -e "\nChecking gofmt -s -w for all folders that don't start with . or _"
GOFMTRESULT=0
GOFMTOUT=$(gofmt -l -s -w $DIRS);
if [ "$GOFMTOUT" != '' ]; then
echo "The following files need 'gofmt -s -w':"
echo "$GOFMTOUT"
GOFMTRESULT=1
BUILDMSG="go fmt -s needed. "
fi

echo -e "\nRunning go vet bosun.org/..."
go vet bosun.org/...
GOVETRESULT=$?
if [ "$GOVETRESULT" != 0 ]; then
BUILDMSG="${BUILDMSG}go vet found problems. "
fi

echo -e "\nGetting esc"
go get -u -v github.com/mjibson/esc
Expand All @@ -26,12 +38,26 @@ GOGENERATEDIFFRESULT=0
if [ "$GOGENERATEDIFF" != '' ]; then
echo "Go generate needs to be run. The following files have changed:"
echo "$GOGENERATEDIFF"
BUILDMSG="${BUILDMSG}go generate needs to run. "
GOGENERATEDIFFRESULT=1
fi

echo -e "\nRunning go test bosun.org/..."
go test bosun.org/...
GOTESTRESULT=$?
if [ "$GOTESTRESULT" != 0 ]; then
BUILDMSG="${BUILDMSG}tests fail."
fi

BUILDSTATUS=failure
if [ "$BUILDMSG" == '' ]; then
BUILDMSG="All checks Passed!"
BUILDSTATUS=success
fi

if [ "$TRAVIS" != '' ]; then
setStatus -o $O -r $R -s=$BUILDSTATUS -c bosun -d="$BUILDMSG" -sha=$SHA
fi

let "RESULT = $GOFMTRESULT | $GOVETRESULT | $GOTESTRESULT | $GOGENERATERESULT | $GOGENERATEDIFFRESULT"
exit $RESULT
4 changes: 2 additions & 2 deletions cmd/bosun/sched/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var savePending bool

func (s *Schedule) Save() {
go func() {
s.Lock("Save")
s.Lock()
defer s.Unlock()
if savePending {
return
Expand Down Expand Up @@ -124,7 +124,7 @@ func (s *Schedule) save() {
func (s *Schedule) RestoreState() error {
log.Println("RestoreState")
start := time.Now()
s.Lock("RestoreState")
s.Lock()
defer s.Unlock()
s.Search.Lock()
defer s.Search.Unlock()
Expand Down
10 changes: 5 additions & 5 deletions cmd/bosun/sched/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func NewStatus(ak expr.AlertKey) *State {
}

func (s *Schedule) GetStatus(ak expr.AlertKey) *State {
s.Lock("GetStatus")
s.Lock()
state := s.status[ak]
s.Unlock()
return state
}

func (s *Schedule) GetOrCreateStatus(ak expr.AlertKey) *State {
s.Lock("GetOrCreateStatus")
s.Lock()
state := s.status[ak]
if state == nil {
state = NewStatus(ak)
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *Schedule) NewRunHistory(start time.Time, cache *cache.Cache) *RunHistor
func (s *Schedule) RunHistory(r *RunHistory) {
checkNotify := false
silenced := s.Silenced()
s.Lock("RunHistory")
s.Lock()
defer s.Unlock()
for ak, event := range r.Events {
state := s.status[ak]
Expand Down Expand Up @@ -345,7 +345,7 @@ func (r *RunHistory) GetUnknownAndUnevaluatedAlertKeys(alert string) (unknown, u
}
}
if !anyFound {
r.schedule.Lock("GetUnknownUneval")
r.schedule.Lock()
for ak, st := range r.schedule.status {
if ak.Name() != alert {
continue
Expand Down Expand Up @@ -386,7 +386,7 @@ func (s *Schedule) findUnknownAlerts(now time.Time) []expr.AlertKey {
if time.Now().Sub(bosunStartupTime) < s.Conf.CheckFrequency {
return keys
}
s.Lock("FindUnknown")
s.Lock()
for ak, st := range s.status {
if st.Forgotten || st.Status() == StError {
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/bosun/sched/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *Schedule) Notify(st *State, n *conf.Notification) {
// duration until the soonest notification triggers.
func (s *Schedule) CheckNotifications() time.Duration {
silenced := s.Silenced()
s.Lock("CheckNotifications")
s.Lock()
defer s.Unlock()
notifications := s.Notifications
s.Notifications = nil
Expand Down
45 changes: 8 additions & 37 deletions cmd/bosun/sched/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ func init() {
}

type Schedule struct {
mutex sync.Mutex
mutexHolder string
mutexAquired time.Time
mutexWaitTime int64
sync.Mutex

Conf *conf.Conf
status States
Expand All @@ -52,31 +49,10 @@ type Schedule struct {
db *bolt.DB
}

func init() {
metadata.AddMetricMeta(
"bosun.schedule.lock_time", metadata.Counter, metadata.MilliSecond,
"Length of time spent waiting for or holding the schedule lock.")
metadata.AddMetricMeta(
"bosun.schedule.lock_count", metadata.Counter, metadata.Count,
"Number of times the given caller acquired the lock.")
}

func (s *Schedule) Lock(method string) {
start := time.Now()
s.mutex.Lock()
s.mutexAquired = time.Now()
s.mutexHolder = method
s.mutexWaitTime = int64(s.mutexAquired.Sub(start) / time.Millisecond) // remember this so we don't have to call put until we leave the critical section.
}

func (s *Schedule) Unlock() {
holder := s.mutexHolder
start := s.mutexAquired
waitTime := s.mutexWaitTime
s.mutex.Unlock()
collect.Add("schedule.lock_time", opentsdb.TagSet{"caller": holder, "op": "wait"}, waitTime)
collect.Add("schedule.lock_time", opentsdb.TagSet{"caller": holder, "op": "hold"}, int64(time.Since(start)/time.Millisecond))
collect.Add("schedule.lock_count", opentsdb.TagSet{"caller": holder}, 1)
func (s *Schedule) TimeLock(t miniprofiler.Timer) {
t.Step("lock", func(t miniprofiler.Timer) {
s.Lock()
})
}

type Metavalue struct {
Expand Down Expand Up @@ -284,16 +260,11 @@ type StateGroups struct {
}

func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGroups, error) {
var silenced map[expr.AlertKey]Silence
T.Step("Silenced", func(miniprofiler.Timer) {
silenced = s.Silenced()
})
silenced := s.Silenced()
t := StateGroups{
TimeAndDate: s.Conf.TimeAndDate,
}
T.Step("lock", func(t miniprofiler.Timer) {
s.Lock("MarshalGroups")
})
s.TimeLock(T)
defer s.Unlock()
status := make(States)
matches, err := makeFilter(filter)
Expand Down Expand Up @@ -584,7 +555,7 @@ func (s *State) Action(user, message string, t ActionType, timestamp time.Time)
}

func (s *Schedule) Action(user, message string, t ActionType, ak expr.AlertKey) error {
s.Lock("Action")
s.Lock()
defer func() {
s.Unlock()
s.Save()
Expand Down
6 changes: 3 additions & 3 deletions cmd/bosun/sched/silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s Silence) ID() string {
func (s *Schedule) Silenced() map[expr.AlertKey]Silence {
aks := make(map[expr.AlertKey]Silence)
now := time.Now()
s.Lock("Silenced")
s.Lock()
for _, si := range s.Silence {
for ak := range s.status {
if si.Silenced(now, ak.Name(), ak.Group()) {
Expand Down Expand Up @@ -108,7 +108,7 @@ func (s *Schedule) AddSilence(start, end time.Time, alert, tagList string, forge
}
si.Tags = tags
}
s.Lock("AddSilence")
s.Lock()
defer s.Unlock()
if confirm {
delete(s.Silence, edit)
Expand All @@ -126,7 +126,7 @@ func (s *Schedule) AddSilence(start, end time.Time, alert, tagList string, forge
}

func (s *Schedule) ClearSilence(id string) error {
s.Lock("ClearSilence")
s.Lock()
delete(s.Silence, id)
s.Unlock()
s.Save()
Expand Down
Loading

0 comments on commit 32b4e0e

Please sign in to comment.