Skip to content

Commit

Permalink
App: Rename package main->app, put main.go in prog/app
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie authored and tomwilkie committed Dec 7, 2015
1 parent cc5bc9f commit d1b18f2
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 117 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ coverage.html
.*.uptodate
scope.tar
scope_ui_build.tar
app/app
app/scope-app
prog/app/app
prog/app/scope-app
prog/probe/probe
prog/probe/scope-probe
docker/scope-app
Expand All @@ -55,3 +55,4 @@ experimental/_integration/_integration
*sublime-workspace
*npm-debug.log
app/static.go
prog/app/static.go
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# If you can use Docker without being root, you can `make SUDO= <target>`
SUDO=sudo -E
DOCKERHUB_USER=weaveworks
APP_EXE=app/scope-app
APP_EXE=prog/app/scope-app
PROBE_EXE=prog/probe/scope-probe
FIXPROBE_EXE=experimental/fixprobe/fixprobe
SCOPE_IMAGE=$(DOCKERHUB_USER)/scope
Expand Down Expand Up @@ -38,7 +38,7 @@ $(SCOPE_EXPORT): $(APP_EXE) $(PROBE_EXE) $(DOCKER_DISTRIB) docker/weave $(RUNSVI

$(RUNSVINIT): vendor/runsvinit/*.go

$(APP_EXE): app/*.go render/*.go report/*.go xfer/*.go common/sanitize/*.go app/static.go
$(APP_EXE): app/*.go render/*.go report/*.go xfer/*.go common/sanitize/*.go prog/app/*.go prog/app/static.go

$(PROBE_EXE): prog/probe/*.go $(shell find probe/ -type f -name *.go) report/*.go xfer/*.go common/sanitize/*.go common/exec/*.go

Expand All @@ -62,9 +62,9 @@ $(RUNSVINIT):
go build -ldflags "-extldflags \"-static\"" -o $@ ./$(@D)
endif

static: app/static.go
static: prog/app/static.go

app/static.go: client/build/app.js
prog/app/static.go: client/build/app.js
esc -o $@ -prefix client/build client/build

ifeq ($(BUILD_IN_CONTAINER),true)
Expand Down
2 changes: 1 addition & 1 deletion app/api_report.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"net/http"
Expand Down
13 changes: 11 additions & 2 deletions app/api_report_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package main
package app_test

import (
"encoding/json"
"net/http/httptest"
"testing"

"github.com/gorilla/mux"

"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/report"
)

func topologyServer() *httptest.Server {
router := mux.NewRouter()
app.RegisterTopologyRoutes(StaticReport{}, router)
return httptest.NewServer(router)
}

func TestAPIReport(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()

is404(t, ts, "/api/report/foobar")
Expand Down
2 changes: 1 addition & 1 deletion app/api_topologies.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"net/http"
Expand Down
17 changes: 12 additions & 5 deletions app/api_topologies_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package main
package app_test

import (
"bytes"
"encoding/gob"
"encoding/json"
"net/http/httptest"
"testing"
"time"

"github.com/gorilla/mux"
"k8s.io/kubernetes/pkg/api"

"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/test/fixture"
)

func TestAPITopology(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()

body := getRawJSON(t, ts, "/api/topology")

var topologies []APITopologyDesc
var topologies []app.APITopologyDesc
if err := json.Unmarshal(body, &topologies); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand Down Expand Up @@ -48,12 +51,16 @@ func TestAPITopology(t *testing.T) {
}

func TestAPITopologyAddsKubernetes(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
router := mux.NewRouter()
c := app.NewCollector(1 * time.Minute)
app.RegisterTopologyRoutes(c, router)
app.RegisterReportPostHandler(c, router)
ts := httptest.NewServer(router)
defer ts.Close()

body := getRawJSON(t, ts, "/api/topology")

var topologies []APITopologyDesc
var topologies []app.APITopologyDesc
if err := json.Unmarshal(body, &topologies); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/api_topology.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"net/http"
Expand Down
32 changes: 16 additions & 16 deletions app/api_topology_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main
package app_test

import (
"encoding/json"
"fmt"
"net/http/httptest"
"net/url"
"reflect"
"testing"

"github.com/gorilla/websocket"

"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/render/expected"
"github.com/weaveworks/scope/report"
Expand All @@ -18,25 +18,25 @@ import (
)

func TestAll(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()

body := getRawJSON(t, ts, "/api/topology")
var topologies []APITopologyDesc
var topologies []app.APITopologyDesc
if err := json.Unmarshal(body, &topologies); err != nil {
t.Fatalf("JSON parse error: %s", err)
}

getTopology := func(topologyURL string) {
body := getRawJSON(t, ts, topologyURL)
var topology APITopology
var topology app.APITopology
if err := json.Unmarshal(body, &topology); err != nil {
t.Fatalf("JSON parse error: %s", err)
}

for _, node := range topology.Nodes {
body := getRawJSON(t, ts, fmt.Sprintf("%s/%s", topologyURL, url.QueryEscape(node.ID)))
var node APINode
var node app.APINode
if err := json.Unmarshal(body, &node); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand All @@ -53,10 +53,10 @@ func TestAll(t *testing.T) {
}

func TestAPITopologyContainers(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
{
body := getRawJSON(t, ts, "/api/topology/containers")
var topo APITopology
var topo app.APITopology
if err := json.Unmarshal(body, &topo); err != nil {
t.Fatal(err)
}
Expand All @@ -73,12 +73,12 @@ func TestAPITopologyContainers(t *testing.T) {
}

func TestAPITopologyApplications(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()
is404(t, ts, "/api/topology/applications/foobar")
{
body := getRawJSON(t, ts, "/api/topology/applications/"+expected.ServerProcessID)
var node APINode
var node app.APINode
if err := json.Unmarshal(body, &node); err != nil {
t.Fatal(err)
}
Expand All @@ -90,7 +90,7 @@ func TestAPITopologyApplications(t *testing.T) {
}
{
body := getRawJSON(t, ts, fmt.Sprintf("/api/topology/applications/%s/%s", expected.ClientProcess1ID, expected.ServerProcessID))
var edge APIEdge
var edge app.APIEdge
if err := json.Unmarshal(body, &edge); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand All @@ -104,12 +104,12 @@ func TestAPITopologyApplications(t *testing.T) {
}

func TestAPITopologyHosts(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()
is404(t, ts, "/api/topology/hosts/foobar")
{
body := getRawJSON(t, ts, "/api/topology/hosts")
var topo APITopology
var topo app.APITopology
if err := json.Unmarshal(body, &topo); err != nil {
t.Fatal(err)
}
Expand All @@ -120,7 +120,7 @@ func TestAPITopologyHosts(t *testing.T) {
}
{
body := getRawJSON(t, ts, "/api/topology/hosts/"+expected.ServerHostRenderedID)
var node APINode
var node app.APINode
if err := json.Unmarshal(body, &node); err != nil {
t.Fatal(err)
}
Expand All @@ -132,7 +132,7 @@ func TestAPITopologyHosts(t *testing.T) {
}
{
body := getRawJSON(t, ts, fmt.Sprintf("/api/topology/hosts/%s/%s", expected.ClientHostRenderedID, expected.ServerHostRenderedID))
var edge APIEdge
var edge app.APIEdge
if err := json.Unmarshal(body, &edge); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
Expand All @@ -146,7 +146,7 @@ func TestAPITopologyHosts(t *testing.T) {

// Basic websocket test
func TestAPITopologyWebsocket(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
ts := topologyServer()
defer ts.Close()
url := "/api/topology/applications/ws"

Expand Down
18 changes: 12 additions & 6 deletions app/collector.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"sync"
Expand All @@ -21,9 +21,15 @@ type Adder interface {
Add(report.Report)
}

// A Collector is a Reporter and an Adder
type Collector interface {
Reporter
Adder
}

// Collector receives published reports from multiple producers. It yields a
// single merged report, representing all collected reports.
type Collector struct {
type collector struct {
mtx sync.Mutex
reports []timestampReport
window time.Duration
Expand Down Expand Up @@ -60,8 +66,8 @@ func (wc *waitableCondition) Broadcast() {
}

// NewCollector returns a collector ready for use.
func NewCollector(window time.Duration) *Collector {
return &Collector{
func NewCollector(window time.Duration) Collector {
return &collector{
window: window,
waitableCondition: waitableCondition{
waiters: map[chan struct{}]struct{}{},
Expand All @@ -72,7 +78,7 @@ func NewCollector(window time.Duration) *Collector {
var now = time.Now

// Add adds a report to the collector's internal state. It implements Adder.
func (c *Collector) Add(rpt report.Report) {
func (c *collector) Add(rpt report.Report) {
c.mtx.Lock()
defer c.mtx.Unlock()
c.reports = append(c.reports, timestampReport{now(), rpt})
Expand All @@ -84,7 +90,7 @@ func (c *Collector) Add(rpt report.Report) {

// Report returns a merged report over all added reports. It implements
// Reporter.
func (c *Collector) Report() report.Report {
func (c *collector) Report() report.Report {
c.mtx.Lock()
defer c.mtx.Unlock()

Expand Down
5 changes: 3 additions & 2 deletions app/collector_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package main
package app_test

import (
"reflect"
"testing"
"time"

"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/test"
)

func TestCollector(t *testing.T) {
window := time.Millisecond
c := NewCollector(window)
c := app.NewCollector(window)

r1 := report.MakeReport()
r1.Endpoint.AddNode("foo", report.MakeNode())
Expand Down
5 changes: 3 additions & 2 deletions app/controls.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app

import (
"log"
Expand All @@ -12,7 +12,8 @@ import (
"github.com/weaveworks/scope/xfer"
)

func registerControlRoutes(router *mux.Router) {
// RegisterControlRoutes registers the various control routes with a http mux.
func RegisterControlRoutes(router *mux.Router) {
controlRouter := &controlRouter{
probes: map[string]controlHandler{},
}
Expand Down
9 changes: 5 additions & 4 deletions app/controls_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app_test

import (
"encoding/json"
Expand All @@ -9,14 +9,15 @@ import (
"testing"
"time"

"github.com/weaveworks/scope/xfer"

"github.com/gorilla/mux"

"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/xfer"
)

func TestControl(t *testing.T) {
router := mux.NewRouter()
registerControlRoutes(router)
app.RegisterControlRoutes(router)
server := httptest.NewServer(router)
defer server.Close()

Expand Down
2 changes: 1 addition & 1 deletion app/mock_reporter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package app_test

import (
"github.com/weaveworks/scope/report"
Expand Down
Loading

0 comments on commit d1b18f2

Please sign in to comment.