diff --git a/.zed/debug.json b/.zed/debug.json new file mode 100644 index 0000000..fd94391 --- /dev/null +++ b/.zed/debug.json @@ -0,0 +1,35 @@ +// Project-local debug tasks +// +// For more documentation on how to configure debug tasks, +// see: https://zed.dev/docs/debugger +// Project-local debug tasks +// +// For more documentation on how to configure debug tasks, +// see: https://zed.dev/docs/debugger +[ + { + "label": "main", + "adapter": "Delve", + "program": "${ZED_WORKTREE_ROOT}/cmd/apiserver/main.go", + "args": ["-c", "${ZED_WORKTREE_ROOT}/config.yaml"], + "request": "launch", + "mode": "debug", + "env": { + "SERVICE_NAME": "api-server" + // "API_SERVER_SERVER_BIND": ":8090" + // "API_SERVER_CONFIG_PATH": "${workspaceFolder}/config.yaml" + } + }, + { + "label": "init", + "adapter": "Delve", + "request": "launch", + "mode": "debug", + "program": "${ZED_WORKTREE_ROOT}/cmd/apiserver/main.go", + "args": ["init"], + "env": { + "SERVICE_NAME": "qqlx", + "QQLX_CONFIG_PATH": "${ZED_WORKTREE_ROOT}/config.yaml" + } + } +] diff --git a/go.mod b/go.mod index efbd8df..2897e3e 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( golang.org/x/oauth2 v0.27.0 gorm.io/driver/mysql v1.6.0 gorm.io/gorm v1.30.0 + resty.dev/v3 v3.0.0-beta.4 ) require ( diff --git a/go.sum b/go.sum index 40d710b..9d89bab 100644 --- a/go.sum +++ b/go.sum @@ -364,3 +364,5 @@ modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds= modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= modernc.org/sqlite v1.20.3 h1:SqGJMMxjj1PHusLxdYxeQSodg7Jxn9WWkaAQjKrntZs= modernc.org/sqlite v1.20.3/go.mod h1:zKcGyrICaxNTMEHSr1HQ2GUraP0j+845GYw37+EyT6A= +resty.dev/v3 v3.0.0-beta.4 h1:2O77oFymtA4NT8AY87wAaSgSGUBk2yvvM1qno9VRXZU= +resty.dev/v3 v3.0.0-beta.4/go.mod h1:NTOerrC/4T7/FE6tXIZGIysXXBdgNqwMZuKtxpea9NM= diff --git a/test/http/http_test.go b/test/http/http_test.go new file mode 100644 index 0000000..41d81ba --- /dev/null +++ b/test/http/http_test.go @@ -0,0 +1,57 @@ +package http_test + +import ( + "context" + "fmt" + "os" + "os/signal" + "syscall" + "testing" + "time" + + "resty.dev/v3" +) + +func TestCurl(t *testing.T) { + client := resty.New() + defer client.Close() + // loc, _ := time.LoadLocation("Asia/Shanghai") + // tt, _ := time.ParseInLocation("2006-01-02 15:04:05", "2025-12-02 13:43:10", loc) + // nt := strconv.FormatInt(tt.Unix(), 10) + // fmt.Printf("nt: %s\n", nt) + + ticker := time.NewTicker(10 * time.Second) + defer ticker.Stop() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + sigChan := make(chan os.Signal, 2) + signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) + go func() { + <-sigChan + fmt.Println("Ctrl+C received, shutting down...") + cancel() + }() + + for { + select { + case <-ticker.C: + nt := time.Now() + fmt.Printf("nt: %s\n", nt.Format("2006-01-02 15:04:05")) + res, err := client.R(). + SetQueryParams(map[string]string{ + "query": `sum by (container) (max_over_time(DCGM_FI_DEV_GPU_UTIL{namespace="a1-prod", container="qwen-image"}[1m])) / 100`, + // "query": `sum (DCGM_FI_DEV_GPU_UTIL{namespace="a1-prod", container="qwen-image"}) by (container) / 100`, + "time": fmt.Sprintf("%d", nt.Unix()), + }). + Get("http://10.99.1.12:30737/api/v1/query") + if err != nil { + t.Fatalf("查询失败: %s\n", err) + } + fmt.Printf("res: %+v\n", res) + case <-ctx.Done(): + fmt.Println("Application stopped.") + return + } + } +}