feat: add Prometheus metrics (#439)

* feat: add Prometheus metrics

* setup metrics using Prometheus client under /metrics endpoint
* add configuration value for metrics
* configure Prometheus middleware for generic metrics
* provide metrics for totals of users, gists and SSH keys
* modify test request to optionally return the response
* provide integration test for Prometheus metrics
* update documentation

* chore: make fmt
This commit is contained in:
Philipp Eckel
2025-03-17 14:30:38 +01:00
committed by GitHub
parent 8c7e941182
commit 1ec026e191
13 changed files with 328 additions and 21 deletions

View File

@ -48,7 +48,7 @@ func (s *TestServer) stop() {
s.server.Stop()
}
func (s *TestServer) Request(method, uri string, data interface{}, expectedCode int) error {
func (s *TestServer) Request(method, uri string, data interface{}, expectedCode int, responsePtr ...*http.Response) error {
var bodyReader io.Reader
if method == http.MethodPost || method == http.MethodPut {
values := structToURLValues(data)
@ -92,6 +92,11 @@ func (s *TestServer) Request(method, uri string, data interface{}, expectedCode
}
}
// If a response pointer was provided, fill it with the response data
if len(responsePtr) > 0 && responsePtr[0] != nil {
*responsePtr[0] = *w.Result()
}
return nil
}
@ -157,7 +162,7 @@ func Setup(t *testing.T) *TestServer {
databaseType = os.Getenv("OPENGIST_TEST_DB")
switch databaseType {
case "sqlite":
databaseDsn = "file:" + filepath.Join(homePath, "tmp", "opengist.db")
databaseDsn = "file:" + filepath.Join(homePath, "tmp", "opengist_test.db")
case "postgres":
databaseDsn = "postgres://postgres:opengist@localhost:5432/opengist_test"
case "mysql":