From f0814c40bca8f37e529dea4b942018472684668d Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Mon, 10 Mar 2025 20:41:28 +0800 Subject: [PATCH] up --- Dockerfile | 5 +++++ config/config.go | 2 +- config/config.json | 2 +- fluentd-deployment.yaml | 8 ++++++++ okx/candleList.go | 9 ++++----- okx/publicApiService.go | 31 +++---------------------------- test/okxAli/candleList_test.go | 2 +- 7 files changed, 23 insertions(+), 36 deletions(-) create mode 100644 Dockerfile create mode 100644 fluentd-deployment.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..92c5bcf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ + +<<<<<<< HEAD +======= +RUN fluent-gem install fluent-plugin-elasticsearch fluent-plugin-rewrite-tag-filter +>>>>>>> Snippet diff --git a/config/config.go b/config/config.go index 41adb8f..88d7fb7 100644 --- a/config/config.go +++ b/config/config.go @@ -6,7 +6,7 @@ import ( ) type Config struct { - ElasticsearchURL string `json:"elasticsearch_url"` + FluentdURL string `json:"fluentdURL_url"` } // LoadConfig 从指定路径加载配置文件 diff --git a/config/config.json b/config/config.json index 5f8eb60..568691f 100644 --- a/config/config.json +++ b/config/config.json @@ -1,5 +1,5 @@ { - "elasticsearch_url": "http://fluentd.k8s.xunlang.home" + "fluentdURL_url": "http://fluentd.k8s.xunlang.home" } diff --git a/fluentd-deployment.yaml b/fluentd-deployment.yaml new file mode 100644 index 0000000..a187c17 --- /dev/null +++ b/fluentd-deployment.yaml @@ -0,0 +1,8 @@ + + initContainers: + - name: install-rewrite-tag-filter + image: your-fluentd-image:version + command: ["fluent-gem", "install", "fluent-plugin-rewrite-tag-filter"] + containers: + - name: fluentd + image: your-fluentd-image:version diff --git a/okx/candleList.go b/okx/candleList.go index b42e275..313c6c9 100644 --- a/okx/candleList.go +++ b/okx/candleList.go @@ -5,9 +5,8 @@ import ( "encoding/csv" "encoding/json" "fmt" + cfg "gitea.zjmud.xyz/phyer/tanya/config" "io" - - cfg "gitea.zjmud.xyz/phyer/tanya/config" // 请将your_project_path替换为实际的项目路径 "net/http" "strconv" "strings" @@ -143,8 +142,8 @@ func (cl *CandleList) ToCsv() (string, error) { return sb.String(), nil } -// ToEs 将Candle数据发送到Elasticsearch -func (cl *CandleList) ToEs() error { +// ToFluentd 将Candle数据发送到Fluentd +func (cl *CandleList) ToFluentd() error { // 获取当前年份 currentYear := time.Now().Year() @@ -240,7 +239,7 @@ func (cl *CandleList) ToEs() error { } // 构造完整URL,添加json参数 - fullURL := fmt.Sprintf("%s/%s?json", strings.TrimRight(config.ElasticsearchURL, "/"), tag) + fullURL := fmt.Sprintf("%s/%s?json", strings.TrimRight(config.FluentdURL, "/"), tag) // 输出完整请求URL和请求体到日志 fmt.Printf("Sending request to URL: %s\n", fullURL) diff --git a/okx/publicApiService.go b/okx/publicApiService.go index 307bd8f..e070afc 100644 --- a/okx/publicApiService.go +++ b/okx/publicApiService.go @@ -94,44 +94,19 @@ func (s *OkxPublicDataService) GetCandles(params CandlesRequest) ([]*Candle, err // 添加调试日志 fmt.Printf("Making request to: %s\n", u.String()) - // 创建自定义HTTP请求 - req, err := http.NewRequest("GET", u.String(), nil) + resp, err := http.Get(u.String()) if err != nil { - return nil, fmt.Errorf("failed to create request: %v", err) + return nil, err } - - // 设置请求头 - req.Header.Set("Accept", "application/json") - req.Header.Set("Content-Type", "application/json") - - // 发送请求 - resp, err := http.DefaultClient.Do(req) - if err != nil { - return nil, fmt.Errorf("request failed: %v", err) - } - defer resp.Body.Close() - // 打印详细调试信息 - fmt.Printf("Request URL: %s\n", u.String()) - fmt.Printf("Response Status: %s\n", resp.Status) - fmt.Printf("Response Headers: %v\n", resp.Header) - // 记录响应状态 fmt.Printf("Response Status: %s\n", resp.Status) // 读取并记录响应体 body, err := io.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("failed to read response body: %v", err) - } - - // 打印响应体长度和内容 - fmt.Printf("Response Body Length: %d\n", len(body)) - if len(body) > 0 { - fmt.Printf("Response Body: %s\n", string(body)) - } else { - fmt.Println("Response Body is empty") + return nil, err } fmt.Printf("Response Body: %s\n", string(body)) diff --git a/test/okxAli/candleList_test.go b/test/okxAli/candleList_test.go index 4314226..918a372 100644 --- a/test/okxAli/candleList_test.go +++ b/test/okxAli/candleList_test.go @@ -58,7 +58,7 @@ func TestCandleList_ToEs(t *testing.T) { if err != nil { t.Fatalf("ToEs failed: %v", err) } - err = cl.ToEs() + err = cl.ToFluentd() if err != nil { t.Fatalf("ToEs failed: %v", err) }