fix(cloudmon): vendor update for support oracle metric (#20039)

This commit is contained in:
屈轩
2024-04-17 15:25:57 +08:00
committed by GitHub
parent d8fe2ce5dd
commit 7a2c092548
14 changed files with 188 additions and 65 deletions
+1 -1
View File
@@ -88,7 +88,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.20240416095227-3e37fc917f65
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240417061814-6a1fe9ae3c31
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
+2 -2
View File
@@ -1204,8 +1204,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.20240416095227-3e37fc917f65 h1:TyUeqGO9VvE0+I4mGshrsUP/Zxy7FYdlY9oAL96OXCs=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240416095227-3e37fc917f65/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240417061814-6a1fe9ae3c31 h1:rSADiPVCxHz6yoTrQgYoJAS6RNz8sg51x/oL9ykUNnQ=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240417061814-6a1fe9ae3c31/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
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=
+35
View File
@@ -0,0 +1,35 @@
// 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 providerdriver
import (
api "yunion.io/x/onecloud/pkg/apis/compute"
)
type OracleCollect struct {
SCollectByResourceIdDriver
}
func (self *OracleCollect) GetProvider() string {
return api.CLOUD_PROVIDER_ORACLE
}
func (self *OracleCollect) IsSupportMetrics() bool {
return true
}
func init() {
Register(&OracleCollect{})
}
+1 -1
View File
@@ -1472,7 +1472,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.20240416095227-3e37fc917f65
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240417061814-6a1fe9ae3c31
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
+4 -5
View File
@@ -16,6 +16,7 @@ package oracle
import (
"context"
"net/url"
"time"
"yunion.io/x/jsonutils"
@@ -60,8 +61,6 @@ func (self *SRegion) GetBootDisk(id string) (*SBootDisk, error) {
return nil, err
}
return ret, nil
return nil, cloudprovider.ErrNotImplemented
}
func (self *SBootDisk) GetId() string {
@@ -187,11 +186,11 @@ func (self *SBootDisk) GetProjectId() string {
}
func (self *SRegion) GetBootDisks(zoneId string) ([]SBootDisk, error) {
params := map[string]interface{}{}
query := url.Values{}
if len(zoneId) > 0 {
params["availabilityDomain"] = zoneId
query.Set("availabilityDomain", zoneId)
}
resp, err := self.list(SERVICE_IAAS, "bootVolumes", params)
resp, err := self.list(SERVICE_IAAS, "bootVolumes", query)
if err != nil {
return nil, err
}
+4 -3
View File
@@ -16,6 +16,7 @@ package oracle
import (
"context"
"net/url"
"time"
"yunion.io/x/jsonutils"
@@ -187,11 +188,11 @@ func (self *SDisk) GetProjectId() string {
}
func (self *SRegion) GetDisks(zoneId string) ([]SDisk, error) {
params := map[string]interface{}{}
query := url.Values{}
if len(zoneId) > 0 {
params["availabilityDomain"] = zoneId
query.Set("availabilityDomain", zoneId)
}
resp, err := self.list(SERVICE_IAAS, "volumes", params)
resp, err := self.list(SERVICE_IAAS, "volumes", query)
if err != nil {
return nil, err
}
+6 -6
View File
@@ -15,6 +15,7 @@
package oracle
import (
"net/url"
"time"
"yunion.io/x/jsonutils"
@@ -163,16 +164,15 @@ func (self *SRegion) GetEips(lifetime string) ([]SEipAddress, error) {
if err != nil {
return nil, err
}
params := map[string]interface{}{
"scope": "AVAILABILITY_DOMAIN",
}
query := url.Values{}
query.Set("scope", "AVAILABILITY_DOMAIN")
if len(lifetime) > 0 {
params["lifetime"] = lifetime
query.Set("lifetime", lifetime)
}
ret := []SEipAddress{}
for _, zone := range zones {
params["availabilityDomain"] = zone.Name
resp, err := self.list(SERVICE_IAAS, "publicIps", params)
query.Set("availabilityDomain", zone.Name)
resp, err := self.list(SERVICE_IAAS, "publicIps", query)
if err != nil {
return nil, err
}
+10 -11
View File
@@ -16,6 +16,7 @@ package oracle
import (
"context"
"net/url"
"time"
billing_api "yunion.io/x/cloudmux/pkg/apis/billing"
@@ -103,9 +104,9 @@ type SInstance struct {
}
func (self *SRegion) GetInstances(zoneId string) ([]SInstance, error) {
params := map[string]interface{}{}
params := url.Values{}
if len(zoneId) > 0 {
params["availabilityDomain"] = zoneId
params.Set("availabilityDomain", zoneId)
}
resp, err := self.list(SERVICE_IAAS, "instances", params)
if err != nil {
@@ -389,9 +390,8 @@ type SVolumeAttachment struct {
}
func (self *SRegion) GetAttachedDisks(instanceId string) ([]SVolumeAttachment, error) {
params := map[string]interface{}{
"instanceId": instanceId,
}
params := url.Values{}
params.Set("instanceId", instanceId)
resp, err := self.list(SERVICE_IAAS, "volumeAttachments", params)
if err != nil {
return nil, err
@@ -409,10 +409,9 @@ type SBootVolumeAttachment struct {
}
func (self *SRegion) GetBootVolumeAttachments(zoneId, instanceId string) ([]SBootVolumeAttachment, error) {
params := map[string]interface{}{
"instanceId": instanceId,
"availabilityDomain": zoneId,
}
params := url.Values{}
params.Set("instanceId", instanceId)
params.Set("availabilityDomain", zoneId)
resp, err := self.list(SERVICE_IAAS, "bootVolumeAttachments", params)
if err != nil {
return nil, err
@@ -430,9 +429,9 @@ type SVnicAttachment struct {
}
func (self *SRegion) GetVnicAttachments(instanceId string) ([]SVnicAttachment, error) {
params := map[string]interface{}{}
params := url.Values{}
if len(instanceId) > 0 {
params["instanceId"] = instanceId
params.Set("instanceId", instanceId)
}
resp, err := self.list(SERVICE_IAAS, "vnicAttachments", params)
if err != nil {
+88
View File
@@ -0,0 +1,88 @@
// 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 oracle
import (
"fmt"
"net/url"
"time"
"yunion.io/x/pkg/errors"
"yunion.io/x/cloudmux/pkg/cloudprovider"
)
func (self *SOracleClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
switch opts.ResourceType {
case cloudprovider.METRIC_RESOURCE_TYPE_SERVER:
return self.GetEcsMetrics(opts)
default:
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "%s", opts.ResourceType)
}
}
func (self *SOracleClient) GetEcsMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
query := url.Values{}
query.Set("compartmentId", self.compartment)
results := []cloudprovider.MetricValues{}
for metricType, queryStr := range map[cloudprovider.TMetricType]string{
cloudprovider.VM_METRIC_TYPE_CPU_USAGE: fmt.Sprintf("CPUUtilization[1m]{resourceId = \"%s\"}.mean()", opts.ResourceId),
cloudprovider.VM_METRIC_TYPE_MEM_USAGE: fmt.Sprintf("MemoryUtilization[1m]{resourceId = \"%s\"}.mean()", opts.ResourceId),
cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_IOPS: fmt.Sprintf("DiskIopsRead[1m]{resourceId = \"%s\"}.rate()", opts.ResourceId),
cloudprovider.VM_METRIC_TYPE_DISK_IO_WRITE_IOPS: fmt.Sprintf("DiskIopsWritten[1m]{resourceId = \"%s\"}.rate()", opts.ResourceId),
cloudprovider.VM_METRIC_TYPE_DISK_IO_READ_BPS: fmt.Sprintf("DiskBytesRead[1m]{resourceId = \"%s\"}.rate()", opts.ResourceId),
cloudprovider.VM_METRIC_TYPE_DISK_IO_WRITE_BPS: fmt.Sprintf("DiskBytesWritten[1m]{resourceId = \"%s\"}.rate()", opts.ResourceId),
cloudprovider.VM_METRIC_TYPE_NET_BPS_RX: fmt.Sprintf("NetworksBytesIn[1m]{resourceId = \"%s\"}.rate()", opts.ResourceId),
cloudprovider.VM_METRIC_TYPE_NET_BPS_TX: fmt.Sprintf("NetworksBytesOut[1m]{resourceId = \"%s\"}.rate()", opts.ResourceId),
} {
params := map[string]interface{}{
"namespace": "oci_computeagent",
"startTime": opts.StartTime,
"endTime": opts.EndTime,
"query": queryStr,
}
resp, err := self.post(SERVICE_TELEMETRY, opts.RegionExtId, "metrics/actions/summarizeMetricsData", query, params)
if err != nil {
return nil, err
}
ret := []struct {
AggregatedDatapoints []struct {
Timestamp time.Time
Value float64
}
}{}
err = resp.Unmarshal(&ret)
if err != nil {
return nil, err
}
result := cloudprovider.MetricValues{
Id: opts.ResourceId,
MetricType: metricType,
Values: []cloudprovider.MetricValue{},
}
for _, values := range ret {
for _, v := range values.AggregatedDatapoints {
result.Values = append(result.Values, cloudprovider.MetricValue{
Timestamp: v.Timestamp,
Value: v.Value,
})
}
}
results = append(results, result)
}
return results, nil
}
+3 -2
View File
@@ -15,6 +15,7 @@
package oracle
import (
"net/url"
"time"
"yunion.io/x/jsonutils"
@@ -140,9 +141,9 @@ func (self *SNetwork) GetProjectId() string {
}
func (self *SRegion) GetNetworks(vpcId string) ([]SNetwork, error) {
params := map[string]interface{}{}
params := url.Values{}
if len(vpcId) > 0 {
params["vcnId"] = vpcId
params.Set("vcnId", vpcId)
}
resp, err := self.list(SERVICE_IAAS, "subnets", params)
if err != nil {
+24 -27
View File
@@ -44,11 +44,13 @@ const (
CLOUD_PROVIDER_ORACLE_CN = "甲骨文"
ORACLE_DEFAULT_REGION = "ap-singapore-1"
DEFAULT_API_VERSION = "20160918"
MONITORY_API_VERSION = "20180401"
NEXT_TOKEN = "opc-next-page"
SERVICE_IAAS = "iaas"
SERVICE_IDENTITY = "identity"
SERVICE_IAAS = "iaas"
SERVICE_IDENTITY = "identity"
SERVICE_TELEMETRY = "telemetry"
)
type OracleClientConfig struct {
@@ -189,8 +191,10 @@ func (self *SOracleClient) getUrl(service, regionId, resource string) (string, e
regionId = ORACLE_DEFAULT_REGION
}
switch service {
case "iaas", "identity":
case SERVICE_IAAS, SERVICE_IDENTITY:
return fmt.Sprintf("https://%s.%s.oraclecloud.com/%s/%s", service, regionId, DEFAULT_API_VERSION, strings.TrimPrefix(resource, "/")), nil
case SERVICE_TELEMETRY:
return fmt.Sprintf("https://%s.%s.oraclecloud.com/%s/%s", service, regionId, MONITORY_API_VERSION, strings.TrimPrefix(resource, "/")), nil
default:
return "", errors.Wrapf(cloudprovider.ErrNotSupported, service)
}
@@ -271,16 +275,16 @@ func (self *SOracleClient) Do(req *http.Request) (*http.Response, error) {
return client.Do(req)
}
func (self *SOracleClient) list(service, regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
if params == nil {
params = map[string]interface{}{}
func (self *SOracleClient) list(service, regionId, resource string, query url.Values) (jsonutils.JSONObject, error) {
if query == nil {
query = url.Values{}
}
if len(self.compartment) > 0 {
params["compartmentId"] = self.compartment
query.Set("compartmentId", self.compartment)
}
ret := jsonutils.NewArray()
for {
resp, token, err := self.request(httputils.GET, service, regionId, resource, params)
resp, token, err := self.request(httputils.GET, service, regionId, resource, query, nil)
if err != nil {
return nil, err
}
@@ -289,28 +293,25 @@ func (self *SOracleClient) list(service, regionId, resource string, params map[s
if len(token) == 0 {
break
}
params["page"] = token
query.Set("page", token)
}
return ret, nil
}
func (self *SOracleClient) get(service, regionId, resource, id string, params map[string]interface{}) (jsonutils.JSONObject, error) {
func (self *SOracleClient) get(service, regionId, resource, id string, query url.Values) (jsonutils.JSONObject, error) {
if len(id) == 0 {
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "empty id")
}
if params == nil {
params = map[string]interface{}{}
}
resp, _, err := self.request(httputils.GET, service, regionId, resource+"/"+id, params)
resp, _, err := self.request(httputils.GET, service, regionId, resource+"/"+id, query, nil)
return resp, err
}
func (self *SOracleClient) post(service, regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
resp, _, err := self.request(httputils.POST, service, regionId, resource, params)
func (self *SOracleClient) post(service, regionId, resource string, query url.Values, params map[string]interface{}) (jsonutils.JSONObject, error) {
resp, _, err := self.request(httputils.POST, service, regionId, resource, query, params)
return resp, err
}
func (self *SOracleClient) request(method httputils.THttpMethod, service, regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, string, error) {
func (self *SOracleClient) request(method httputils.THttpMethod, service, regionId, resource string, query url.Values, params map[string]interface{}) (jsonutils.JSONObject, string, error) {
uri, err := self.getUrl(service, regionId, resource)
if err != nil {
return nil, "", err
@@ -318,15 +319,9 @@ func (self *SOracleClient) request(method httputils.THttpMethod, service, region
if params == nil {
params = map[string]interface{}{}
}
values := url.Values{}
if method == httputils.GET {
for k, v := range params {
values.Set(k, v.(string))
}
if len(values) > 0 {
uri = fmt.Sprintf("%s?%s", uri, values.Encode())
}
params = nil
if len(query) > 0 {
uri = fmt.Sprintf("%s?%s", uri, query.Encode())
}
req := httputils.NewJsonRequest(method, uri, params)
@@ -381,7 +376,9 @@ type Compartment struct {
}
func (self *SOracleClient) GetCompartments() ([]Compartment, error) {
resp, err := self.list(SERVICE_IDENTITY, ORACLE_DEFAULT_REGION, "compartments", map[string]interface{}{"compartmentId": self.tenancyOCID})
query := url.Values{}
query.Set("compartmentId", self.tenancyOCID)
resp, err := self.list(SERVICE_IDENTITY, ORACLE_DEFAULT_REGION, "compartments", query)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -218,5 +218,5 @@ func (self *SOracleProvider) GetCloudRegionExternalIdPrefix() string {
}
func (self *SOracleProvider) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
return nil, cloudprovider.ErrNotImplemented
return self.client.GetMetrics(opts)
}
+5 -4
View File
@@ -16,6 +16,7 @@ package oracle
import (
"fmt"
"net/url"
api "yunion.io/x/cloudmux/pkg/apis/compute"
"yunion.io/x/cloudmux/pkg/cloudprovider"
@@ -171,12 +172,12 @@ func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
return nil, cloudprovider.ErrNotFound
}
func (self *SRegion) list(service, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.client.list(service, self.RegionName, resource, params)
func (self *SRegion) list(service, resource string, query url.Values) (jsonutils.JSONObject, error) {
return self.client.list(service, self.RegionName, resource, query)
}
func (self *SRegion) get(service, resource, id string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.client.get(service, self.RegionName, resource, id, params)
func (self *SRegion) get(service, resource, id string, query url.Values) (jsonutils.JSONObject, error) {
return self.client.get(service, self.RegionName, resource, id, query)
}
func (self *SRegion) GetIStoragecacheById(id string) (cloudprovider.ICloudStoragecache, error) {
+4 -2
View File
@@ -15,6 +15,8 @@
package oracle
import (
"net/url"
api "yunion.io/x/cloudmux/pkg/apis/compute"
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/cloudmux/pkg/multicloud"
@@ -88,9 +90,9 @@ func (self *SSecurityGroup) GetProjectId() string {
}
func (self *SRegion) GetSecurityGroups(vpcId string) ([]SSecurityGroup, error) {
params := map[string]interface{}{}
params := url.Values{}
if len(vpcId) > 0 {
params["vcnId"] = vpcId
params.Set("vcnId", vpcId)
}
resp, err := self.list(SERVICE_IAAS, "securityLists", params)
if err != nil {