Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit 8bb588a

Browse files
committed
Refactor to use middleware from weaveworks/common.
1 parent 4d04796 commit 8bb588a

File tree

8 files changed

+229
-137
lines changed

8 files changed

+229
-137
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: required
33
services:
44
- docker
55
go:
6-
- 1.6
6+
- 1.7
77
before_install:
88
- go get -u github.com/FiloSottile/gvt
99
- gvt restore

cmd/cataloguesvc/main.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,27 @@ import (
1818
_ "github.com/go-sql-driver/mysql"
1919
"github.com/jmoiron/sqlx"
2020
"github.com/microservices-demo/catalogue"
21-
"github.com/microservices-demo/catalogue/middleware"
21+
"github.com/prometheus/client_golang/prometheus"
22+
"github.com/weaveworks/common/middleware"
2223
"golang.org/x/net/context"
2324
)
2425

2526
const (
2627
ServiceName = "catalogue"
2728
)
2829

30+
var (
31+
HTTPLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
32+
Name: "request_duration_seconds",
33+
Help: "Time (in seconds) spent serving HTTP requests.",
34+
Buckets: prometheus.DefBuckets,
35+
}, []string{"service", "method", "route", "status_code"})
36+
)
37+
38+
func init() {
39+
prometheus.MustRegister(HTTPLatency)
40+
}
41+
2942
func main() {
3043
var (
3144
port = flag.String("port", "8081", "Port to bind HTTP listener") // TODO(pb): should be -addr, default ":8081"
@@ -110,9 +123,8 @@ func main() {
110123

111124
httpMiddleware := []middleware.Interface{
112125
middleware.Instrument{
113-
Duration: middleware.HTTPLatency,
126+
Duration: HTTPLatency,
114127
RouteMatcher: router,
115-
Service: ServiceName,
116128
},
117129
}
118130

docker/catalogue/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.6
1+
FROM golang:1.7
22

33
RUN mkdir /app
44
COPY . /go/src/github.com/microservices-demo/catalogue/

middleware/instrument.go

-94
This file was deleted.

middleware/middleware.go

-33
This file was deleted.

scripts/build.sh

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ echo $CODE_DIR
2727

2828
cp -r $CODE_DIR/images/ $CODE_DIR/docker/catalogue/images/
2929
cp -r $CODE_DIR/cmd/ $CODE_DIR/docker/catalogue/cmd/
30-
cp -r $CODE_DIR/middleware/ $CODE_DIR/docker/catalogue/middleware/
3130
cp $CODE_DIR/*.go $CODE_DIR/docker/catalogue/
3231
mkdir -p $CODE_DIR/docker/catalogue/vendor && cp $CODE_DIR/vendor/manifest $CODE_DIR/docker/catalogue/vendor/
3332

test/unit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_go(self):
1111
code_dir = script_dir + "/.."
1212
home = expanduser("~")
1313
goPath = os.environ['GOPATH']
14-
command = ['docker', 'run', '--rm', '-v', goPath + ':/go/src/', '-v', code_dir + ':/go/src/github.com/microservices-demo/catalogue', '-w', '/go/src/github.com/microservices-demo/catalogue', '-e', 'GOPATH=/go/', 'golang:1.6', 'go', 'test', '-v', '-covermode=count', '-coverprofile=coverage.out']
14+
command = ['docker', 'run', '--rm', '-v', goPath + ':/go/src/', '-v', code_dir + ':/go/src/github.com/microservices-demo/catalogue', '-w', '/go/src/github.com/microservices-demo/catalogue', '-e', 'GOPATH=/go/', 'golang:1.7', 'go', 'test', '-v', '-covermode=count', '-coverprofile=coverage.out']
1515

1616
print(Docker().execute(command))
1717

0 commit comments

Comments
 (0)