feat: dataReport 增加 disabled 开关,默认关闭埋点与上报
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -110,7 +110,8 @@ type GlobalCfgEx struct {
|
||||
AesKey string `yaml:"aesKey"` // 数据解密KEY
|
||||
} `yaml:"adCenter"`
|
||||
DataReport struct {
|
||||
Url string `yaml:"url"`
|
||||
Url string `yaml:"url"`
|
||||
Disabled bool `yaml:"disabled"`
|
||||
} `yaml:"dataReport"`
|
||||
LsjMediaConf struct {
|
||||
AppId string `yaml:"appId"`
|
||||
|
||||
@@ -43,6 +43,7 @@ adCenter:
|
||||
aesKey: "gD4+rmbX5TS5cLbb3wAN5uEAYp/1j4hkQrS9SzuSjc8"
|
||||
dataReport:
|
||||
url: "https://api.shuifeng.cc"
|
||||
disabled: true
|
||||
lsjMediaConf:
|
||||
appId: "430696"
|
||||
apiKey: "ed48e96ce490bc94bd5eb5133dd542d0"
|
||||
|
||||
@@ -74,8 +74,9 @@ func Run(args []string) {
|
||||
initData()
|
||||
ipstatsync.StartSync()
|
||||
dataReport.Init(dataReport.Config{
|
||||
ApiUrl: appg.Conf.DataReport.Url,
|
||||
RunMod: appg.Conf.RunMod,
|
||||
ApiUrl: appg.Conf.DataReport.Url,
|
||||
RunMod: appg.Conf.RunMod,
|
||||
Disabled: appg.Conf.DataReport.Disabled,
|
||||
})
|
||||
|
||||
initHttpServer()
|
||||
|
||||
@@ -428,6 +428,9 @@ func md5String(input string) string {
|
||||
}
|
||||
|
||||
func insertEvent(event dataReport.CommonField) {
|
||||
if !dataReport.Enabled() {
|
||||
return
|
||||
}
|
||||
b, _ := json.Marshal(event)
|
||||
if err := eventmod.InsertOneEvent(context.Background(), &eventmod.Event{
|
||||
EventId: event.EventID,
|
||||
|
||||
@@ -41,7 +41,15 @@ func GenerateGlobalEventID() string {
|
||||
return strings.ReplaceAll(uuid.New().String(), "-", "")
|
||||
}
|
||||
|
||||
// Enabled 当前是否允许上报:Disabled=true 或 ApiUrl 为空都视为关闭。
|
||||
func Enabled() bool {
|
||||
return !config.Disabled && strings.TrimSpace(config.ApiUrl) != ""
|
||||
}
|
||||
|
||||
func AsyncReport(eventData interface{}, retryCount int) {
|
||||
if !Enabled() {
|
||||
return
|
||||
}
|
||||
// TODO 后续可改成kafka异步处理
|
||||
godef.Go(func() {
|
||||
// 自动重试
|
||||
@@ -227,6 +235,9 @@ func JsonRawMessage(v interface{}) json.RawMessage {
|
||||
|
||||
// 批量上报事件
|
||||
func BatchReport(ctx context.Context, data interface{}) error {
|
||||
if !Enabled() {
|
||||
return nil
|
||||
}
|
||||
apiUrl := config.ApiUrl + "/api/eventTracking/batchReport.json"
|
||||
reqBody, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
||||
@@ -39,6 +39,10 @@ type sdkConfigResponse struct {
|
||||
|
||||
// StartSDKConfigCron 定时拉取 SDK 域名配置串,服务端只缓存并原样透传。
|
||||
func StartSDKConfigCron() {
|
||||
if !Enabled() {
|
||||
log.Info("dataReport disabled, skip SDK config cron")
|
||||
return
|
||||
}
|
||||
sdkConfigOnce.Do(func() {
|
||||
if err := RefreshSDKDomainConfig(); err != nil {
|
||||
log.Error("RefreshSDKDomainConfig first run fail", log.E(err))
|
||||
|
||||
@@ -12,8 +12,9 @@ type Response struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ApiUrl string `json:"apiUrl"`
|
||||
RunMod string `json:"runMod"` // 运行模式: dev/test/prod/release
|
||||
ApiUrl string `json:"apiUrl"`
|
||||
RunMod string `json:"runMod"` // 运行模式: dev/test/prod/release
|
||||
Disabled bool `json:"disabled"` // true 时跳过全部埋点上报与 SDK 配置拉取
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -81,8 +81,9 @@ func Run(args []string) {
|
||||
initData()
|
||||
initSeoPush()
|
||||
dataReport.Init(dataReport.Config{
|
||||
ApiUrl: webg.Conf.DataReport.Url,
|
||||
RunMod: webg.Conf.RunMod,
|
||||
ApiUrl: webg.Conf.DataReport.Url,
|
||||
RunMod: webg.Conf.RunMod,
|
||||
Disabled: webg.Conf.DataReport.Disabled,
|
||||
})
|
||||
|
||||
initHttpServer()
|
||||
|
||||
@@ -19,6 +19,9 @@ const (
|
||||
)
|
||||
|
||||
func Report() {
|
||||
if !dataReport.Enabled() {
|
||||
return
|
||||
}
|
||||
//防止重入
|
||||
if isRuining {
|
||||
return
|
||||
|
||||
+2
-1
@@ -58,7 +58,8 @@ type GlobalCfgEx struct {
|
||||
} `yaml:"playletMediaResourceDBCfg"`
|
||||
NewInnerStatUrl string `yaml:"newInnerStatUrl"`
|
||||
DataReport struct {
|
||||
Url string `yaml:"url"`
|
||||
Url string `yaml:"url"`
|
||||
Disabled bool `yaml:"disabled"`
|
||||
} `yaml:"dataReport"`
|
||||
NewPayCenter payCenter.Conf `yaml:"newPayCenter"`
|
||||
DataCenterBackflow struct {
|
||||
|
||||
Reference in New Issue
Block a user