-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from cxl123156/br_release_sdk_v3
add rds cpu&mem field, support input ak&sk from command line
- Loading branch information
Showing
37 changed files
with
1,365 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package collector | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/agiledragon/gomonkey/v2" | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/apig/v2/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestShowDetailsOfInstanceV2(t *testing.T) { | ||
apigClient := getAPICSClient() | ||
id := "0001-0001-0000001" | ||
name := "instance01" | ||
instanceInfo := model.ShowDetailsOfInstanceV2Response{ | ||
Id: &id, | ||
InstanceName: &name, | ||
} | ||
patches := gomonkey.ApplyMethodReturn(apigClient, "ShowDetailsOfInstanceV2", &instanceInfo, nil) | ||
defer patches.Reset() | ||
resp, err := showDetailsOfInstanceV2(id) | ||
assert.Equal(t, true, err == nil) | ||
assert.Equal(t, name, *resp.InstanceName) | ||
} | ||
|
||
func TestGetResourceInfo(t *testing.T) { | ||
var ( | ||
id = "0001-0001-000001" | ||
name = "instance01" | ||
eip = "*.*.*.*" | ||
epId = "0" | ||
apiId = "api0000001" | ||
emptyStr = "" | ||
) | ||
|
||
sysConfig := map[string][]string{ | ||
"instance_id": {"requests"}, | ||
"instance_id,api_id": {"req_count"}, | ||
"instance_id,node_ip": {"node_qps"}, | ||
} | ||
|
||
instances := []model.RespInstanceBase{{Id: &id, InstanceName: &name, EipAddress: &eip, EnterpriseProjectId: &epId}} | ||
apis := []model.ApiInfoPerPage{{Id: &apiId, Name: "api1", GroupName: &emptyStr, GroupId: "group1"}} | ||
instance := model.ShowDetailsOfInstanceV2Response{ | ||
NodeIps: &model.NodeIps{ | ||
Livedata: &[]string{"*.*.*.2"}, | ||
Shubao: &[]string{"*.*.*.3"}, | ||
}, | ||
} | ||
|
||
patches := gomonkey.ApplyFuncReturn(getMetricConfigMap, sysConfig) | ||
patches.ApplyFuncReturn(getAllAPICInstances, instances, nil) | ||
patches.ApplyFuncReturn(getApisOfInstances, apis, nil) | ||
patches.ApplyFuncReturn(showDetailsOfInstanceV2, &instance, nil) | ||
defer patches.Reset() | ||
var getter = APICInfo{} | ||
label, metrics := getter.GetResourceInfo() | ||
assert.Equal(t, 4, len(label)) | ||
assert.Equal(t, 4, len(metrics)) | ||
} | ||
|
||
func TestGetAllAPICInstances(t *testing.T) { | ||
var ( | ||
id = "0001-0001-000001" | ||
name = "instance01" | ||
) | ||
respPage1 := model.ListInstancesV2Response{ | ||
HttpStatusCode: 200, | ||
Instances: &[]model.RespInstanceBase{ | ||
{Id: &id, InstanceName: &name}, | ||
}, | ||
} | ||
respPage2 := model.ListInstancesV2Response{ | ||
HttpStatusCode: 200, | ||
Instances: &[]model.RespInstanceBase{}, | ||
} | ||
apicClient := getAPICSClient() | ||
patches := gomonkey.ApplyMethodFunc(apicClient, "ListInstancesV2", func(req *model.ListInstancesV2Request) (*model.ListInstancesV2Response, error) { | ||
if *req.Offset == 0 { | ||
return &respPage1, nil | ||
} | ||
return &respPage2, nil | ||
}) | ||
defer patches.Reset() | ||
instances, err := getAllAPICInstances() | ||
assert.Equal(t, true, err == nil) | ||
assert.Equal(t, 1, len(instances)) | ||
} | ||
|
||
func TestGetApisOfInstances(t *testing.T) { | ||
var ( | ||
id = "0001-0001-000001" | ||
name = "api01" | ||
) | ||
respPage1 := model.ListApisV2Response{ | ||
HttpStatusCode: 200, | ||
Apis: &[]model.ApiInfoPerPage{ | ||
{Id: &id, Name: name}, | ||
}, | ||
} | ||
respPage2 := model.ListApisV2Response{ | ||
HttpStatusCode: 200, | ||
Apis: &[]model.ApiInfoPerPage{}, | ||
} | ||
apicClient := getAPICSClient() | ||
patches := gomonkey.ApplyMethodFunc(apicClient, "ListApisV2", func(req *model.ListApisV2Request) (*model.ListApisV2Response, error) { | ||
if *req.Offset == 0 { | ||
return &respPage1, nil | ||
} | ||
return &respPage2, nil | ||
}) | ||
defer patches.Reset() | ||
apis, err := getApisOfInstances("00001") | ||
assert.Equal(t, true, err == nil) | ||
assert.Equal(t, 1, len(apis)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package collector | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/agiledragon/gomonkey/v2" | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/def" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestApiGGetResourceInfo(t *testing.T) { | ||
respPage1 := ListAppsResponse{ | ||
HttpStatusCode: 200, | ||
Apps: &[]Apps{ | ||
{ID: "app-0001", Name: "app1"}, | ||
}, | ||
} | ||
respPage2 := ListAppsResponse{ | ||
HttpStatusCode: 200, | ||
Apps: &[]Apps{}, | ||
} | ||
sysConfig := map[string][]string{"api_id": {"req_count"}} | ||
|
||
apigClient := getAPIGSClient() | ||
patches := gomonkey.ApplyFuncReturn(getMetricConfigMap, sysConfig) | ||
patches.ApplyMethodFunc(apigClient.HcClient, "Sync", func(req interface{}, reqDef *def.HttpRequestDef) (interface{}, error) { | ||
request, ok := req.(*ListAppsRequest) | ||
if !ok { | ||
return nil, errors.New("test error") | ||
} | ||
if *request.Offset == 0 { | ||
return &respPage1, nil | ||
} | ||
return &respPage2, nil | ||
}) | ||
defer patches.Reset() | ||
|
||
var getter APIGInfo | ||
labels, metrics := getter.GetResourceInfo() | ||
assert.Equal(t, 1, len(labels)) | ||
assert.Equal(t, 1, len(metrics)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package collector | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/agiledragon/gomonkey/v2" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAsGetResourceInfo(t *testing.T) { | ||
sysConfig := map[string][]string{"AutoScalingGroup": {"req_count"}} | ||
groups := []ResourceBaseInfo{ | ||
{ID: "0001-0001-000000001", Name: "group01", EpId: "0"}, | ||
} | ||
patches := gomonkey.ApplyFuncReturn(getMetricConfigMap, sysConfig) | ||
patches.ApplyFuncReturn(getResourcesBaseInfoFromRMS, groups, nil) | ||
defer patches.Reset() | ||
|
||
var asGetter ASInfo | ||
labels, metrics := asGetter.GetResourceInfo() | ||
assert.Equal(t, 1, len(labels)) | ||
assert.Equal(t, 1, len(metrics)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package collector | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/agiledragon/gomonkey/v2" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBmsGetResourceInfo(t *testing.T) { | ||
sysConfig := map[string][]string{"instance_id": {"cpu_utils"}} | ||
instances := []EcsInstancesInfo{ | ||
{ResourceBaseInfo: ResourceBaseInfo{ID: "0001-0001-000000001", Name: "host01", EpId: "0"}}, | ||
} | ||
patches := gomonkey.ApplyFuncReturn(getMetricConfigMap, sysConfig) | ||
patches.ApplyFuncReturn(getAllServerFromRMS, instances, nil) | ||
patches.ApplyFunc(loadAgentDimensions, func(_ string) { return }) | ||
patches.ApplyFuncReturn(getIPFromEcsInfo, "") | ||
defer patches.Reset() | ||
|
||
var bmsGetter BMSInfo | ||
labels, metrics := bmsGetter.GetResourceInfo() | ||
assert.Equal(t, 1, len(labels)) | ||
assert.Equal(t, 1, len(metrics)) | ||
|
||
var servicesGetter SERVICEBMSInfo | ||
serviceLabel, _ := servicesGetter.GetResourceInfo() | ||
assert.Equal(t, 1, len(serviceLabel)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package collector | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/agiledragon/gomonkey/v2" | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cbr/v1/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCbrGetResourceInfo(t *testing.T) { | ||
defaultEpId := "0" | ||
respPage1 := model.ListVaultResponse{ | ||
HttpStatusCode: 200, | ||
Vaults: &[]model.Vault{ | ||
{Id: "app-0001", Name: "app1", EnterpriseProjectId: &defaultEpId}, | ||
}, | ||
} | ||
respPage2 := model.ListVaultResponse{ | ||
HttpStatusCode: 200, | ||
Vaults: &[]model.Vault{}, | ||
} | ||
sysConfig := map[string][]string{"instance_id": {"vault_util"}} | ||
|
||
cbrClient := getCBRClient() | ||
patches := gomonkey.ApplyFuncReturn(getMetricConfigMap, sysConfig) | ||
patches.ApplyFuncReturn(getResourceFromRMS, false) | ||
patches.ApplyMethodFunc(cbrClient, "ListVault", func(req *model.ListVaultRequest) (*model.ListVaultResponse, error) { | ||
if *req.Offset == 0 { | ||
return &respPage1, nil | ||
} | ||
return &respPage2, nil | ||
}) | ||
defer patches.Reset() | ||
|
||
var cbrgetter CBRInfo | ||
labels, metrics := cbrgetter.GetResourceInfo() | ||
assert.Equal(t, 1, len(labels)) | ||
assert.Equal(t, 1, len(metrics)) | ||
} |
Oops, something went wrong.