Skip to content

Commit a121eee

Browse files
author
Ricardo Gamba
committed
Merge branch 'embed-assets'
2 parents d4c862e + bbb8809 commit a121eee

23 files changed

+852
-148
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build/**
2-
cmd/debug
2+
cmd/debug
3+
.vscode/**

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ BUILD=`git rev-parse HEAD | head -c 8`
66
LDFLAGS="-X main.Version=${VERSION} -X main.Build=${BUILD}"
77

88
.PHONY: build
9-
build:
9+
build: generate
1010
@echo "==> Building"
11+
@go generate dashboard/*.go
1112
@go build -ldflags ${LDFLAGS} -o build/${BINARY} cmd/*.go
1213
@echo "\n==>\033[32m Ok\033[m\n"
1314

15+
.PHONY: generate
16+
generate:
17+
@echo "==> Generating"
18+
@go generate dashboard/*.go
19+
@echo "\n==>\033[32m Ok\033[m\n"
20+
1421
.PHONY: release
1522
release:
1623
@echo "==> Releasing for all platforms"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ implementing an HTTP API with the benefits of async inter-service communication.
66
Here is a simple diagram of how Postman works
77

88

9-
<img src="./assets/process1.png" align="left" alt="process" style="margin: 10px 0 20px 0" />
9+
<img src="./assets/img/process1.png" align="left" alt="process" style="margin: 10px 0 20px 0" />
1010

1111

1212
Most of the HTTP services use a reverse proxy (nginx, Apache, etc) already, you can

assets/html/footer.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="container">
2+
<footer class="footer">
3+
<p>Postman <b>{{.appVersion}}</b> Build <b>{{.appBuild}}</b></p>
4+
</footer>
5+
</div>
6+
7+
<!-- Bootstrap core JavaScript
8+
================================================== -->
9+
<!-- Placed at the end of the document so the pages load faster -->
10+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
12+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
13+
</body>
14+
</html>

assets/html/header.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta name="description" content="">
7+
<meta name="author" content="">
8+
9+
<title>Postman - Dashboard</title>
10+
11+
<!-- Bootstrap core CSS -->
12+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
13+
<style>
14+
body {
15+
padding-top: 7rem;
16+
color: #555;
17+
}
18+
.card .table td,.card .table th {
19+
padding-left: 3px;
20+
padding-right: 3px;
21+
}
22+
.footer {
23+
margin-top: 35px;
24+
padding-top: 1.5rem;
25+
color: #777;
26+
border-top: .05rem solid #e6e6e6;
27+
}
28+
</style>
29+
</head>
30+
31+
<body>
32+
33+
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
34+
<div class="container">
35+
<a class="navbar-brand" href="#" style="margin-right: 35px">Postman</a>
36+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
37+
<span class="navbar-toggler-icon"></span>
38+
</button>
39+
40+
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
41+
<ul class="navbar-nav mr-auto">
42+
<li class="nav-item">
43+
<a class="nav-link" href="/">Dashboard</a>
44+
</li>
45+
<li class="nav-item">
46+
<a class="nav-link" href="/settings">Settings</a>
47+
</li>
48+
</ul>
49+
</div>
50+
</div>
51+
</nav>

assets/html/index.html

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{{template "header.html" .}}
2+
<div class="container">
3+
4+
<div class="starter-template">
5+
<h1>Dashboard</h1>
6+
7+
<div class="row" style="margin-top: 40px">
8+
<div class="col-sm-6">
9+
<div class="card">
10+
<div class="card-body">
11+
<h4 class="card-title">Current service</h4>
12+
<h6 class="card-subtitle mb-2 text-muted">This instance info.</h6>
13+
<table class="table" style="margin-top: 30px">
14+
<tr>
15+
<th scope="row">Service name</th>
16+
<td><span class="badge badge-primary" style="font-size: 100%">{{.currentServiceName}}</span></td>
17+
</tr>
18+
<tr>
19+
<th scope="row">Active instances</th>
20+
<td>{{.currentServiceInstances}}</td>
21+
</tr>
22+
</table>
23+
<a href="#" class="card-link">View more</a>
24+
</div>
25+
</div>
26+
</div>
27+
<div class="col-sm-6">
28+
<div class="card">
29+
<div class="card-body">
30+
<h4 class="card-title">Current process</h4>
31+
<h6 class="card-subtitle mb-2 text-muted">Process info.</h6>
32+
<table class="table" style="margin-top: 30px">
33+
<tr>
34+
<th scope="row">Process ID</th>
35+
<td>{{.processId}}</td>
36+
</tr>
37+
</table>
38+
</div>
39+
</div>
40+
</div>
41+
</div>
42+
<div class="row" style="margin-top: 30px">
43+
<div class="col-sm-6">
44+
<div class="card">
45+
<div class="card-body">
46+
<h4 class="card-title">Incomming requests</h4>
47+
<h6 class="card-subtitle mb-2 text-muted">Communication relative to this instance.</h6>
48+
<table class="table" style="margin-top: 15px">
49+
<thead>
50+
<th>Requesting service</th>
51+
<th>Requests last minute</th>
52+
</thead>
53+
{{range $serviceName, $count := .incomingRequests}}
54+
<tr>
55+
<td>{{$serviceName}}</td>
56+
<td>{{$count}}</td>
57+
</tr>
58+
{{end}}
59+
</table>
60+
</div>
61+
</div>
62+
</div>
63+
<div class="col-sm-6">
64+
<div class="card">
65+
<div class="card-body">
66+
<h4 class="card-title">Outgoing requests</h4>
67+
<h6 class="card-subtitle mb-2 text-muted">Communication relative to this instance.</h6>
68+
<table class="table" style="margin-top: 15px">
69+
<thead>
70+
<th>Destination service</th>
71+
<th>Requests last minute</th>
72+
</thead>
73+
{{range $serviceName, $count := .outgoingRequests}}
74+
<tr>
75+
<td>{{$serviceName}}</td>
76+
<td>{{$count}}</td>
77+
</tr>
78+
{{end}}
79+
</table>
80+
</div>
81+
</div>
82+
</div>
83+
</div>
84+
</div>
85+
86+
87+
</div><!-- /.container -->
88+
{{template "footer.html" .}}

assets/html/settings.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{{template "header.html" .}}
2+
3+
<div class="container">
4+
<h1 style="margin-bottom: 30px">Settings</h1>
5+
<h4>Service</h4>
6+
<table class="table" style="table-layout: fixed">
7+
{{range $key, $value := .service}}
8+
<tr>
9+
<th>{{$key}}</th>
10+
<td>{{$value}}</td>
11+
</tr>
12+
{{end}}
13+
</table>
14+
15+
<h4>HTTP</h4>
16+
<table class="table" style="table-layout: fixed">
17+
{{range $key, $value := .http}}
18+
<tr>
19+
<th>{{$key}}</th>
20+
<td>{{$value}}</td>
21+
</tr>
22+
{{end}}
23+
</table>
24+
25+
<h4>Dashboard</h4>
26+
<table class="table" style="table-layout: fixed">
27+
{{range $key, $value := .dashboard}}
28+
<tr>
29+
<th>{{$key}}</th>
30+
<td>{{$value}}</td>
31+
</tr>
32+
{{end}}
33+
</table>
34+
</div>
35+
36+
{{template "footer.html" .}}
File renamed without changes.
File renamed without changes.

async/amqp.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ func GetResponseQueueName() string {
6767
return responseQueueName
6868
}
6969

70+
// GetServiceName doesn't need description.
71+
func GetServiceName() string {
72+
return serviceName
73+
}
74+
7075
// CreateNewChannel is used to create new channels.
7176
// This func is intended for use outside of this package, for example
7277
// in the proxy package, it will create one channel per http request.
@@ -232,3 +237,19 @@ func createInvalidQueueNameError(queueName string) *Error {
232237
},
233238
)
234239
}
240+
241+
// GetServiceInstances returns the number of consumers of a given request
242+
// queue on the AMQP server. In other words that means the number of instances
243+
// available for that given service.
244+
func GetServiceInstances(serviceName string) int {
245+
ch, err := conn.Channel()
246+
if err != nil {
247+
return 0
248+
}
249+
queueName := buildRequestQueueName(serviceName)
250+
queue, err := ch.QueueInspect(queueName)
251+
if err != nil {
252+
return 0
253+
}
254+
return queue.Consumers
255+
}

async/amqp_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestConsumeFromRequestQueue(t *testing.T) {
5252
defer _close_connection()
5353
c := make(chan bool)
5454
OnNewRequest = func(req protobuf.Request) {
55-
assert.Equal(t, "test", req.GetBody())
55+
assert.Equal(t, "test", req.Body)
5656
c <- true
5757
}
5858
request := &protobuf.Request{Body: "test"}
@@ -104,16 +104,16 @@ func TestSendMessage(t *testing.T) {
104104
_consumeQueue("postman.req.service1", func(msg []byte) {
105105
req := &protobuf.Request{}
106106
proto.Unmarshal(msg, req)
107-
response := &protobuf.Response{Body: "testresponse", RequestId: req.GetId()}
107+
response := &protobuf.Response{Body: "testresponse", RequestId: req.Id}
108108
respMsg, _ := proto.Marshal(response)
109-
_publishMessage(respMsg, req.GetResponseQueue())
109+
_publishMessage(respMsg, req.ResponseQueue)
110110
})
111111
c := make(chan bool)
112112
ch, _ := conn.Channel()
113113
req := &protobuf.Request{Body: "test", Method: "GET", ResponseQueue: responseQueueName}
114114
SendRequestMessage(ch, "service1", req, func(resp *protobuf.Response, err *Error) {
115115
assert.Nil(t, err)
116-
assert.Equal(t, "testresponse", resp.GetBody())
116+
assert.Equal(t, "testresponse", resp.Body)
117117
c <- true
118118
})
119119
<-c
@@ -126,9 +126,9 @@ func TestSendMessageParallelCalls(t *testing.T) {
126126
_consumeQueue("postman.req.service1", func(msg []byte) {
127127
req := &protobuf.Request{}
128128
proto.Unmarshal(msg, req)
129-
response := &protobuf.Response{Body: req.GetBody(), RequestId: req.GetId()}
129+
response := &protobuf.Response{Body: req.Body, RequestId: req.Id}
130130
respMsg, _ := proto.Marshal(response)
131-
_publishMessage(respMsg, req.GetResponseQueue())
131+
_publishMessage(respMsg, req.ResponseQueue)
132132
})
133133
var wait sync.WaitGroup
134134
for i := 0; i <= 100; i++ {
@@ -139,7 +139,7 @@ func TestSendMessageParallelCalls(t *testing.T) {
139139
SendRequestMessage(ch, "service1", req, func(resp *protobuf.Response, err *Error) {
140140
expectedBody := fmt.Sprintf("%d", i)
141141
assert.Nil(t, err)
142-
assert.Equal(t, expectedBody, resp.GetBody())
142+
assert.Equal(t, expectedBody, resp.Body)
143143
wait.Done()
144144
})
145145
}(i)

0 commit comments

Comments
 (0)