Skip to content

Commit

Permalink
feat: Maintaining audit logs (#3763)
Browse files Browse the repository at this point in the history
* Middleware

* logger middleware service layer

* updated files

* commented code

* updated files

* updated files

* updated files

* pr comments

* updated files

* updated files

* updated files

* refactoring

* removing spilled userAuth object

* refactoring

* updated files

* refactoring functions names

* wire gen

* making middleware more efficient

* adding status code in audit log middleware

* log fix

* refactoring

* refactoring and few fixes

* changed package + refactoring

* argocd assets added

* removed unnecessary code

* EOF error fix

* request payload place changed to be printed at last

---------

Co-authored-by: Prakash Kumar <prakash.kumar@devtron.ai>
  • Loading branch information
dhananjay0601 and prakash100198 committed Sep 1, 2023
1 parent 1b57820 commit d6c81b8
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 55 deletions.
6 changes: 5 additions & 1 deletion App.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"crypto/tls"
"fmt"
"github.com/devtron-labs/devtron/api/util"
"github.com/devtron-labs/devtron/client/telemetry"
"github.com/devtron-labs/devtron/otel"
"log"
Expand Down Expand Up @@ -54,6 +55,7 @@ type App struct {
serveTls bool
sessionManager2 *authMiddleware.SessionManager
OtelTracingService *otel.OtelTracingServiceImpl
loggingMiddleware util.LoggingMiddleware
}

func NewApp(router *router.MuxRouter,
Expand All @@ -64,6 +66,7 @@ func NewApp(router *router.MuxRouter,
pubsubClient *pubsub.PubSubClientServiceImpl,
sessionManager2 *authMiddleware.SessionManager,
posthogClient *telemetry.PosthogClient,
loggingMiddleware util.LoggingMiddleware,
) *App {
//check argo connection
//todo - check argo-cd version on acd integration installation
Expand All @@ -78,6 +81,7 @@ func NewApp(router *router.MuxRouter,
sessionManager2: sessionManager2,
posthogClient: posthogClient,
OtelTracingService: otel.NewOtelTracingServiceImpl(Logger),
loggingMiddleware: loggingMiddleware,
}
return app
}
Expand All @@ -94,7 +98,7 @@ func (app *App) Start() {
//authEnforcer := casbin2.Create()

server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: authMiddleware.Authorizer(app.sessionManager2, user.WhitelistChecker)(app.MuxRouter.Router)}

app.MuxRouter.Router.Use(app.loggingMiddleware.LoggingMiddleware)
app.MuxRouter.Router.Use(middleware.PrometheusMiddleware)
if tracerProvider != nil {
app.MuxRouter.Router.Use(otelmux.Middleware(otel.OTEL_ORCHESTRASTOR_SERVICE_NAME))
Expand Down
3 changes: 3 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/devtron-labs/devtron/api/team"
"github.com/devtron-labs/devtron/api/terminal"
"github.com/devtron-labs/devtron/api/user"
util5 "github.com/devtron-labs/devtron/api/util"
webhookHelm "github.com/devtron-labs/devtron/api/webhook/helm"
"github.com/devtron-labs/devtron/client/argocdServer"
"github.com/devtron-labs/devtron/client/argocdServer/application"
Expand Down Expand Up @@ -213,6 +214,8 @@ func InitializeApp() (*App, error) {
pipeline.GetDeploymentServiceTypeConfig,
pipeline.NewPipelineBuilderImpl,
wire.Bind(new(pipeline.PipelineBuilder), new(*pipeline.PipelineBuilderImpl)),
util5.NewLoggingMiddlewareImpl,
wire.Bind(new(util5.LoggingMiddleware), new(*util5.LoggingMiddlewareImpl)),
pipeline2.NewPipelineRestHandlerImpl,
wire.Bind(new(pipeline2.PipelineConfigRestHandler), new(*pipeline2.PipelineConfigRestHandlerImpl)),
router.NewPipelineRouterImpl,
Expand Down
1 change: 0 additions & 1 deletion api/appStore/deployment/AppStoreDeploymentRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func NewAppStoreDeploymentRouterImpl(appStoreDeploymentRestHandler AppStoreDeplo
}

func (router AppStoreDeploymentRouterImpl) Init(configRouter *mux.Router) {

configRouter.Path("/application/install").
HandlerFunc(router.appStoreDeploymentRestHandler.InstallApp).Methods("POST")

Expand Down
4 changes: 3 additions & 1 deletion api/dashboardEvent/DashboardTelemetryRouter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dashboardEvent

import "github.com/gorilla/mux"
import (
"github.com/gorilla/mux"
)

type DashboardTelemetryRouter interface {
Init(configRouter *mux.Router)
Expand Down
4 changes: 3 additions & 1 deletion api/deployment/DeploymentConfigRouter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package deployment

import "github.com/gorilla/mux"
import (
"github.com/gorilla/mux"
)

type DeploymentConfigRouter interface {
Init(configRouter *mux.Router)
Expand Down
4 changes: 3 additions & 1 deletion api/helm-app/HelmAppRouter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import "github.com/gorilla/mux"
import (
"github.com/gorilla/mux"
)

type HelmAppRouter interface {
InitAppListRouter(helmRouter *mux.Router)
Expand Down
1 change: 0 additions & 1 deletion api/k8s/application/k8sApplicationRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewK8sApplicationRouterImpl(k8sApplicationRestHandler K8sApplicationRestHan
}

func (impl *K8sApplicationRouterImpl) InitK8sApplicationRouter(k8sAppRouter *mux.Router) {

k8sAppRouter.Path("/resource/rotate").Queries("appId", "{appId}").
HandlerFunc(impl.k8sApplicationRestHandler.RotatePod).Methods("POST")

Expand Down
1 change: 0 additions & 1 deletion api/k8s/capacity/k8sCapacityRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func NewK8sCapacityRouterImpl(k8sCapacityRestHandler K8sCapacityRestHandler) *K8
}

func (impl *K8sCapacityRouterImpl) InitK8sCapacityRouter(k8sCapacityRouter *mux.Router) {

k8sCapacityRouter.Path("/cluster/list/raw").
HandlerFunc(impl.k8sCapacityRestHandler.GetClusterListRaw).Methods("GET")

Expand Down
1 change: 0 additions & 1 deletion api/router/ApplicationRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func NewApplicationRouterImpl(handler restHandler.ArgoApplicationRestHandler, lo
}

func (r ApplicationRouterImpl) initApplicationRouter(router *mux.Router) {

router.Path("/stream").
Queries("name", "{name}").
Methods("GET").
Expand Down
1 change: 0 additions & 1 deletion api/router/CommonRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func NewCommonRouterImpl(commonRestHandler restHandler.CommonRestHanlder) *Commo
return &CommonRouterImpl{commonRestHandler: commonRestHandler}
}
func (impl CommonRouterImpl) InitCommonRouter(router *mux.Router) {

router.Path("/checklist").
HandlerFunc(impl.commonRestHandler.GlobalChecklist).
Methods("GET")
Expand Down
1 change: 0 additions & 1 deletion api/router/ConfigMapRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func NewConfigMapRouterImpl(restHandler restHandler.ConfigMapRestHandler) *Confi
}

func (router ConfigMapRouterImpl) initConfigMapRouter(configRouter *mux.Router) {

configRouter.Path("/global/cm").
HandlerFunc(router.restHandler.CMGlobalAddUpdate).Methods("POST")
configRouter.Path("/environment/cm").
Expand Down
1 change: 0 additions & 1 deletion api/router/MigrateDbRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func NewMigrateDbRouterImpl(migrateDbRestHandler restHandler.MigrateDbRestHandle
return &MigrateDbRouterImpl{migrateDbRestHandler: migrateDbRestHandler}
}
func (impl MigrateDbRouterImpl) InitMigrateDbRouter(migrateRouter *mux.Router) {

migrateRouter.Path("/db").
HandlerFunc(impl.migrateDbRestHandler.SaveDbConfig).
Methods("POST")
Expand Down
8 changes: 3 additions & 5 deletions api/router/PProfRouter.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package router

import (
"github.com/devtron-labs/devtron/api/restHandler"
"github.com/gorilla/mux"
"go.uber.org/zap"
"github.com/devtron-labs/devtron/api/restHandler"
"github.com/gorilla/mux"
"go.uber.org/zap"
)

type PProfRouter interface {
Expand All @@ -24,7 +24,6 @@ func NewPProfRouter(logger *zap.SugaredLogger,
}

func (ppr PProfRouterImpl) initPProfRouter(router *mux.Router) {

router.HandleFunc("/", ppr.pprofRestHandler.Index)
router.HandleFunc("/cmdline", ppr.pprofRestHandler.Cmdline)
router.HandleFunc("/profile", ppr.pprofRestHandler.Profile)
Expand All @@ -37,4 +36,3 @@ func (ppr PProfRouterImpl) initPProfRouter(router *mux.Router) {
router.HandleFunc("/mutex", ppr.pprofRestHandler.Mutex)
router.HandleFunc("/allocs", ppr.pprofRestHandler.Allocs)
}

1 change: 0 additions & 1 deletion api/router/PipelineConfigRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func NewPipelineRouterImpl(restHandler app.PipelineConfigRestHandler,
pipelineHistoryRestHandler: pipelineHistoryRestHandler,
pipelineStatusTimelineRestHandler: pipelineStatusTimelineRestHandler,
}

}

func (router PipelineConfigRouterImpl) initPipelineConfigRouter(configRouter *mux.Router) {
Expand Down
1 change: 0 additions & 1 deletion api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter PipelineTriggerRouter, P
}

func (r MuxRouter) Init() {

r.Router.PathPrefix("/orchestrator/api/vi/pod/exec/ws").Handler(terminal.CreateAttachHandler("/orchestrator/api/vi/pod/exec/ws"))

r.Router.StrictSlash(true)
Expand Down
74 changes: 74 additions & 0 deletions api/util/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package util

import (
"bytes"
"github.com/devtron-labs/devtron/internal/middleware"
"github.com/devtron-labs/devtron/pkg/user"
"io"
"log"
"net/http"
"time"
)

type AuditLoggerDTO struct {
UrlPath string `json:"urlPath"`
UserEmail string `json:"userEmail"`
UpdatedOn time.Time `json:"updatedOn"`
QueryParams string `json:"queryParams"`
ApiResponseCode int `json:"apiResponseCode"`
RequestPayload []byte `json:"requestPayload"`
}

type LoggingMiddlewareImpl struct {
userService user.UserService
}

func NewLoggingMiddlewareImpl(userService user.UserService) *LoggingMiddlewareImpl {
return &LoggingMiddlewareImpl{
userService: userService,
}
}

type LoggingMiddleware interface {
LoggingMiddleware(next http.Handler) http.Handler
}

// LoggingMiddleware is a middleware function that logs the incoming request.
func (impl LoggingMiddlewareImpl) LoggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
d := middleware.NewDelegator(w, nil)

token := r.Header.Get("token")
userEmail, err := impl.userService.GetEmailFromToken(token)
if err != nil {
log.Printf("AUDIT_LOG: user does not exists")
}

// Read the request body into a buffer
var bodyBuffer bytes.Buffer
_, err = io.Copy(&bodyBuffer, r.Body)
if err != nil {
log.Printf("AUDIT_LOG: error reading request body for urlPath: %s queryParams: %s userEmail: %s", r.URL.Path, r.URL.Query().Encode(), userEmail)
}

// Restore the request body for downstream handlers
r.Body = io.NopCloser(&bodyBuffer)

auditLogDto := &AuditLoggerDTO{
UrlPath: r.URL.Path,
UserEmail: userEmail,
UpdatedOn: time.Now(),
QueryParams: r.URL.Query().Encode(),
RequestPayload: bodyBuffer.Bytes(),
}
// Call the next handler in the chain.
next.ServeHTTP(d, r)

auditLogDto.ApiResponseCode = d.Status()
LogRequest(auditLogDto)
})
}

func LogRequest(auditLogDto *AuditLoggerDTO) {
log.Printf("AUDIT_LOG: urlPath: %s, queryParams: %s,updatedBy: %s, updatedOn: %s, apiResponseCode: %d,requestPayload: %s", auditLogDto.UrlPath, auditLogDto.QueryParams, auditLogDto.UserEmail, auditLogDto.UpdatedOn, auditLogDto.ApiResponseCode, auditLogDto.RequestPayload)
}
1 change: 0 additions & 1 deletion cmd/external-app/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func (r *MuxRouter) Init() {
}
_, _ = writer.Write(b)
})

ssoLoginRouter := baseRouter.PathPrefix("/sso").Subrouter()
r.ssoLoginRouter.InitSsoLoginRouter(ssoLoginRouter)
teamRouter := baseRouter.PathPrefix("/team").Subrouter()
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ require (
github.com/go-resty/resty/v2 v2.7.0
github.com/gogo/protobuf v1.3.2
github.com/golang-jwt/jwt/v4 v4.4.2
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.9
github.com/google/go-github v17.0.0+incompatible
github.com/google/uuid v1.3.0
github.com/google/wire v0.3.0
github.com/google/wire v0.5.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/schema v1.1.0
github.com/gorilla/sessions v1.2.1
Expand Down Expand Up @@ -140,7 +141,6 @@ require (
github.com/go-xorm/xorm v0.7.9 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-github/v41 v41.0.0 // indirect
Expand Down Expand Up @@ -233,14 +233,12 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/exp v0.0.0-20220602145555-4a0574d9293f // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.101.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/euank/go-kmsg-parser v2.0.0+incompatible/go.mod h1:MhmAMZ8V4CYH4ybgdRwPr2TU5ThnS43puaKEMpja1uw=
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
Expand Down Expand Up @@ -557,8 +556,8 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/wire v0.3.0 h1:imGQZGEVEHpje5056+K+cgdO72p0LQv2xIIFXNGUf60=
github.com/google/wire v0.3.0/go.mod h1:i1DMg/Lu8Sz5yYl25iOdmc5CT5qusaa+zmRWs16741s=
github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8=
github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU=
github.com/googleapis/enterprise-certificate-proxy v0.2.0 h1:y8Yozv7SZtlU//QXbezB6QkpuE6jMD2/gfzk4AftXjs=
github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
Expand All @@ -568,7 +567,6 @@ github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0
github.com/googleapis/gax-go/v2 v2.6.0 h1:SXk3ABtQYDT/OH8jAyvEOQ58mgawq5C4o/4/89qN2ZU=
github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMdcIDwU/6+DDoY=
github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU=
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
Expand Down Expand Up @@ -793,13 +791,11 @@ github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.0.6/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-ieproxy v0.0.1 h1:qiyop7gCflfhwCzGyeT0gro3sF9AIg9HU98JORTkqfI=
github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E=
github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
Expand Down Expand Up @@ -1325,8 +1321,6 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1-0.20210830214625-1b1db11ec8f4/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1439,7 +1433,6 @@ golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -1624,8 +1617,6 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion internal/middleware/delegator.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func init() {
}
}

func newDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) delegator {
func NewDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) delegator {
d := &responseWriterDelegator{
ResponseWriter: w,
observeWriteHeader: observeWriteHeaderFunc,
Expand Down
2 changes: 1 addition & 1 deletion internal/middleware/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func PrometheusMiddleware(next http.Handler) http.Handler {
g := currentRequestGauge.WithLabelValues(path, method)
g.Inc()
defer g.Dec()
d := newDelegator(w, nil)
d := NewDelegator(w, nil)
next.ServeHTTP(d, r)
httpDuration.WithLabelValues(path, method, strconv.Itoa(d.Status())).Observe(time.Since(start).Seconds())
requestCounter.WithLabelValues(path, method, strconv.Itoa(d.Status())).Inc()
Expand Down
Loading

0 comments on commit d6c81b8

Please sign in to comment.