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