fix(cloudmon): cloudpods metric sync (#21461)

This commit is contained in:
屈轩
2024-10-25 17:26:20 +08:00
committed by GitHub
parent 547c3b939a
commit e3779e2c81
8 changed files with 67 additions and 24 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ require (
k8s.io/client-go v0.19.3
k8s.io/cluster-bootstrap v0.19.3
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241021095524-bf7da369f379
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241025091256-d552aef5b421
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20240930100528-1671a2d0d22f
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
+2 -2
View File
@@ -1274,8 +1274,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241021095524-bf7da369f379 h1:53ncGcuIFZFJDeJBwgams6c84xKx9so/vRxXR2fwmgU=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241021095524-bf7da369f379/go.mod h1:rj/pb3DitJlQaQD8UW1oxx/KD+PzDZqoywzqRJaFE9A=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241025091256-d552aef5b421 h1:oE9ZrlZv1br/OGlLxZJDlQPrYzxJllqvtjMqVDUKxjM=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241025091256-d552aef5b421/go.mod h1:rj/pb3DitJlQaQD8UW1oxx/KD+PzDZqoywzqRJaFE9A=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
+1
View File
@@ -295,6 +295,7 @@ func (self *SCloudpodsClient) GetCapabilities() []string {
cloudprovider.CLOUD_CAPABILITY_PROJECT + cloudprovider.READ_ONLY_SUFFIX,
cloudprovider.CLOUD_CAPABILITY_COMPUTE,
cloudprovider.CLOUD_CAPABILITY_NETWORK,
cloudprovider.CLOUD_CAPABILITY_SECURITY_GROUP,
cloudprovider.CLOUD_CAPABILITY_EIP,
}
}
+1 -1
View File
@@ -544,7 +544,7 @@ type SMetricData struct {
}
func (cli *SCloudpodsClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
brandArr := []string{"OneCloud", "VMware"}
brandArr := []string{"OneCloud"}
metrics := []SMetricData{}
usefulResourceType := []cloudprovider.TResourceType{cloudprovider.METRIC_RESOURCE_TYPE_HOST, cloudprovider.METRIC_RESOURCE_TYPE_SERVER}
isUse, _ := utils.InArray(opts.ResourceType, usefulResourceType)
+37
View File
@@ -0,0 +1,37 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shell
import (
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/log"
"yunion.io/x/pkg/util/shellutils"
"yunion.io/x/onecloud/pkg/mcclient/cloudpods"
)
func init() {
shellutils.R(&cloudprovider.MetricListOptions{}, "metric-list", "List metrics in a namespace", func(cli *cloudpods.SRegion, args *cloudprovider.MetricListOptions) error {
metrics, err := cli.GetClient().GetMetrics(args)
if err != nil {
return err
}
for i := range metrics {
log.Infof("metric: %s %s %s", metrics[i].Id, metrics[i].MetricType, metrics[i].Unit)
printList(metrics[i].Values, len(metrics[i].Values), 0, 0, []string{})
}
return nil
})
}
+1 -1
View File
@@ -1576,7 +1576,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241021095524-bf7da369f379
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241025091256-d552aef5b421
## explicit; go 1.21
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
+20 -15
View File
@@ -23,6 +23,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"
api "yunion.io/x/cloudmux/pkg/apis/compute"
"yunion.io/x/cloudmux/pkg/cloudprovider"
@@ -95,7 +96,7 @@ func (self *SLBListener) GetBackendServerPort() int {
// https://cloud.tencent.com/document/product/214/30691
func (self *SLBListener) CreateILoadBalancerListenerRule(rule *cloudprovider.SLoadbalancerListenerRule) (cloudprovider.ICloudLoadbalancerListenerRule, error) {
hc := getListenerRuleHealthCheck(rule)
requestId, err := self.lb.region.CreateLoadbalancerListenerRule(self.lb.GetId(),
resp, err := self.lb.region.CreateLoadbalancerListenerRule(self.lb.GetId(),
self.GetId(),
rule.Domain,
rule.Path,
@@ -106,7 +107,7 @@ func (self *SLBListener) CreateILoadBalancerListenerRule(rule *cloudprovider.SLo
return nil, err
}
err = self.lb.region.WaitLBTaskSuccess(requestId, 5*time.Second, 60*time.Second)
err = self.lb.region.WaitLBTaskSuccess(resp.RequestId, 5*time.Second, 60*time.Second)
if err != nil {
return nil, err
}
@@ -116,14 +117,13 @@ func (self *SLBListener) CreateILoadBalancerListenerRule(rule *cloudprovider.SLo
return nil, err
}
for _, r := range self.Rules {
if r.GetPath() == rule.Path {
r.listener = self
for i := range self.Rules {
r := self.Rules[i]
if utils.IsInStringArray(r.LocationId, resp.LocationIds) {
return &r, nil
}
}
return nil, cloudprovider.ErrNotFound
return nil, errors.Wrapf(cloudprovider.ErrNotFound, jsonutils.Marshal(resp).String())
}
func (self *SLBListener) GetILoadBalancerListenerRuleById(ruleId string) (cloudprovider.ICloudLoadbalancerListenerRule, error) {
@@ -452,12 +452,13 @@ func (self *SRegion) GetLoadbalancerListeners(lbId string, lblisIds []string, pr
return listeners, nil
}
// 返回requestId
func (self *SRegion) CreateLoadbalancerListenerRule(lbid string, listenerId string, domain string, url string, scheduler string, sessionExpireTime int, hc *HealthCheck) (string, error) {
if len(lbid) == 0 {
return "", fmt.Errorf("loadbalancer id should not be empty")
}
type ListenerRuleResponse struct {
RequestId string
LocationIds []string
}
// 返回requestId
func (self *SRegion) CreateLoadbalancerListenerRule(lbid string, listenerId string, domain string, url string, scheduler string, sessionExpireTime int, hc *HealthCheck) (*ListenerRuleResponse, error) {
params := map[string]string{
"LoadBalancerId": lbid,
"ListenerId": listenerId,
@@ -482,10 +483,14 @@ func (self *SRegion) CreateLoadbalancerListenerRule(lbid string, listenerId stri
resp, err := self.clbRequest("CreateRule", params)
if err != nil {
return "", err
return nil, err
}
return resp.GetString("RequestId")
ret := &ListenerRuleResponse{}
err = resp.Unmarshal(ret)
if err != nil {
return nil, err
}
return ret, nil
}
// 返回requestId
@@ -36,7 +36,7 @@ type SLBListenerRule struct {
Certificate Certificate `json:"Certificate"`
URL string `json:"Url"`
HealthCheck HealthCheck `json:"HealthCheck"`
LocationID string `json:"LocationId"`
LocationId string `json:"LocationId"`
Scheduler string `json:"Scheduler"`
SessionExpireTime int64 `json:"SessionExpireTime"`
}
@@ -52,15 +52,15 @@ func (self *SLBListenerRule) Delete(ctx context.Context) error {
}
func (self *SLBListenerRule) GetId() string {
return self.LocationID
return self.LocationId
}
func (self *SLBListenerRule) GetName() string {
return self.LocationID
return self.LocationId
}
func (self *SLBListenerRule) GetGlobalId() string {
return self.LocationID
return self.LocationId
}
func (self *SLBListenerRule) GetStatus() string {