Browse Source

优化日志

jiantaoli 4 years ago
parent
commit
2206d45d03
4 changed files with 74 additions and 72 deletions
  1. 55 47
      ads_handler.go
  2. 10 10
      adslib/addata/custom.go
  3. 5 5
      adslib/addata/xiaomi.go
  4. 4 10
      adslib/device/device.go

+ 55 - 47
ads_handler.go

@@ -66,6 +66,11 @@ func adsHandler(c *gin.Context) {
66 66
 	request.Parse(c)
67 67
 
68 68
 	log.Printf("%+v", request)
69
+
70
+	// 放这里主要为了拿到reqeust id做日志记录
71
+	dspInfo := utils.DspParam{}
72
+	dspInfo.Init()
73
+
69 74
 	advertiser := "xiaomi"
70 75
 	uaClient := request.UaClient
71 76
 	// 获取ua
@@ -144,7 +149,7 @@ func adsHandler(c *gin.Context) {
144 149
 
145 150
 	// 定制city code
146 151
 	cityCode, err := city.GetCityCode(ipInfo.City)
147
-	log.Infof("got city code: %d", cityCode)
152
+	log.WithField("request_id", dspInfo.RequestId).Infof("got city code: %d", cityCode)
148 153
 	if err != nil {
149 154
 		c.String(404, "get city code failed: %s", err)
150 155
 		return
@@ -164,12 +169,12 @@ func adsHandler(c *gin.Context) {
164 169
 		// 频率控制
165 170
 		freqControlConf, err := redis_data.GetFreqCrontolConf(request.ReqSource)
166 171
 		if err != nil {
167
-			log.Errorf("get freq control conf failed: %s", err)
172
+			log.WithField("request_id", dspInfo.RequestId).Errorf("get freq control conf failed: %s", err)
168 173
 			c.String(404, "get freq control conf failed: %s", err)
169 174
 			return
170 175
 		}
171 176
 
172
-		log.Infof("freq control conf: %+v", freqControlConf)
177
+		log.WithField("request_id", dspInfo.RequestId).Infof("freq control conf: %+v", freqControlConf)
173 178
 		hour, _ := strconv.Atoi(time.Now().Format("01"))
174 179
 		tmpControlInterval, ok := freqControlConf.GetControlTime(hour)
175 180
 		if ok {
@@ -187,7 +192,7 @@ func adsHandler(c *gin.Context) {
187 192
 	needControl := false
188 193
 	if request.ReqSource != "wzb_h5" && lastReqTime != 0 && time.Now().Unix()-lastReqTime < int64(freqControlInterval) {
189 194
 		// 需要凭空
190
-		log.Infof("need control: %d", lastReqTime)
195
+		log.WithField("request_id", dspInfo.RequestId).Infof("need control: %d", lastReqTime)
191 196
 		needControl = true
192 197
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_FREQ_0", cityCode)
193 198
 	} else {
@@ -197,7 +202,7 @@ func adsHandler(c *gin.Context) {
197 202
 	//### 检查是否是ip黑名单
198 203
 	isIpBlack, err := ads_checker.CheckBlackIp(ip)
199 204
 	if err != nil {
200
-		log.Errorf("check black ip failed: %s", err)
205
+		log.WithField("request_id", dspInfo.RequestId).Errorf("check black ip failed: %s", err)
201 206
 		c.String(404, "check black ip failed: %s", err)
202 207
 		return
203 208
 	}
@@ -209,7 +214,7 @@ func adsHandler(c *gin.Context) {
209 214
 	// 获取渠道的黑白性
210 215
 	reqChannelFlag, err := redis_data.GetChannelFlag(request.ReqSource, "ads_req")
211 216
 	if err != nil {
212
-		log.Errorf("get req channel flag failed: %s", err)
217
+		log.WithField("request_id", dspInfo.RequestId).Errorf("get req channel flag failed: %s", err)
213 218
 		c.String(404, "get req channel flag failed: %s", err)
214 219
 		return
215 220
 	}
@@ -241,12 +246,12 @@ func adsHandler(c *gin.Context) {
241 246
 		randomNum := 3
242 247
 		deviceConf, realRedisKey, err := device.GetMiDeviceConf(ip, randomNum, specialDeviceNum)
243 248
 		if err != nil {
244
-			log.Errorf("get mi device conf failed: %s", err)
249
+			log.WithField("request_id", dspInfo.RequestId).Errorf("get mi device conf failed: %s", err)
245 250
 			c.String(404, "get mi device conf failed: %s", err)
246 251
 			return
247 252
 		}
248 253
 		if deviceConf != nil {
249
-			log.Infof("use cache imei: %+v", deviceConf)
254
+			log.WithField("request_id", dspInfo.RequestId).Infof("use cache imei: %+v", deviceConf)
250 255
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_CACHE", cityCode) // 通过缓存请求
251 256
 			imei = deviceConf.Imei
252 257
 			uaClient = deviceConf.Ua
@@ -266,7 +271,7 @@ func adsHandler(c *gin.Context) {
266 271
 				fakeImei := ""
267 272
 				fakeDeviceConf, leftCnt, err := device.GetDailyFakeDeviceConfByCityCode(cityCode)
268 273
 				if err != nil {
269
-					log.Errorf("get device conf failed: %s", err)
274
+					log.WithField("request_id", dspInfo.RequestId).Errorf("get device conf failed: %s", err)
270 275
 					c.String(404, "get device conf failed: %s", err)
271 276
 					return
272 277
 				}
@@ -278,7 +283,7 @@ func adsHandler(c *gin.Context) {
278 283
 					device.SetAdsTagLog(advertiser, request.ReqSource, "DS_REPL", cityCode)
279 284
 					err := device.SetMiDeviceConf(realRedisKey, *fakeDeviceConf)
280 285
 					if err != nil {
281
-						log.Errorf("set mi device conf failed: %s", err)
286
+						log.WithField("request_id", dspInfo.RequestId).Errorf("set mi device conf failed: %s", err)
282 287
 					}
283 288
 					imei = fakeDeviceConf.Imei
284 289
 					uaClient = fakeDeviceConf.Ua
@@ -325,34 +330,37 @@ func adsHandler(c *gin.Context) {
325 330
 		// 解码ua_client
326 331
 		uaClient, _ = url.QueryUnescape(uaClient)
327 332
 	} else if request.IsMiDevice() {
328
-		log.Info("real mi")
333
+		log.WithField("request_id", dspInfo.RequestId).Info("real mi")
329 334
 		device.SetAdsTagLog(advertiser, request.ReqSource, "DS_MI_REAL", cityCode) // 是小米设备
330 335
 		userFlag = 3
331 336
 		sendPhoneType = 1
332 337
 	}
333 338
 
334 339
 	// 检查下,替换后的设备是否是黑名单, 再次检查, 防止放入cache后, 新增了黑名单
335
-	isBlackImei, err := device.CheckIsBlackImei(imei, false)
340
+	checkImei := imei
341
+	// 替换过的imei从redis取的, 都是md5后的, 不需要再md5
342
+	if replaceFlag != 1 {
343
+		checkImei = utils.Md5(imei)
344
+	}
345
+	isBlackImei, err := device.CheckIsBlackImei(checkImei)
336 346
 	if err != nil {
337
-		log.Errorf("get device conf failed: %s", err)
347
+		log.WithField("request_id", dspInfo.RequestId).Errorf("get device conf failed: %s", err)
338 348
 		c.String(404, "get device conf failed: %s", err)
339 349
 		return
340 350
 	}
341 351
 
342
-	log.Tracef("replace flag: %d", replaceFlag)
352
+	log.WithField("request_id", dspInfo.RequestId).Tracef("replace flag: %d", replaceFlag)
343 353
 	if isBlackImei {
344 354
 		if replaceFlag == 1 {
345
-			log.Trace("replace")
355
+			log.WithField("request_id", dspInfo.RequestId).Trace("replace")
346 356
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI_REPLACE", cityCode)
347 357
 		} else {
348
-			log.Trace("not replace")
358
+			log.WithField("request_id", dspInfo.RequestId).Trace("not replace")
349 359
 			device.SetAdsTagLog(advertiser, request.ReqSource, "DS_BLACK_IMEI", cityCode)
350 360
 		}
351 361
 	}
352 362
 
353 363
 	// 组装公共的dsp_info
354
-	dspInfo := utils.DspParam{}
355
-	dspInfo.Init()
356 364
 	dspInfo.DspCityCode = cityCode
357 365
 	dspInfo.Imei = imei
358 366
 	dspInfo.OriginImei = originImei
@@ -379,12 +387,12 @@ func adsHandler(c *gin.Context) {
379 387
 	dspInfo.RealReqSource = request.ReqSource
380 388
 	dspInfo.SendPhoneType = sendPhoneType
381 389
 	md5Imei := imei
382
-	if dspInfo.ReplaceFlag == 0 {
383
-		md5Imei = utils.Md5(imei)
390
+	if dspInfo.OriginImei != "" {
391
+		md5Imei = utils.Md5(dspInfo.OriginImei)
384 392
 	}
385 393
 
386 394
 	dspInfo.RealMd5Imei = md5Imei
387
-	log.Infof("dsp: %+v", dspInfo)
395
+	log.WithField("request_id", dspInfo.RequestId).Infof("dsp: %+v", dspInfo)
388 396
 	//ads_item = None
389 397
 	//xiaomi_response = []
390 398
 	hour, _ := strconv.Atoi(time.Now().Format("01"))
@@ -397,7 +405,7 @@ func adsHandler(c *gin.Context) {
397 405
 		}
398 406
 	}
399 407
 
400
-	log.Infof("can request: %t", canRequest)
408
+	log.WithField("request_id", dspInfo.RequestId).Infof("can request: %t", canRequest)
401 409
 
402 410
 	var adData *addata.AdData
403 411
 
@@ -405,11 +413,11 @@ func adsHandler(c *gin.Context) {
405 413
 	if canRequest && !isBlackImei && reqChannelFlag.ChannelFlag == 1 && flowFlag == 1 && !isIpBlack && advertiser == "xiaomi" && request.ReqSource != "" && !needControl && (replaceFlag == 1 || request.IsMiDevice()) {
406 414
 		adData, err = addata.GetAdsInfos(&dspInfo, advertiser)
407 415
 		if err != nil {
408
-			log.Errorf("get mi ad data failed: %s", err)
416
+			log.WithField("request_id", dspInfo.RequestId).Errorf("get mi ad data failed: %s", err)
409 417
 			c.String(404, "get mi ad data failed: %s", err)
410 418
 			return
411 419
 		}
412
-		log.Infof("get mi ads data: %+v", adData)
420
+		log.WithField("request_id", dspInfo.RequestId).Infof("get mi ads data: %+v", adData)
413 421
 	}
414 422
 
415 423
 	canMixFlag := 1
@@ -417,7 +425,7 @@ func adsHandler(c *gin.Context) {
417 425
 	response := Response{}
418 426
 	response.Msg = "ok"
419 427
 	if adData != nil && len(adData.TargetAddition) > 1 {
420
-		log.Infof("add target js order")
428
+		log.WithField("request_id", dspInfo.RequestId).Infof("add target js order")
421 429
 		xiaomiResponseFlag = 1
422 430
 		realTarget := ""
423 431
 		if adData.Target != "" {
@@ -432,11 +440,11 @@ func adsHandler(c *gin.Context) {
432 440
 		adData.Target = realTarget
433 441
 		adData.JsOrderId, err = redis_data.GetMinScriptOrderByAdv(advertiser)
434 442
 		if err != nil {
435
-			log.Errorf("get min script order by adv failed: %s", err)
443
+			log.WithField("request_id", dspInfo.RequestId).Errorf("get min script order by adv failed: %s", err)
436 444
 			c.String(404, "get min script order by adv failed: %s", err)
437 445
 			return
438 446
 		}
439
-		log.Infof("got min script order: %d", adData.JsOrderId)
447
+		log.WithField("request_id", dspInfo.RequestId).Infof("got min script order: %d", adData.JsOrderId)
440 448
 		adData.UserAgent = uaClient
441 449
 
442 450
 		if dspInfo.ReqSource == "kuxin" && adData.Target != "" {
@@ -452,11 +460,11 @@ func adsHandler(c *gin.Context) {
452 460
 		// // 判断这个渠道是否要去融合和融合的流量占比
453 461
 		// mixChannelFlag, err := redis_data.GetChannelFlag(dspInfo.ReqSource, "ads_mix")
454 462
 		// if err != nil {
455
-		// 	log.Errorf("get device conf failed: %s", err)
463
+		// 	log.WithField("request_id", dspInfo.RequestId).Errorf("get device conf failed: %s", err)
456 464
 		// 	c.String(404, "get device conf failed: %s", err)
457 465
 		// 	return
458 466
 		// }
459
-		flowRandomNum = rand.Intn(100)
467
+		// flowRandomNum = rand.Intn(100)
460 468
 		//isOverFlow := false
461 469
 		//if flowRandomNum > mixChannelFlag.Weigth {
462 470
 		//	isOverFlow = true
@@ -481,25 +489,25 @@ func adsHandler(c *gin.Context) {
481 489
 				serverActionResponse["server_video_timer"] = 1
482 490
 			}
483 491
 		}
484
-		log.Infof("server action response: %+v", serverActionResponse)
492
+		log.WithField("request_id", dspInfo.RequestId).Infof("server action response: %+v", serverActionResponse)
485 493
 		// 增加跟随订单
486 494
 		if len(adData.TargetAddition) == 2 && serverActionResponse["server_video_finish"] == 1 && (dspInfo.ReqSource == "kuxin" || dspInfo.ReqSource == "zhiku") {
487
-			log.Infof("add more order")
495
+			log.WithField("request_id", dspInfo.RequestId).Infof("add more order")
488 496
 			adData, err = addata.CombineOrderBy(adData, &dspInfo)
489 497
 			if err != nil {
490
-				log.Errorf("combine order failed: %s", err)
498
+				log.WithField("request_id", dspInfo.RequestId).Errorf("combine order failed: %s", err)
491 499
 				c.String(404, "combine order failed: %s", err.Error())
492 500
 				return
493 501
 			}
494
-			log.Infof("get custom order: %+v", adData)
502
+			log.WithField("request_id", dspInfo.RequestId).Infof("get custom order: %+v", adData)
495 503
 		}
496 504
 
497 505
 		//# 检查最后是否有click
498
-		log.Infof("check ads item new: %+v", adData)
506
+		log.WithField("request_id", dspInfo.RequestId).Infof("check ads item new: %+v", adData)
499 507
 
500 508
 		for _, targetAddition := range adData.TargetAddition {
501 509
 			if targetAddition.Type == "CLICK" || targetAddition.Type == "VIDEO_TIMER" {
502
-				log.Infof("can't mix, targetAddition: %+v", targetAddition)
510
+				log.WithField("request_id", dspInfo.RequestId).Infof("can't mix, targetAddition: %+v", targetAddition)
503 511
 				canMixFlag = 0
504 512
 				break
505 513
 			}
@@ -507,7 +515,7 @@ func adsHandler(c *gin.Context) {
507 515
 
508 516
 		if request.NewAdsFlag == 0 {
509 517
 			response.AdData = *adData
510
-			log.Infof("update response: +%v", response)
518
+			log.WithField("request_id", dspInfo.RequestId).Infof("update response: +%v", response)
511 519
 		} else {
512 520
 			jsonBytes, err := json.Marshal(*adData)
513 521
 			if err != nil {
@@ -519,7 +527,7 @@ func adsHandler(c *gin.Context) {
519 527
 		}
520 528
 	}
521 529
 
522
-	log.Infof("can mix: %d, xiaomi rsp flag: %d", canMixFlag, xiaomiResponseFlag)
530
+	log.WithField("request_id", dspInfo.RequestId).Infof("can mix: %d, xiaomi rsp flag: %d", canMixFlag, xiaomiResponseFlag)
523 531
 	if canMixFlag == 1 {
524 532
 		response.Result = 2
525 533
 		response.Msg = "no ads"
@@ -536,7 +544,7 @@ func adsHandler(c *gin.Context) {
536 544
 				c.String(404, "get custom ads info failed: %s", err.Error())
537 545
 				return
538 546
 			}
539
-			log.Infof("dingtou: %+v", customAdData)
547
+			log.WithField("request_id", dspInfo.RequestId).Infof("dingtou: %+v", customAdData)
540 548
 
541 549
 			// 定投没有就跑其他的
542 550
 			if customAdData == nil {
@@ -554,7 +562,7 @@ func adsHandler(c *gin.Context) {
554 562
 			if customAdData != nil && (shortMessage == "ads_vast_response" || shortMessage == "ads_tt_thirds") {
555 563
 				adDataBytes, err := json.Marshal(*customAdData)
556 564
 				if err != nil {
557
-					log.Errorf("marshal adData failed: %s\n", err)
565
+					log.WithField("request_id", dspInfo.RequestId).Errorf("marshal adData failed: %s\n", err)
558 566
 				}
559 567
 				grayLogData := struct {
560 568
 					Ip           string
@@ -606,7 +614,7 @@ func adsHandler(c *gin.Context) {
606 614
 
607 615
 					adDataBytes, err := json.Marshal(lastAdData)
608 616
 					if err != nil {
609
-						log.Errorf("marshal adData failed: %s", err)
617
+						log.WithField("request_id", dspInfo.RequestId).Errorf("marshal adData failed: %s", err)
610 618
 					}
611 619
 					grayLogData := struct {
612 620
 						ShortMessage string `json:"short_message"`
@@ -617,7 +625,7 @@ func adsHandler(c *gin.Context) {
617 625
 					}
618 626
 
619 627
 					graylog.Log(grayLogData)
620
-					log.Infof("replace addata: %+v", lastAdData)
628
+					log.WithField("request_id", dspInfo.RequestId).Infof("replace addata: %+v", lastAdData)
621 629
 					customAdData = &lastAdData
622 630
 				}
623 631
 			}
@@ -627,19 +635,19 @@ func adsHandler(c *gin.Context) {
627 635
 					response.Result = 0
628 636
 					response.Msg = "ok"
629 637
 
630
-					log.Infof("rsp1: %+v", customAdData)
638
+					log.WithField("request_id", dspInfo.RequestId).Infof("rsp1: %+v", customAdData)
631 639
 					jsonBytes, err := json.Marshal(customAdData)
632 640
 					if err != nil {
633 641
 						c.String(404, "marsha custom addata failed: %s", err.Error())
634 642
 						return
635 643
 					}
636
-					log.Infof("rsp1: %s", jsonBytes)
644
+					log.WithField("request_id", dspInfo.RequestId).Infof("rsp1: %s", jsonBytes)
637 645
 					encryptData, _ := encrypt.Encrypt(jsonBytes, []byte(adslib.GetConf().SecretKey))
638 646
 					response.AdsResult = encryptData
639 647
 
640
-					log.Infof("encrypt: %s", encryptData)
648
+					log.WithField("request_id", dspInfo.RequestId).Infof("encrypt: %s", encryptData)
641 649
 					s, err := encrypt.Decrypt(encryptData, []byte(adslib.GetConf().SecretKey))
642
-					log.Info(s, err)
650
+					log.WithField("request_id", dspInfo.RequestId).Info(s, err)
643 651
 
644 652
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
645 653
 					rspBytes, err := json.Marshal(response)
@@ -647,7 +655,7 @@ func adsHandler(c *gin.Context) {
647 655
 						c.String(404, "marshal Response failed: %s", err.Error())
648 656
 						return
649 657
 					}
650
-					log.Infof("rsp1: %s", rspBytes)
658
+					log.WithField("request_id", dspInfo.RequestId).Infof("rsp1: %s", rspBytes)
651 659
 					c.String(200, string(rspBytes))
652 660
 					return
653 661
 				} else {
@@ -676,6 +684,6 @@ func adsHandler(c *gin.Context) {
676 684
 		graylog.ReportGrayLog(request, dspInfo, 0, 0)
677 685
 	}
678 686
 	device.SetAdsTagLog(advertiser, dspInfo.ReqSource, "DS_REQ", cityCode) // 所有请求
679
-	log.Infof("rsp3: %s", rspBytes)
687
+	log.WithField("request_id", dspInfo.RequestId).Infof("rsp3: %s", rspBytes)
680 688
 	c.String(200, string(rspBytes))
681 689
 }

+ 10 - 10
adslib/addata/custom.go

@@ -147,14 +147,14 @@ func getNeedDispatchCount(adData *redis_data.AdOrderInfo) (int, error) {
147 147
 func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHasFlag int) (*AdData, error) {
148 148
 	order, err := GetOneAds(dsp, orderType, fixFlag)
149 149
 	if err != nil {
150
-		log.Errorf("get one ads failed: %s", err)
150
+		log.WithField("request_id", dsp.RequestId).Errorf("get one ads failed: %s", err)
151 151
 		return nil, err
152 152
 	}
153 153
 	if order == nil {
154 154
 		return nil, nil
155 155
 	}
156 156
 
157
-	log.Infof("begin got custom ad info, xiaomi has flag: %d", xiaomiHasFlag)
157
+	log.WithField("request_id", dsp.RequestId).Infof("begin got custom ad info, xiaomi has flag: %d", xiaomiHasFlag)
158 158
 	if xiaomiHasFlag == 1 {
159 159
 		if strings.Index(order.Title, "_ios") > 0 {
160 160
 			return nil, nil
@@ -181,7 +181,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
181 181
 
182 182
 	redis_data.SetPlanDispatchCount(order.OrderID, "show", needDispatchCnt, curTime)
183 183
 
184
-	log.Infof("all count: %d, over kpi: %d, show kpi: %d", needDispatchCnt, finishShowCnt, order.ShowKpi)
184
+	log.WithField("request_id", dsp.RequestId).Infof("all count: %d, over kpi: %d, show kpi: %d", needDispatchCnt, finishShowCnt, order.ShowKpi)
185 185
 	// 计算曲线比例
186 186
 	rate := float32(order.ShowKpi) / float32(needDispatchCnt)
187 187
 
@@ -195,7 +195,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
195 195
 	if err != nil {
196 196
 		return nil, err
197 197
 	}
198
-	log.Infof("line value: %d, rate: %f", lineValue, rate)
198
+	log.WithField("request_id", dsp.RequestId).Infof("line value: %d, rate: %f", lineValue, rate)
199 199
 
200 200
 	// 当前分钟需要放出去的数量
201 201
 	curMinuteNeedDispatchCnt := int(float32(lineValue) * rate)
@@ -205,11 +205,11 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
205 205
 
206 206
 	redis_data.SetOrderPlanDispatchCount(order.OrderID, "show", curMinuteNeedDispatchCnt, curTime)
207 207
 
208
-	log.Infof("tt thirds: %+v", order)
208
+	log.WithField("request_id", dsp.RequestId).Infof("tt thirds: %+v", order)
209 209
 	// 获取当前分钟已经完成的下发
210 210
 	curMinuteFinishedDispatchCnt, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
211 211
 
212
-	log.Infof("o value: %d, w value: %d", curMinuteFinishedDispatchCnt, curMinuteNeedDispatchCnt)
212
+	log.WithField("request_id", dsp.RequestId).Infof("o value: %d, w value: %d", curMinuteFinishedDispatchCnt, curMinuteNeedDispatchCnt)
213 213
 	if curMinuteFinishedDispatchCnt < curMinuteNeedDispatchCnt {
214 214
 		data := AdData{
215 215
 			Duration:  5,
@@ -235,7 +235,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
235 235
 		if strings.Index(order.Title, "_ios") != -1 {
236 236
 			iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
237 237
 			if err != nil {
238
-				log.Errorf("get ios ua imei failed: %s", err)
238
+				log.WithField("request_id", dsp.RequestId).Errorf("get ios ua imei failed: %s", err)
239 239
 				return nil, err
240 240
 			}
241 241
 			if iosUa != "" {
@@ -270,7 +270,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
270 270
 			if r < 40 && xiaomiHasFlag == 0 {
271 271
 				iosImei, iosUa, err := redis_data.GetIosUaImei(dsp.Ip)
272 272
 				if err != nil {
273
-					log.Errorf("get ios ua imei failed: %s", err)
273
+					log.WithField("request_id", dsp.RequestId).Errorf("get ios ua imei failed: %s", err)
274 274
 					return nil, err
275 275
 				}
276 276
 				if iosUa != "" {
@@ -320,7 +320,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
320 320
 
321 321
 		r := rand.Intn(1000)
322 322
 		clickRate := int(float32(order.ClickKpi) / float32(order.ShowKpi) * 1000)
323
-		log.Infof("rand: %d, rate: %d", r, clickRate)
323
+		log.WithField("request_id", dsp.RequestId).Infof("rand: %d, rate: %d", r, clickRate)
324 324
 		if r < clickRate {
325 325
 			//下发点击
326 326
 			addi = genMonitorAction("CLICK", order.Title, dsp.ReqSource, clickUrl)
@@ -328,7 +328,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
328 328
 			md5Skip := utils.Md5(targetUrl)
329 329
 			_, err = redis_data.IncrFinishedDispatchCount(order.OrderID, "click", 1, curTime)
330 330
 			if err != nil {
331
-				log.Errorf("incr finished dispatch count failed: %s", err)
331
+				log.WithField("request_id", dsp.RequestId).Errorf("incr finished dispatch count failed: %s", err)
332 332
 			}
333 333
 			realTarget := adslib.GetConf().Host + fmt.Sprintf("?action=LOADING&req_source=%s&advertiser=%s&skip=%s&skip_other=%s",
334 334
 				dsp.ReqSource, order.Title, "", md5Skip)

+ 5 - 5
adslib/addata/xiaomi.go

@@ -190,7 +190,7 @@ func GetAdsInfos(dsp *utils.DspParam, advertiser string) (*AdData, error) {
190 190
 		target := html.UnescapeString(target)
191 191
 		targetParseUrl, err := url.Parse(target)
192 192
 		if err != nil {
193
-			log.Errorf("parse url failed, url: %s, err: %s", target, err)
193
+			log.WithField("request_id", dsp.RequestId).Errorf("parse url failed, url: %s, err: %s", target, err)
194 194
 			continue
195 195
 		}
196 196
 
@@ -315,11 +315,11 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
315 315
 
316 316
 	clickChannelFlag, err := redis_data.GetChannelFlag(dsp.ReqSource, "ads_click")
317 317
 	if err != nil {
318
-		log.Errorf("get ads_click channel flag failed: %s", err)
318
+		log.WithField("request_id", dsp.RequestId).Errorf("get ads_click channel flag failed: %s", err)
319 319
 		return nil, err
320 320
 	}
321 321
 
322
-	log.Tracef("click channel flag: %+v\n", clickChannelFlag)
322
+	log.WithField("request_id", dsp.RequestId).Tracef("click channel flag: %+v\n", clickChannelFlag)
323 323
 
324 324
 	clickRandom := rand.Intn(100)
325 325
 	needClick := false
@@ -461,7 +461,7 @@ func CombineLastAdsInfos(dsp *utils.DspParam, advertiser string, gotoUrls []stri
461 461
 
462 462
 		canReport, err := redis_data.GetDeviceIpReport(dsp.Imei, dsp.Ip)
463 463
 		if err != nil {
464
-			log.Errorf("get device ip report failed: %s", err)
464
+			log.WithField("request_id", dsp.RequestId).Errorf("get device ip report failed: %s", err)
465 465
 			return nil, err
466 466
 		}
467 467
 
@@ -520,7 +520,7 @@ func genAdsAction(urls []string, advertiser string,
520 520
 		lastUrls = append(urls, reportUrl)
521 521
 	}
522 522
 
523
-	log.Tracef("action: %s, all send: %d,  all show: %d, control: +%v %+v %t\n", action, allSendNum, allShowNum, flowControlConf, lastUrls, needControl)
523
+	log.WithField("request_id", dsp.RequestId).Tracef("action: %s, all send: %d,  all show: %d, control: +%v %+v %t\n", action, allSendNum, allShowNum, flowControlConf, lastUrls, needControl)
524 524
 
525 525
 	if len(lastUrls) == 0 {
526 526
 		duration = 0

+ 4 - 10
adslib/device/device.go

@@ -7,7 +7,6 @@ import (
7 7
 	log "github.com/sirupsen/logrus"
8 8
 	"math/rand"
9 9
 	"miads/adslib/ads_redis"
10
-	"miads/adslib/utils"
11 10
 	"strconv"
12 11
 	"strings"
13 12
 	"time"
@@ -151,7 +150,7 @@ func GetDailyFakeDeviceConfByCityCode(cityCode int) (*DeviceConf, int, error) {
151 150
 			continue
152 151
 		}
153 152
 
154
-		isBlackItem, err := CheckIsBlackImei(d.Imei, false)
153
+		isBlackItem, err := CheckIsBlackImei(d.Imei)
155 154
 		if err != nil {
156 155
 			continue
157 156
 		}
@@ -182,17 +181,12 @@ func GetDailyFakeDeviceConfByCityCode(cityCode int) (*DeviceConf, int, error) {
182 181
 }
183 182
 
184 183
 // 检查是否是黑名单
185
-func CheckIsBlackImei(imei string, needMd5 bool) (bool, error) {
184
+func CheckIsBlackImei(imei string) (bool, error) {
186 185
 	conn := ads_redis.RedisConn.Get()
187 186
 	defer conn.Close()
188 187
 
189
-	checkImei := imei
190
-	if needMd5 {
191
-		checkImei = utils.Md5(imei)
192
-	}
193
-
194
-	redisKey := "ads_black_device_" + checkImei[0:2]
195
-	isBlackImei, err := redis.Bool(conn.Do("SISMEMBER", redisKey, checkImei))
188
+	redisKey := "ads_black_device_" + imei[0:2]
189
+	isBlackImei, err := redis.Bool(conn.Do("SISMEMBER", redisKey, imei))
196 190
 	if err != nil {
197 191
 		return false, err
198 192
 	}