@@ -64,7 +64,7 @@ func (h *PrometheusServer) Initialize(_ context.Context, option map[string]inter
64
64
api map [string ]apiserver.APIConfig ) error {
65
65
h .option = option
66
66
h .openAPI = api
67
- h .listenIP = option ["listenIP" ].(string )
67
+ h .listenIP , _ = option ["listenIP" ].(string )
68
68
h .listenPort = uint32 (option ["listenPort" ].(int ))
69
69
// 连接数限制的配置
70
70
if raw , _ := option ["connLimit" ].(map [interface {}]interface {}); raw != nil {
@@ -234,14 +234,14 @@ func (h *PrometheusServer) process(req *restful.Request, rsp *restful.Response,
234
234
}
235
235
236
236
// preprocess 请求预处理
237
- func (h * PrometheusServer ) preprocess (req * restful.Request , rsp * restful.Response ) error {
237
+ func (h * PrometheusServer ) preprocess (req * restful.Request , _ * restful.Response ) error {
238
238
// 设置开始时间
239
239
req .SetAttribute ("start-time" , time .Now ())
240
240
return nil
241
241
}
242
242
243
243
// postProcess 请求后处理:统计
244
- func (h * PrometheusServer ) postProcess (req * restful.Request , rsp * restful.Response ) {
244
+ func (h * PrometheusServer ) postProcess (req * restful.Request , _ * restful.Response ) {
245
245
now := time .Now ()
246
246
247
247
// 接口调用统计
@@ -250,17 +250,15 @@ func (h *PrometheusServer) postProcess(req *restful.Request, rsp *restful.Respon
250
250
// 去掉最后一个"/"
251
251
path = strings .TrimSuffix (path , "/" )
252
252
}
253
- startTime := req .Attribute ("start-time" ).(time.Time )
254
-
255
- diff := now .Sub (startTime )
253
+ startTime , _ := req .Attribute ("start-time" ).(time.Time )
256
254
// 打印耗时超过1s的请求
257
- if diff > time .Second {
255
+ if diff := now . Sub ( startTime ); diff > time .Second {
258
256
log .Info ("[API-Server][Prometheus] handling time > 1s" ,
259
257
zap .String ("client-address" , req .Request .RemoteAddr ),
260
258
zap .String ("user-agent" , req .HeaderParameter ("User-Agent" )),
261
259
zap .String ("request-id" , req .HeaderParameter ("Request-Id" )),
262
260
zap .String ("method" , req .Request .Method ),
263
- zap .String ("url" , req . Request . URL . String () ),
261
+ zap .String ("url" , path ),
264
262
zap .Duration ("handling-time" , diff ),
265
263
)
266
264
}
0 commit comments