this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Track whether or not a query is typeahead in metrics

+17 -8
+17 -8
search/metrics.go
··· 60 60 Name: "http_request_size_bytes", 61 61 Help: "A histogram of request sizes for requests.", 62 62 Buckets: prometheus.ExponentialBuckets(100, 10, 8), 63 - }, []string{"code", "method", "path"}) 63 + }, []string{"code", "method", "path", "extras"}) 64 64 65 65 var reqDur = promauto.NewHistogramVec(prometheus.HistogramOpts{ 66 66 Name: "http_request_duration_seconds", 67 67 Help: "A histogram of latencies for requests.", 68 68 Buckets: prometheus.ExponentialBuckets(0.0001, 2, 18), 69 - }, []string{"code", "method", "path"}) 69 + }, []string{"code", "method", "path", "extras"}) 70 70 71 71 var reqCnt = promauto.NewCounterVec(prometheus.CounterOpts{ 72 72 Name: "http_requests_total", 73 73 Help: "A counter for requests to the wrapped handler.", 74 - }, []string{"code", "method", "path"}) 74 + }, []string{"code", "method", "path", "extras"}) 75 75 76 76 var resSz = promauto.NewHistogramVec(prometheus.HistogramOpts{ 77 77 Name: "http_response_size_bytes", 78 78 Help: "A histogram of response sizes for requests.", 79 79 Buckets: prometheus.ExponentialBuckets(100, 10, 8), 80 - }, []string{"code", "method", "path"}) 80 + }, []string{"code", "method", "path", "extras"}) 81 81 82 82 // MetricsMiddleware defines handler function for metrics middleware 83 83 func MetricsMiddleware(next echo.HandlerFunc) echo.HandlerFunc { ··· 110 110 111 111 responseSize := float64(c.Response().Size) 112 112 113 - reqDur.WithLabelValues(statusStr, method, path).Observe(elapsed) 114 - reqCnt.WithLabelValues(statusStr, method, path).Inc() 115 - reqSz.WithLabelValues(statusStr, method, path).Observe(float64(requestSize)) 116 - resSz.WithLabelValues(statusStr, method, path).Observe(responseSize) 113 + // Custom label for Typeahead search queries 114 + isTypeahead := c.QueryParam("typeahead") == "true" 115 + labels := []string{statusStr, method, path} 116 + if isTypeahead { 117 + labels = append(labels, "typeahead") 118 + } else { 119 + labels = append(labels, "") 120 + } 121 + 122 + reqDur.WithLabelValues(labels...).Observe(elapsed) 123 + reqCnt.WithLabelValues(labels...).Inc() 124 + reqSz.WithLabelValues(labels...).Observe(float64(requestSize)) 125 + resSz.WithLabelValues(labels...).Observe(responseSize) 117 126 118 127 return err 119 128 }