up
This commit is contained in:
parent
7202a98998
commit
f0814c40bc
5
Dockerfile
Normal file
5
Dockerfile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
RUN fluent-gem install fluent-plugin-elasticsearch fluent-plugin-rewrite-tag-filter
|
||||||
|
>>>>>>> Snippet
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ElasticsearchURL string `json:"elasticsearch_url"`
|
FluentdURL string `json:"fluentdURL_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConfig 从指定路径加载配置文件
|
// LoadConfig 从指定路径加载配置文件
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"elasticsearch_url": "http://fluentd.k8s.xunlang.home"
|
"fluentdURL_url": "http://fluentd.k8s.xunlang.home"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
8
fluentd-deployment.yaml
Normal file
8
fluentd-deployment.yaml
Normal file
@ -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
|
@ -5,9 +5,8 @@ import (
|
|||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
cfg "gitea.zjmud.xyz/phyer/tanya/config"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
cfg "gitea.zjmud.xyz/phyer/tanya/config" // 请将your_project_path替换为实际的项目路径
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -143,8 +142,8 @@ func (cl *CandleList) ToCsv() (string, error) {
|
|||||||
return sb.String(), nil
|
return sb.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToEs 将Candle数据发送到Elasticsearch
|
// ToFluentd 将Candle数据发送到Fluentd
|
||||||
func (cl *CandleList) ToEs() error {
|
func (cl *CandleList) ToFluentd() error {
|
||||||
// 获取当前年份
|
// 获取当前年份
|
||||||
currentYear := time.Now().Year()
|
currentYear := time.Now().Year()
|
||||||
|
|
||||||
@ -240,7 +239,7 @@ func (cl *CandleList) ToEs() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 构造完整URL,添加json参数
|
// 构造完整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和请求体到日志
|
// 输出完整请求URL和请求体到日志
|
||||||
fmt.Printf("Sending request to URL: %s\n", fullURL)
|
fmt.Printf("Sending request to URL: %s\n", fullURL)
|
||||||
|
@ -94,44 +94,19 @@ func (s *OkxPublicDataService) GetCandles(params CandlesRequest) ([]*Candle, err
|
|||||||
// 添加调试日志
|
// 添加调试日志
|
||||||
fmt.Printf("Making request to: %s\n", u.String())
|
fmt.Printf("Making request to: %s\n", u.String())
|
||||||
|
|
||||||
// 创建自定义HTTP请求
|
resp, err := http.Get(u.String())
|
||||||
req, err := http.NewRequest("GET", u.String(), nil)
|
|
||||||
if err != nil {
|
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()
|
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)
|
fmt.Printf("Response Status: %s\n", resp.Status)
|
||||||
|
|
||||||
// 读取并记录响应体
|
// 读取并记录响应体
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read response body: %v", err)
|
return nil, 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")
|
|
||||||
}
|
}
|
||||||
fmt.Printf("Response Body: %s\n", string(body))
|
fmt.Printf("Response Body: %s\n", string(body))
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func TestCandleList_ToEs(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ToEs failed: %v", err)
|
t.Fatalf("ToEs failed: %v", err)
|
||||||
}
|
}
|
||||||
err = cl.ToEs()
|
err = cl.ToFluentd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ToEs failed: %v", err)
|
t.Fatalf("ToEs failed: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user