Browse Source

Fix dashboard target in Makefile
Lock ranking buffers while aggregating

Jordan Schalm 8 năm trước cách đây
mục cha
commit
ebf74b820e
2 tập tin đã thay đổi với 6 bổ sung4 xóa
  1. 2 2
      Makefile
  2. 4 2
      dashboard/datastore.go

+ 2 - 2
Makefile

@@ -24,7 +24,7 @@ dependencies:
 	$(GO_VARS) $(GO) list -f='{{ join .Deps "\n" }}' $(ROOT)/cmd/guerrillad | grep -v $(ROOT) | tr '\n' ' ' | $(GO_VARS) xargs $(GO) install -v
 	cd dashboard/js && npm install && cd ../..
 
-dashboard: dashboard/*
+dashboard: dashboard/*.go */*/*/*.js */*/*/*/*.js
 	cd dashboard/js && npm run build && cd ../..
 	statik -src=dashboard/js/build -dest=dashboard
 
@@ -44,4 +44,4 @@ testrace: *.go */*.go */*/*.go
 	$(GO_VARS) $(GO) test -v ./tests -race
 	$(GO_VARS) $(GO) test -v ./cmd/guerrillad -race
 	$(GO_VARS) $(GO) test -v ./response -race
-	$(GO_VARS) $(GO) test -v ./backends -race
+	$(GO_VARS) $(GO) test -v ./backends -race

+ 4 - 2
dashboard/datastore.go

@@ -121,7 +121,6 @@ func (ds *dataStore) rankingManager() {
 		case <-stopRankingManager:
 			return
 		}
-
 	}
 }
 
@@ -132,7 +131,9 @@ func (ds *dataStore) aggregateRankings() ranking {
 	topHelo := make(map[string]int, len(ds.topHelo[0]))
 	topIP := make(map[string]int, len(ds.topIP[0]))
 
-	for i := 0; i < nRankingBuffers; i++ {
+	ds.lock.Lock()
+	// Aggregate buffers
+	for i := 1; i < nRankingBuffers; i++ {
 		for domain, count := range ds.topDomain[i] {
 			topDomain[domain] += count
 		}
@@ -143,6 +144,7 @@ func (ds *dataStore) aggregateRankings() ranking {
 			topIP[ip] += count
 		}
 	}
+	ds.lock.Unlock()
 
 	return ranking{
 		TopDomain: topDomain,