Skip to content

Commit 20b47f6

Browse files
committed
fix(volc): update volc monitor api
1 parent 1cfe517 commit 20b47f6

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

pkg/multicloud/volcengine/shell/monitor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package shell
1616

1717
import (
18+
"time"
19+
1820
"yunion.io/x/log"
1921
"yunion.io/x/pkg/util/shellutils"
2022

@@ -24,6 +26,12 @@ import (
2426

2527
func init() {
2628
shellutils.R(&cloudprovider.MetricListOptions{}, "metric-list", "List metrics", func(cli *volcengine.SRegion, args *cloudprovider.MetricListOptions) error {
29+
if args.StartTime.IsZero() {
30+
args.StartTime = time.Now().Add(time.Minute * -20)
31+
}
32+
if args.EndTime.IsZero() {
33+
args.EndTime = time.Now()
34+
}
2735
metrics, err := cli.GetClient().GetMetrics(args)
2836
if err != nil {
2937
return err

pkg/multicloud/volcengine/volcengine.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ const (
4747

4848
VOLCENGINE_API_VERSION = "2020-04-01"
4949
VOLCENGINE_IAM_API_VERSION = "2018-01-01"
50-
VOLCENGINE_OBSERVE_API_VERSION = "2018-01-01"
50+
VOLCENGINE_MONITOR_API_VERSION = "2018-01-01"
5151
VOLCENGINE_BILLING_API_VERSION = "2022-01-01"
5252

5353
VOLCENGINE_API = "open.volcengineapi.com"
5454
VOLCENGINE_IAM_API = "iam.volcengineapi.com"
5555
VOLCENGINE_TOS_API = "tos-cn-beijing.volces.com"
5656
VOLCENGINE_BILLING_API = "billing.volcengineapi.com"
5757

58-
VOLCENGINE_SERVICE_ECS = "ecs"
59-
VOLCENGINE_SERVICE_VPC = "vpc"
60-
VOLCENGINE_SERVICE_NAT = "natgateway"
61-
VOLCENGINE_SERVICE_STORAGE = "storage_ebs"
62-
VOLCENGINE_SERVICE_IAM = "iam"
63-
VOLCENGINE_SERVICE_TOS = "tos"
64-
VOLCENGINE_SERVICE_OBSERVICE = "Volc_Observe"
65-
VOLCENGINE_SERVICE_BILLING = "billing"
58+
VOLCENGINE_SERVICE_ECS = "ecs"
59+
VOLCENGINE_SERVICE_VPC = "vpc"
60+
VOLCENGINE_SERVICE_NAT = "natgateway"
61+
VOLCENGINE_SERVICE_STORAGE = "storage_ebs"
62+
VOLCENGINE_SERVICE_IAM = "iam"
63+
VOLCENGINE_SERVICE_TOS = "tos"
64+
VOLCENGINE_SERVICE_MONITOR = "cloudmonitor"
65+
VOLCENGINE_SERVICE_BILLING = "billing"
6666

6767
VOLCENGINE_DEFAULT_REGION = "cn-beijing"
6868
)
@@ -276,8 +276,8 @@ func (self *sCred) Do(req *http.Request) (*http.Response, error) {
276276
}
277277

278278
func (client *SVolcEngineClient) monitorRequest(regionId, apiName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
279-
cred := client.getSdkCredential(regionId, VOLCENGINE_SERVICE_OBSERVICE, "")
280-
return client.jsonRequest(cred, VOLCENGINE_API, VOLCENGINE_OBSERVE_API_VERSION, apiName, params)
279+
cred := client.getSdkCredential(regionId, VOLCENGINE_SERVICE_MONITOR, "")
280+
return client.jsonRequest(cred, VOLCENGINE_API, VOLCENGINE_MONITOR_API_VERSION, apiName, params)
281281
}
282282

283283
func (client *SVolcEngineClient) jsonRequest(cred sdk.Credentials, domain string, apiVersion string, apiName string, params interface{}) (jsonutils.JSONObject, error) {
@@ -306,23 +306,20 @@ func (client *SVolcEngineClient) jsonRequest(cred sdk.Credentials, domain string
306306
method = httputils.DELETE
307307
}
308308
}
309-
if cred.Service == VOLCENGINE_SERVICE_OBSERVICE {
309+
if cred.Service == VOLCENGINE_SERVICE_MONITOR {
310310
method = httputils.POST
311311
}
312312
// 私网接口仅支持GET请求
313313
if cred.Service == VOLCENGINE_SERVICE_VPC {
314314
method = httputils.GET
315315
}
316316

317-
form := url.Values{}
318-
_params, _ := params.(map[string]string)
317+
var reqBody io.Reader = nil
319318
switch method {
320319
case httputils.POST:
321-
for k, v := range _params {
322-
form.Set(k, v)
323-
query.Set(k, v)
324-
}
320+
reqBody = strings.NewReader(jsonutils.Marshal(params).String())
325321
default:
322+
_params, _ := params.(map[string]string)
326323
for k, v := range _params {
327324
query.Set(k, v)
328325
}
@@ -333,7 +330,7 @@ func (client *SVolcEngineClient) jsonRequest(cred sdk.Credentials, domain string
333330
return nil, errors.Wrapf(err, "url.Parse")
334331
}
335332

336-
req, err := http.NewRequest(string(method), u.String(), strings.NewReader(form.Encode()))
333+
req, err := http.NewRequest(string(method), u.String(), reqBody)
337334
if err != nil {
338335
return nil, errors.Wrapf(err, "NewRequest")
339336
}

0 commit comments

Comments
 (0)