From 0a3f28130d1199308c716da670af65b68a6626cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=85=E6=B3=89=E6=B5=81=E5=93=8D?= Date: Thu, 4 Dec 2025 11:01:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ft:=20resty.dev=20htto=20=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .zed/debug.json | 35 +++++++++++++++++++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ test/http/http_test.go | 31 +++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 .zed/debug.json create mode 100644 test/http/http_test.go 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..ee6fac1 --- /dev/null +++ b/test/http/http_test.go @@ -0,0 +1,31 @@ +package http_test + +import ( + "fmt" + "strconv" + "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) + + 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": nt, + }). + Get("http://10.99.1.12:30737/api/v1/query") + if err != nil { + t.Fatalf("查询失败: %s\n", err) + } + fmt.Printf("res: %+v\n", res) +} From 5fe53280cdba011b524bba8534e352d330c43173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=85=E6=B3=89=E6=B5=81=E5=93=8D?= Date: Fri, 5 Dec 2025 14:23:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/http/http_test.go | 56 +++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/test/http/http_test.go b/test/http/http_test.go index ee6fac1..41d81ba 100644 --- a/test/http/http_test.go +++ b/test/http/http_test.go @@ -1,8 +1,11 @@ package http_test import ( + "context" "fmt" - "strconv" + "os" + "os/signal" + "syscall" "testing" "time" @@ -12,20 +15,43 @@ import ( 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) + // 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) - 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": nt, - }). - Get("http://10.99.1.12:30737/api/v1/query") - if err != nil { - t.Fatalf("查询失败: %s\n", err) + 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 + } } - fmt.Printf("res: %+v\n", res) }