ilm 策略生成相关函数测试通过

This commit is contained in:
zhangkun9038@dingtalk.com 2025-03-30 19:54:38 +08:00
parent 14810ba8c0
commit 2d0f44fb05
2 changed files with 7 additions and 5 deletions

View File

@ -586,6 +586,7 @@ func ensureILMPolicy(client *http.Client, esConfig cfg.ElasticsearchConfig, poli
fmt.Println("[ILM Policy] max_docs not set in NormalRollover, skipping max_docs in rollover") fmt.Println("[ILM Policy] max_docs not set in NormalRollover, skipping max_docs in rollover")
} }
warmDays, coldDays, deleteDays := NonLinearCoolingModel(daysDiff, period, dataConfig.CoolingModelConfig)
policy := map[string]interface{}{ policy := map[string]interface{}{
"policy": map[string]interface{}{ "policy": map[string]interface{}{
"phases": map[string]interface{}{ "phases": map[string]interface{}{
@ -598,7 +599,7 @@ func ensureILMPolicy(client *http.Client, esConfig cfg.ElasticsearchConfig, poli
}, },
}, },
"warm": map[string]interface{}{ "warm": map[string]interface{}{
"min_age": fmt.Sprintf("%dd", dataConfig.NormalPhases["warm"]), "min_age": fmt.Sprintf("%dd", warmDays), // 使用冷却模型计算的 warmDays
"actions": map[string]interface{}{ "actions": map[string]interface{}{
"allocate": map[string]interface{}{ "allocate": map[string]interface{}{
"include": map[string]string{"_tier_preference": "data_warm"}, "include": map[string]string{"_tier_preference": "data_warm"},
@ -606,7 +607,7 @@ func ensureILMPolicy(client *http.Client, esConfig cfg.ElasticsearchConfig, poli
}, },
}, },
"cold": map[string]interface{}{ "cold": map[string]interface{}{
"min_age": fmt.Sprintf("%dd", dataConfig.NormalPhases["cold"]), "min_age": fmt.Sprintf("%dd", coldDays), // 使用冷却模型计算的 coldDays
"actions": map[string]interface{}{ "actions": map[string]interface{}{
"allocate": map[string]interface{}{ "allocate": map[string]interface{}{
"include": map[string]string{"_tier_preference": "data_cold"}, "include": map[string]string{"_tier_preference": "data_cold"},
@ -614,7 +615,7 @@ func ensureILMPolicy(client *http.Client, esConfig cfg.ElasticsearchConfig, poli
}, },
}, },
"delete": map[string]interface{}{ "delete": map[string]interface{}{
"min_age": fmt.Sprintf("%dd", retentionDays), "min_age": fmt.Sprintf("%dd", deleteDays), // 使用冷却模型计算的 deleteDays
"actions": map[string]interface{}{ "actions": map[string]interface{}{
"delete": map[string]interface{}{}, "delete": map[string]interface{}{},
}, },
@ -649,10 +650,11 @@ func ensureILMPolicy(client *http.Client, esConfig cfg.ElasticsearchConfig, poli
} }
// 创建或更新策略 // 创建或更新策略
policyData, err := json.Marshal(policy) policyData, err := json.MarshalIndent(policy, "", " ")
if err != nil { if err != nil {
return fmt.Errorf("failed to marshal ILM policy: %v", err) return fmt.Errorf("failed to marshal ILM policy: %v", err)
} }
fmt.Printf("[ILM Policy] Printing ILM policy to console:\n%s\n", string(policyData))
req, err := http.NewRequest("PUT", policyURL, bytes.NewBuffer(policyData)) req, err := http.NewRequest("PUT", policyURL, bytes.NewBuffer(policyData))
if err != nil { if err != nil {
return fmt.Errorf("failed to create ILM policy request: %v", err) return fmt.Errorf("failed to create ILM policy request: %v", err)

View File

@ -186,7 +186,7 @@ func (s *OkxPublicDataService) GetCandles(params CandlesRequest) ([]*Candle, err
if err != nil { if err != nil {
return nil, err return nil, err
} }
fmt.Printf("Response Body: %s\n", string(body)) //fmt.Printf("Response Body: %s\n", string(body))
// 重新设置resp.Body以便后续解码 // 重新设置resp.Body以便后续解码
resp.Body = io.NopCloser(bytes.NewBuffer(body)) resp.Body = io.NopCloser(bytes.NewBuffer(body))