Browse Source

test travis

Jordan Schalm 8 years ago
parent
commit
b90508ab95

+ 5 - 1
.travis.yml

@@ -11,6 +11,10 @@ install:
   - go get github.com/Masterminds/glide
   - go get github.com/Masterminds/glide
   - go install github.com/Masterminds/glide
   - go install github.com/Masterminds/glide
   - glide up
   - glide up
+  - go get github.com/rakyll/statik
+  - go install github.com/rakyll/statik
+  - cd dashboard/js && npm install && npm run build && cd ../..
+  - statik -src=dashboard/js/build -dest=dashboard
 
 
 script:
 script:
   - ./.travis.gofmt.sh
   - ./.travis.gofmt.sh
@@ -18,4 +22,4 @@ script:
   - go test ./tests
   - go test ./tests
   - go test
   - go test
   - go test ./cmd/guerrillad
   - go test ./cmd/guerrillad
-  - go test ./response
+  - go test ./response

+ 3 - 38
dashboard/dashboard.go

@@ -1,7 +1,6 @@
 package dashboard
 package dashboard
 
 
 import (
 import (
-	"html/template"
 	"math/rand"
 	"math/rand"
 	"net/http"
 	"net/http"
 	"time"
 	"time"
@@ -13,17 +12,12 @@ import (
 	"github.com/rakyll/statik/fs"
 	"github.com/rakyll/statik/fs"
 )
 )
 
 
-const (
-	dashboard      = "index.html"
-	dashboardPath  = "dashboard/html/index.html"
-	sessionTimeout = time.Hour * 24 // TODO replace with config
-)
+const sessionTimeout = time.Hour * 24 // TODO replace with config
 
 
 var (
 var (
 	// Cache of HTML templates
 	// Cache of HTML templates
-	templates = template.Must(template.ParseFiles(dashboardPath))
-	config    *Config
-	sessions  map[string]*session
+	config   *Config
+	sessions map[string]*session
 )
 )
 
 
 var upgrader = websocket.Upgrader{
 var upgrader = websocket.Upgrader{
@@ -39,7 +33,6 @@ type Config struct {
 
 
 // Begin collecting data and listening for dashboard clients
 // Begin collecting data and listening for dashboard clients
 func Run(c *Config) {
 func Run(c *Config) {
-	log.Info("Dashboard run")
 	statikFS, _ := fs.New()
 	statikFS, _ := fs.New()
 	config = c
 	config = c
 	sessions = map[string]*session{}
 	sessions = map[string]*session{}
@@ -54,19 +47,7 @@ func Run(c *Config) {
 	log.WithError(err).Error("Dashboard server failed to start")
 	log.WithError(err).Error("Dashboard server failed to start")
 }
 }
 
 
-func indexHandler(w http.ResponseWriter, r *http.Request) {
-	c, err := r.Cookie("SID")
-	_, sidExists := sessions[c.Value]
-	if err != nil || !sidExists {
-		// No SID cookie
-		startSession(w, r)
-	}
-	w.WriteHeader(http.StatusOK)
-	templates.ExecuteTemplate(w, dashboard, nil)
-}
-
 func webSocketHandler(w http.ResponseWriter, r *http.Request) {
 func webSocketHandler(w http.ResponseWriter, r *http.Request) {
-	log.Info("websocket handler")
 	cookie, err := r.Cookie("SID")
 	cookie, err := r.Cookie("SID")
 	if err != nil {
 	if err != nil {
 		// TODO error
 		// TODO error
@@ -112,19 +93,3 @@ func startSession(w http.ResponseWriter, r *http.Request) *session {
 	sessions[sessionID] = sess
 	sessions[sessionID] = sess
 	return sess
 	return sess
 }
 }
-
-// TODO unused
-func getSession(r *http.Request) *session {
-	c, err := r.Cookie("SID")
-	if err != nil {
-		return nil
-	}
-
-	sid := c.Value
-	sess, ok := sessions[sid]
-	if !ok {
-		return nil
-	}
-
-	return sess
-}

+ 6 - 2
dashboard/datastore.go

@@ -171,7 +171,11 @@ func dataListener(interval time.Duration) {
 		runtime.ReadMemStats(memStats)
 		runtime.ReadMemStats(memStats)
 		ramPoint := point{t, memStats.Alloc}
 		ramPoint := point{t, memStats.Alloc}
 		nClientPoint := point{t, store.nClients}
 		nClientPoint := point{t, store.nClients}
-		log.Info("datastore:89", ramPoint, nClientPoint)
+		log.WithFields(map[string]interface{}{
+			"ram":     ramPoint.Y,
+			"clients": nClientPoint.Y,
+		}).Info("Logging analytics data")
+
 		store.addRAMPoint(ramPoint)
 		store.addRAMPoint(ramPoint)
 		store.addNClientPoint(nClientPoint)
 		store.addNClientPoint(nClientPoint)
 		store.notify(&message{tickMessageType, dataFrame{
 		store.notify(&message{tickMessageType, dataFrame{
@@ -235,7 +239,7 @@ func (h logHook) Fire(e *log.Entry) error {
 			return nil
 			return nil
 		}
 		}
 	}
 	}
-	log.Info("event ", event)
+
 	switch event {
 	switch event {
 	case "connect":
 	case "connect":
 		store.lock.Lock()
 		store.lock.Lock()

+ 0 - 42
dashboard/html/index.html

@@ -1,42 +0,0 @@
-<!DOCTYPE html>
-<html>
-	<head>
-		<title>Guerrilla | Dashboard</title>
-	</head>
-	<body>
-		<canvas id="ram-graph" width="500" height="200"></canvas>
-	</body>
-	<!--script src="https://cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.min.js"></script-->
-	<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
-	<!--script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script-->
-
-	<!-- imports global MG variable -->
-	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
-	<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.1.1/d3.min.js"></script>
-	<script src="https://cdnjs.cloudflare.com/ajax/libs/metrics-graphics/2.11.0/metricsgraphics.js"></script>
-	<script>
-
-
-	var data = [1,2,3,4,5,6,7,8,9,10].map(n => ({date: moment().add(n, 'days').format('YYYY-MM-DD'), value: n}));
-	console.log(data);
-	MG.data_graphic({
-		title: "Line Chart",
-		description: "This is a simple line chart. You can remove the area portion by adding area: false to the arguments list.",
-		data: data,
-		width: 600,
-		height: 200,
-		right: 40,
-		target: document.getElementById('ram-graph'),
-		x_accessor: 'date',
-		y_accessor: 'value'
-	});
-
-	// var smoothie = new SmoothieChart();
-	// var ram = new TimeSeries();
-	//
-	// smoothie.addTimeSeries(ram);
-	// smoothie.streamTo(document.getElementById('ram-graph'), 1000);
-
-
-	</script>
-</html>

+ 0 - 13
dashboard/html/login.html

@@ -1,13 +0,0 @@
-<!DOCTYPE html>
-<html>
-	<head>
-		<title>Guerrilla | Login</title>
-	</head>
-	<body>
-		<form action="/login" method="POST">
-			<input type="text" name="username" required>Username</input>
-			<input type="password" name="password" required>Password</input>
-			<input type="submit" value="Submit" />
-		</form>
-	</body>
-</html>

+ 1 - 1
dashboard/js/src/components/App.js

@@ -32,7 +32,7 @@ const RANKING_SIZE = 5;
 const _computeRanking = mapping => {
 const _computeRanking = mapping => {
 	return Object.keys(mapping)
 	return Object.keys(mapping)
 		.map(k => ({value: k, count: mapping[k]}))
 		.map(k => ({value: k, count: mapping[k]}))
-		.sort((a, b) => a.count - b.count)
+		.sort((a, b) => b.count - a.count)
 		.slice(0, RANKING_SIZE);
 		.slice(0, RANKING_SIZE);
 }
 }
 
 

+ 2 - 2
mocks/client.go

@@ -12,8 +12,8 @@ const (
 )
 )
 
 
 var (
 var (
-	helos = []string{"hi", "hello", "ahoy", "bonjour"}
-	froms = []string{"joe@gmail.com", "[email protected]", "[email protected]", "sally@gmail.com"}
+	helos = []string{"hi", "hello", "ahoy", "bonjour", "hey!"}
+	froms = []string{"joe@yahoo.com", "[email protected]", "[email protected]", "[email protected]", "alex@outlook.com"}
 )
 )
 
 
 func lastWords(message string, err error) {
 func lastWords(message string, err error) {