@@ -92,6 +92,8 @@ func (c *ClusterGatewayProxy) New() runtime.Object {
92
92
func (in * ClusterGatewayProxy ) Destroy () {}
93
93
94
94
func (c * ClusterGatewayProxy ) Connect (ctx context.Context , id string , options runtime.Object , r registryrest.Responder ) (http.Handler , error ) {
95
+ ts := time .Now ()
96
+
95
97
proxyOpts , ok := options .(* ClusterGatewayProxyOptions )
96
98
if ! ok {
97
99
return nil , fmt .Errorf ("invalid options object: %#v" , options )
@@ -161,6 +163,7 @@ func (c *ClusterGatewayProxy) Connect(ctx context.Context, id string, options ru
161
163
finishFunc : func (code int ) {
162
164
metrics .RecordProxiedRequestsByResource (proxyReqInfo .Resource , proxyReqInfo .Verb , code )
163
165
metrics .RecordProxiedRequestsByCluster (id , code )
166
+ metrics .RecordProxiedRequestsDuration (proxyReqInfo .Resource , proxyReqInfo .Verb , id , code , time .Since (ts ))
164
167
},
165
168
}, nil
166
169
}
@@ -197,7 +200,21 @@ var (
197
200
apiSuffix = "/proxy"
198
201
)
199
202
200
- func (p * proxyHandler ) ServeHTTP (writer http.ResponseWriter , request * http.Request ) {
203
+ type proxyResponseWriter struct {
204
+ http.ResponseWriter
205
+ statusCode int
206
+ }
207
+
208
+ func (in * proxyResponseWriter ) WriteHeader (statusCode int ) {
209
+ in .statusCode = statusCode
210
+ in .ResponseWriter .WriteHeader (statusCode )
211
+ }
212
+
213
+ func (p * proxyHandler ) ServeHTTP (_writer http.ResponseWriter , request * http.Request ) {
214
+ writer := & proxyResponseWriter {_writer , http .StatusOK }
215
+ defer func () {
216
+ p .finishFunc (writer .statusCode )
217
+ }()
201
218
cluster := p .clusterGateway
202
219
if cluster .Spec .Access .Credential == nil {
203
220
responsewriters .InternalError (writer , request , fmt .Errorf ("proxying cluster %s not support due to lacking credentials" , cluster .Name ))
0 commit comments