Browse Source

Standardize http metrics, to flux_request_duration

Paul Bellamy 2 years ago
parent
commit
7e96b1b850
No account linked to committer's email address
4 changed files with 175 additions and 24 deletions
  1. 6
    6
      cmd/fluxsvc/main.go
  2. 8
    14
      http/transport.go
  3. 3
    4
      metrics/metrics.go
  4. 158
    0
      vendor/manifest

+ 6
- 6
cmd/fluxsvc/main.go View File

@@ -99,7 +99,7 @@ func main() {
99 99
 		busMetrics       platform.BusMetrics
100 100
 		helperDuration   metrics.Histogram
101 101
 		historyMetrics   history.Metrics
102
-		httpDuration     metrics.Histogram
102
+		httpDuration     *stdprometheus.HistogramVec
103 103
 		instanceMetrics  instance.Metrics
104 104
 		jobWorkerMetrics jobs.WorkerMetrics
105 105
 		registryMetrics  registry.Metrics
@@ -107,13 +107,12 @@ func main() {
107 107
 		serverMetrics    server.Metrics
108 108
 	)
109 109
 	{
110
-		httpDuration = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
110
+		httpDuration = stdprometheus.NewHistogramVec(stdprometheus.HistogramOpts{
111 111
 			Namespace: "flux",
112
-			Subsystem: "fluxsvc",
113
-			Name:      "http_request_duration_seconds",
114
-			Help:      "HTTP request duration in seconds.",
112
+			Name:      "request_duration_seconds",
113
+			Help:      "Time (in seconds) spent serving HTTP requests.",
115 114
 			Buckets:   stdprometheus.DefBuckets,
116
-		}, []string{fluxmetrics.LabelMethod, "status_code"})
115
+		}, []string{fluxmetrics.LabelMethod, fluxmetrics.LabelRoute, "status_code", "ws"})
117 116
 		serverMetrics.StatusDuration = prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
118 117
 			Namespace: "flux",
119 118
 			Subsystem: "fluxsvc",
@@ -190,6 +189,7 @@ func main() {
190 189
 		instanceMetrics = instance.NewMetrics()
191 190
 		jobWorkerMetrics = jobs.NewWorkerMetrics()
192 191
 	}
192
+	stdprometheus.MustRegister(httpDuration)
193 193
 
194 194
 	var messageBus platform.MessageBus
195 195
 	{

+ 8
- 14
http/transport.go View File

@@ -10,14 +10,14 @@ import (
10 10
 	"net/http"
11 11
 	"net/url"
12 12
 	"path"
13
-	"strconv"
14 13
 	"strings"
15 14
 	"time"
16 15
 
17 16
 	"github.com/go-kit/kit/log"
18
-	"github.com/go-kit/kit/metrics"
19 17
 	"github.com/gorilla/mux"
20 18
 	"github.com/pkg/errors"
19
+	stdprometheus "github.com/prometheus/client_golang/prometheus"
20
+	"github.com/weaveworks/common/middleware"
21 21
 
22 22
 	"github.com/weaveworks/flux"
23 23
 	"github.com/weaveworks/flux/api"
@@ -46,7 +46,7 @@ func NewRouter() *mux.Router {
46 46
 	return r
47 47
 }
48 48
 
49
-func NewHandler(s api.FluxService, r *mux.Router, logger log.Logger, h metrics.Histogram) http.Handler {
49
+func NewHandler(s api.FluxService, r *mux.Router, logger log.Logger, h *stdprometheus.HistogramVec) http.Handler {
50 50
 	for method, handlerFunc := range map[string]func(api.FluxService) http.Handler{
51 51
 		"ListServices":   handleListServices,
52 52
 		"ListImages":     handleListImages,
@@ -66,11 +66,14 @@ func NewHandler(s api.FluxService, r *mux.Router, logger log.Logger, h metrics.H
66 66
 		var handler http.Handler
67 67
 		handler = handlerFunc(s)
68 68
 		handler = logging(handler, log.NewContext(logger).With("method", method))
69
-		handler = observing(handler, h.With("method", method))
70 69
 
71 70
 		r.Get(method).Handler(handler)
72 71
 	}
73
-	return r
72
+
73
+	return middleware.Instrument{
74
+		RouteMatcher: r,
75
+		Duration:     h,
76
+	}.Wrap(r)
74 77
 }
75 78
 
76 79
 // When an API call fails, we may want to distinguish among the causes
@@ -823,15 +826,6 @@ func logging(next http.Handler, logger log.Logger) http.Handler {
823 826
 	})
824 827
 }
825 828
 
826
-func observing(next http.Handler, h metrics.Histogram) http.Handler {
827
-	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
828
-		begin := time.Now()
829
-		cw := &codeWriter{w, http.StatusOK}
830
-		next.ServeHTTP(cw, r)
831
-		h.With("status_code", strconv.Itoa(cw.code)).Observe(time.Since(begin).Seconds())
832
-	})
833
-}
834
-
835 829
 // codeWriter intercepts the HTTP status code. WriteHeader may not be called in
