From cc06fe3a500136e4a07dd7d752870936a8dcae56 Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Thu, 16 Jan 2025 23:39:23 +0100 Subject: [PATCH] fix(metrics): fallback to legacy naming --- assets/go-licenses.json | 5 +++++ routers/common/middleware.go | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/assets/go-licenses.json b/assets/go-licenses.json index a20494184bd40..817c84bc04f05 100644 --- a/assets/go-licenses.json +++ b/assets/go-licenses.json @@ -439,6 +439,11 @@ "path": "github.com/felixge/fgprof/LICENSE.txt", "licenseText": "The MIT License (MIT)\nCopyright © 2020 Felix Geisendörfer \u003cfelix@felixge.de\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n" }, + { + "name": "github.com/felixge/httpsnoop", + "path": "github.com/felixge/httpsnoop/LICENSE.txt", + "licenseText": "Copyright (c) 2016 Felix Geisendörfer (felix@debuggable.com)\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n" + }, { "name": "github.com/fsnotify/fsnotify", "path": "github.com/fsnotify/fsnotify/LICENSE", diff --git a/routers/common/middleware.go b/routers/common/middleware.go index fe455251f9430..94dd20a5bcfc5 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -24,6 +24,12 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" ) +const ( + httpRequestMethod = "http_request_method" + httpResponseStatusCode = "http_response_status_code" + httpRoute = "http_route" +) + var ( // reqInflightGauge tracks the amount of currently handled requests reqInflightGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{ @@ -31,28 +37,28 @@ var ( Subsystem: "server", Name: "active_requests", Help: "Number of active HTTP server requests.", - }, []string{"http.request.method"}) + }, []string{httpRequestMethod}) // reqDurationHistogram tracks the time taken by http request reqDurationHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: "http", Subsystem: "server", Name: "request_duration", Help: "Measures the latency of HTTP requests processed by the server", - }, []string{"http.request.method", "http.response.status_code", "http.route"}) + }, []string{httpRequestMethod, httpResponseStatusCode, httpRoute}) // reqSizeHistogram tracks the size of request reqSizeHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: "http", Subsystem: "server_request", Name: "body_size", Help: "Size of HTTP server request bodies.", - }, []string{"http.request.method", "http.response.status_code", "http.route"}) + }, []string{httpRequestMethod, httpResponseStatusCode, httpRoute}) // respSizeHistogram tracks the size of the response respSizeHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: "http", Subsystem: "server_response", Name: "body_size", Help: "Size of HTTP server response bodies.", - }, []string{"http.request.method", "http.response.status_code", "http.route"}) + }, []string{httpRequestMethod, httpResponseStatusCode, httpRoute}) ) // ProtocolMiddlewares returns HTTP protocol related middlewares, and it provides a global panic recovery