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

Commit 1714eca

Browse files
author
Phil Winder
authored
Merge pull request #45 from microservices-demo/refactor/weave-common
Reuse middleware from weaveworks/common.
2 parents e147999 + c06f85b commit 1714eca

File tree

8 files changed

+48
-149
lines changed

8 files changed

+48
-149
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: go
2-
go: 1.6
2+
go: 1.7
33
sudo: required
44
env:
55
- GROUP=weaveworksdemos COMMIT=$TRAVIS_COMMIT TAG=$TRAVIS_TAG

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.6-alpine
1+
FROM golang:1.7-alpine
22
ENV sourcesdir /go/src/github.com/microservices-demo/user/
33
ENV MONGO_HOST mytestdb:27017
44
ENV HATEAOS user

Dockerfile-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
66

77
RUN apt-get update && apt-get install -yq git curl
88

9-
RUN curl -sSL https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz -o go.tar.gz && \
9+
RUN curl -sSL https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz -o go.tar.gz && \
1010
tar -C /usr/local -xvf go.tar.gz
1111
RUN go get -v github.com/Masterminds/glide
1212

glide.lock

Lines changed: 28 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ import:
2727
subpackages:
2828
- hystrix
2929
- package: github.com/felixge/httpsnoop
30+
- package: github.com/weaveworks/common
31+
subpackages:
32+
- middleware

main.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,32 @@ import (
1515
"github.com/microservices-demo/user/api"
1616
"github.com/microservices-demo/user/db"
1717
"github.com/microservices-demo/user/db/mongodb"
18-
"github.com/microservices-demo/user/middleware"
1918
stdopentracing "github.com/opentracing/opentracing-go"
2019
zipkin "github.com/openzipkin/zipkin-go-opentracing"
2120
stdprometheus "github.com/prometheus/client_golang/prometheus"
21+
commonMiddleware "github.com/weaveworks/common/middleware"
2222
"golang.org/x/net/context"
2323
)
2424

2525
var (
26-
dev bool
2726
port string
28-
acc string
2927
zip string
3028
)
3129

30+
var (
31+
HTTPLatency = stdprometheus.NewHistogramVec(stdprometheus.HistogramOpts{
32+
Name: "request_duration_seconds",
33+
Help: "Time (in seconds) spent serving HTTP requests.",
34+
Buckets: stdprometheus.DefBuckets,
35+
}, []string{"method", "route", "status_code", "isWS"})
36+
)
37+
3238
const (
3339
ServiceName = "user"
3440
)
3541

3642
func init() {
37-
43+
stdprometheus.MustRegister(HTTPLatency)
3844
flag.StringVar(&zip, "zipkin", os.Getenv("ZIPKIN"), "Zipkin address")
3945
flag.StringVar(&port, "port", "8084", "Port on which to run")
4046
db.Register("mongodb", &mongodb.Mongo{})
@@ -124,16 +130,15 @@ func main() {
124130
// HTTP router
125131
router := api.MakeHTTPHandler(ctx, endpoints, logger, tracer)
126132

127-
httpMiddleware := []middleware.Interface{
128-
middleware.Instrument{
129-
Duration: middleware.HTTPLatency,
133+
httpMiddleware := []commonMiddleware.Interface{
134+
commonMiddleware.Instrument{
135+
Duration: HTTPLatency,
130136
RouteMatcher: router,
131-
Service: ServiceName,
132137
},
133138
}
134139

135140
// Handler
136-
handler := middleware.Merge(httpMiddleware...).Wrap(router)
141+
handler := commonMiddleware.Merge(httpMiddleware...).Wrap(router)
137142

138143
// Create and launch the HTTP server.
139144
go func() {

middleware/instrument.go

Lines changed: 0 additions & 94 deletions
This file was deleted.

middleware/middleware.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)