836 830
 // case of success, so either prepopulate code with http.StatusOK, or check for
837 831
 // zero on the read side.

+ 3
- 4
metrics/metrics.go View File

@@ -5,10 +5,9 @@ Labels and so on for metrics used in Flux.
5 5
 */
6 6
 
7 7
 const (
8
-	LabelInstanceID = "instance_id"
9
-	LabelMethod     = "method"
10
-	LabelNamespace  = "namespace"
11
-	LabelSuccess    = "success"
8
+	LabelRoute   = "route"
9
+	LabelMethod  = "method"
10
+	LabelSuccess = "success"
12 11
 
13 12
 	// Labels for release metrics
14 13
 	LabelAction      = "action"

+ 158
- 0
vendor/manifest View File

@@ -1,6 +1,24 @@
1 1
 {
2 2
 	"version": 0,
3 3
 	"dependencies": [
4
+		{
5
+			"importpath": "cloud.google.com/go/compute/metadata",
6
+			"repository": "https://code.googlesource.com/gocloud",
7
+			"vcs": "git",
8
+			"revision": "dd09098543bc5e1171c212bba31c7b5e0beea39c",
9
+			"branch": "master",
10
+			"path": "/compute/metadata",
11
+			"notests": true
12
+		},
13
+		{
14
+			"importpath": "cloud.google.com/go/internal",
15
+			"repository": "https://code.googlesource.com/gocloud",
16
+			"vcs": "git",
17
+			"revision": "dd09098543bc5e1171c212bba31c7b5e0beea39c",
18
+			"branch": "master",
19
+			"path": "internal",
20
+			"notests": true
21
+		},
4 22
 		{
5 23
 			"importpath": "github.com/BurntSushi/toml",
6 24
 			"repository": "https://github.com/BurntSushi/toml",
@@ -301,6 +319,14 @@
301 319
 			"branch": "master",
302 320
 			"notests": true
303 321
 		},
322
+		{
323
+			"importpath": "github.com/golang/glog",
324
+			"repository": "https://github.com/golang/glog",
325
+			"vcs": "git",
326
+			"revision": "23def4e6c14b4da8ac2ed8007337bc5eb5007998",
327
+			"branch": "master",
328
+			"notests": true
329
+		},
304 330
 		{
305 331
 			"importpath": "github.com/golang/protobuf/proto",
306 332
 			"repository": "https://github.com/golang/protobuf",
@@ -310,6 +336,15 @@
310 336
 			"path": "/proto",
311 337
 			"notests": true
312 338
 		},
339
+		{
340
+			"importpath": "github.com/golang/protobuf/protoc-gen-go/descriptor",
341
+			"repository": "https://github.com/golang/protobuf",
342
+			"vcs": "git",
343
+			"revision": "8ee79997227bf9b34611aee7946ae64735e6fd93",
344
+			"branch": "master",
345
+			"path": "/protoc-gen-go/descriptor",
346
+			"notests": true
347
+		},
313 348
 		{
314 349
 			"importpath": "github.com/golang/protobuf/ptypes/any",
315 350
 			"repository": "https://github.com/golang/protobuf",
@@ -327,6 +362,14 @@
327 362
 			"branch": "master",
328 363
 			"notests": true
329 364
 		},
365
+		{
366
+			"importpath": "github.com/googleapis/gax-go",
367
+			"repository": "https://github.com/googleapis/gax-go",
368
+			"vcs": "git",
369
+			"revision": "da06d194a00e19ce00d9011a13931c3f6f6887c7",
370
+			"branch": "master",
371
+			"notests": true
372
+		},
330 373
 		{
331 374
 			"importpath": "github.com/gorilla/context",
332 375
 			"repository": "https://github.com/gorilla/context",
@@ -754,6 +797,24 @@
754 797
 			"path": "/codec",
755 798
 			"notests": true
756 799
 		},
800
+		{
801
+			"importpath": "github.com/weaveworks/common/middleware",
802
+			"repository": "https://github.com/weaveworks/common",
803
+			"vcs": "git",
804
+			"revision": "08ae9c839237b80dd6fd41b8570573d1528cec3b",
805
+			"branch": "master",
806
+			"path": "/middleware",
807
+			"notests": true
808
+		},
809
+		{
810
+			"importpath": "github.com/weaveworks/common/user",
811
+			"repository": "https://github.com/weaveworks/common",
812
+			"vcs": "git",
813
+			"revision": "08ae9c839237b80dd6fd41b8570573d1528cec3b",
814
+			"branch": "master",
815
+			"path": "user",
816
+			"notests": true
817
+		},
757 818
 		{
758 819
 			"importpath": "github.com/weaveworks/scope/common/mtime",
759 820
 			"repository": "https://github.com/weaveworks/scope",
@@ -790,6 +851,24 @@
790 851
 			"path": "encoding/secconf",
791 852
 			"notests": true
792 853
 		},
854
+		{
855
+			"importpath": "go4.org/syncutil/singleflight",
856
+			"repository": "https://github.com/camlistore/go4",
857
+			"vcs": "git",
858
+			"revision": "7ce08ca145dbe0e66a127c447b80ee7914f3e4f9",
859
+			"branch": "master",
860
+			"path": "/syncutil/singleflight",
861
+			"notests": true
862
+		},
863
+		{
864
+			"importpath": "golang.org/x/crypto/acme",
865
+			"repository": "https://go.googlesource.com/crypto",
866
+			"vcs": "git",
867
+			"revision": "641ab6b32049cabca26c30bf27baaae445bf4175",
868
+			"branch": "master",
869
+			"path": "acme",
870
+			"notests": true
871
+		},
793 872
 		{
794 873
 			"importpath": "golang.org/x/crypto/cast5",
795 874
 			"repository": "https://go.googlesource.com/crypto",
@@ -853,6 +932,15 @@
853 932
 			"path": "/html",
854 933
 			"notests": true
855 934
 		},
935
+		{
936
+			"importpath": "golang.org/x/net/http2",
937
+			"repository": "https://go.googlesource.com/net",
938
+			"vcs": "git",
939
+			"revision": "007e530097ad7f954752df63046b4036f98ba6a6",
940
+			"branch": "master",
941
+			"path": "/http2",
942
+			"notests": true
943
+		},
856 944
 		{
857 945
 			"importpath": "golang.org/x/net/idna",
858 946
 			"repository": "https://go.googlesource.com/net",
@@ -862,6 +950,24 @@
862 950
 			"path": "idna",
863 951
 			"notests": true
864 952
 		},
953
+		{
954
+			"importpath": "golang.org/x/net/internal/timeseries",
955
+			"repository": "https://go.googlesource.com/net",
956
+			"vcs": "git",
957
+			"revision": "007e530097ad7f954752df63046b4036f98ba6a6",
958
+			"branch": "master",
959
+			"path": "internal/timeseries",
960
+			"notests": true
961
+		},
962
+		{
963
+			"importpath": "golang.org/x/net/lex/httplex",
964
+			"repository": "https://go.googlesource.com/net",
965
+			"vcs": "git",
966
+			"revision": "007e530097ad7f954752df63046b4036f98ba6a6",
967
+			"branch": "master",
968
+			"path": "lex/httplex",
969
+			"notests": true
970
+		},
865 971
 		{
866 972
 			"importpath": "golang.org/x/net/publicsuffix",
867 973
 			"repository": "https://go.googlesource.com/net",
@@ -871,6 +977,23 @@
871 977
 			"path": "/publicsuffix",
872 978
 			"notests": true
873 979
 		},
980
+		{
981
+			"importpath": "golang.org/x/net/trace",
982
+			"repository": "https://go.googlesource.com/net",
983
+			"vcs": "git",
984
+			"revision": "007e530097ad7f954752df63046b4036f98ba6a6",
985
+			"branch": "master",
986
+			"path": "trace",
987
+			"notests": true
988
+		},
989
+		{
990
+			"importpath": "golang.org/x/oauth2",
991
+			"repository": "https://go.googlesource.com/oauth2",
992
+			"vcs": "git",
993
+			"revision": "314dd2c0bf3ebd592ec0d20847d27e79d0dbe8dd",
994
+			"branch": "master",
995
+			"notests": true
996
+		},
874 997
 		{
875 998
 			"importpath": "golang.org/x/sys/unix",
876 999
 			"repository": "https://go.googlesource.com/sys",
@@ -979,6 +1102,33 @@
979 1102
 			"path": "unicode/rangetable",
980 1103
 			"notests": true
981 1104
 		},
1105
+		{
1106
+			"importpath": "google.golang.org/api/compute/v1",
1107
+			"repository": "https://code.googlesource.com/google-api-go-client",
1108
+			"vcs": "git",
1109
+			"revision": "dfa61ae24628a06502b9c2805d983b57e89399b5",
1110
+			"branch": "master",
1111
+			"path": "/compute/v1",
1112
+			"notests": true
1113
+		},
1114
+		{
1115
+			"importpath": "google.golang.org/api/gensupport",
1116
+			"repository": "https://code.googlesource.com/google-api-go-client",
1117
+			"vcs": "git",
1118
+			"revision": "dfa61ae24628a06502b9c2805d983b57e89399b5",
1119
+			"branch": "master",
1120
+			"path": "gensupport",
1121
+			"notests": true
1122
+		},
1123
+		{
1124
+			"importpath": "google.golang.org/api/googleapi",
1125
+			"repository": "https://code.googlesource.com/google-api-go-client",
1126
+			"vcs": "git",
1127
+			"revision": "dfa61ae24628a06502b9c2805d983b57e89399b5",
1128
+			"branch": "master",
1129
+			"path": "googleapi",
1130
+			"notests": true
1131
+		},
982 1132
 		{
983 1133
 			"importpath": "google.golang.org/appengine",
984 1134
 			"repository": "https://github.com/golang/appengine",
@@ -987,6 +1137,14 @@
987 1137
 			"branch": "master",
988 1138
 			"notests": true
989 1139
 		},
1140
+		{
1141
+			"importpath": "google.golang.org/grpc",
1142
+			"repository": "https://github.com/grpc/grpc-go",
1143
+			"vcs": "git",
1144
+			"revision": "21f8ed309495401e6fd79b3a9fd549582aed1b4c",
1145
+			"branch": "master",
1146
+			"notests": true
1147
+		},
990 1148
 		{
991 1149
 			"importpath": "gopkg.in/airbrake/gobrake.v2",
992 1150
 			"repository": "https://gopkg.in/airbrake/gobrake.v2",

Loading…
Cancel
Save