diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2020-02-03 16:18:14 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2020-02-03 16:18:14 +0300 |
commit | 98c3e01dc59b1a1374f648e0f4c2e599f20657d4 (patch) | |
tree | 0b21c9267efc6a2f4685baec21800a53dc461c86 /internal/serving | |
parent | 57a8b1184da1d53184aad5d4f0bedea51d330b1a (diff) |
Add serverless serving metrics
This adds:
- serverless invocations counter
- serverless request latency histogram
Diffstat (limited to 'internal/serving')
-rw-r--r-- | internal/serving/serverless/serverless.go | 3 | ||||
-rw-r--r-- | internal/serving/serverless/transport.go | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/internal/serving/serverless/serverless.go b/internal/serving/serverless/serverless.go index a8d090da..a73affeb 100644 --- a/internal/serving/serverless/serverless.go +++ b/internal/serving/serverless/serverless.go @@ -5,6 +5,7 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/httperrors" "gitlab.com/gitlab-org/gitlab-pages/internal/serving" + "gitlab.com/gitlab-org/gitlab-pages/metrics" ) // Serverless is a servering used to proxy requests between a client and @@ -26,6 +27,8 @@ func New(function Function, cluster Cluster) serving.Serving { // ServeFileHTTP handle an incoming request and proxies it to Knative cluster func (s *Serverless) ServeFileHTTP(h serving.Handler) bool { + metrics.ServerlessRequests.Inc() + s.proxy.ServeHTTP(h.Writer, h.Request) return true diff --git a/internal/serving/serverless/transport.go b/internal/serving/serverless/transport.go index 5a0f5165..b7fabb13 100644 --- a/internal/serving/serverless/transport.go +++ b/internal/serving/serverless/transport.go @@ -5,6 +5,8 @@ import ( "net" "net/http" "time" + + "gitlab.com/gitlab-org/gitlab-pages/metrics" ) // Transport is a struct that handle the proxy connection round trip to Knative @@ -39,8 +41,11 @@ func NewTransport(cluster Cluster) *Transport { // RoundTrip performs a connection to a Knative cluster and returns a response func (t *Transport) RoundTrip(request *http.Request) (*http.Response, error) { + start := time.Now() + response, err := t.transport.RoundTrip(request) - // TODO add prometheus metrics for round trip timing + metrics.ServerlessLatency.Observe(time.Since(start).Seconds()) + return response, err } |