diff --git a/cmd/otelcontribcol/components.go b/cmd/otelcontribcol/components.go index 5f0e069cf3bd..5363acafef6a 100644 --- a/cmd/otelcontribcol/components.go +++ b/cmd/otelcontribcol/components.go @@ -432,6 +432,7 @@ func components() (otelcol.Factories, error) { factories.ReceiverModules[haproxyreceiver.NewFactory().Type()] = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver v0.106.1" factories.ReceiverModules[hostmetricsreceiver.NewFactory().Type()] = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.106.1" factories.ReceiverModules[httpcheckreceiver.NewFactory().Type()] = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver v0.106.1" + factories.ReceiverModules[huaweicloudcesreceiver.NewFactory().Type()] = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver v0.106.1" factories.ReceiverModules[influxdbreceiver.NewFactory().Type()] = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/influxdbreceiver v0.106.1" factories.ReceiverModules[iisreceiver.NewFactory().Type()] = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/iisreceiver v0.106.1" factories.ReceiverModules[jaegerreceiver.NewFactory().Type()] = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.106.1" diff --git a/receiver/huaweicloudcesreceiver/README.md b/receiver/huaweicloudcesreceiver/README.md index a6c8ce6c2e6b..a9c4b867d4ac 100644 --- a/receiver/huaweicloudcesreceiver/README.md +++ b/receiver/huaweicloudcesreceiver/README.md @@ -52,6 +52,8 @@ receivers: collection_interval: 3h initial_delay: 5s region_name: eu-west-101 + access_key: ${env:HUAWEICLOUD_SDK_AK} + secret_key: ${env:HUAWEICLOUD_SDK_SK} project_id: "project_1" period: 300 filter: average diff --git a/receiver/huaweicloudcesreceiver/ces_client.go b/receiver/huaweicloudcesreceiver/ces_client.go new file mode 100644 index 000000000000..927274b5ccaa --- /dev/null +++ b/receiver/huaweicloudcesreceiver/ces_client.go @@ -0,0 +1,60 @@ +package huaweicloudcesreceiver + +import ( + ces "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1" + "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model" +) + +//go:generate mockery --name CesClient +type CesClient interface { + BatchListMetricData(request *model.BatchListMetricDataRequest) (*model.BatchListMetricDataResponse, error) + BatchListMetricDataInvoker(request *model.BatchListMetricDataRequest) *ces.BatchListMetricDataInvoker + CreateAlarm(request *model.CreateAlarmRequest) (*model.CreateAlarmResponse, error) + CreateAlarmInvoker(request *model.CreateAlarmRequest) *ces.CreateAlarmInvoker + CreateAlarmTemplate(request *model.CreateAlarmTemplateRequest) (*model.CreateAlarmTemplateResponse, error) + CreateAlarmTemplateInvoker(request *model.CreateAlarmTemplateRequest) *ces.CreateAlarmTemplateInvoker + CreateEvents(request *model.CreateEventsRequest) (*model.CreateEventsResponse, error) + CreateEventsInvoker(request *model.CreateEventsRequest) *ces.CreateEventsInvoker + CreateMetricData(request *model.CreateMetricDataRequest) (*model.CreateMetricDataResponse, error) + CreateMetricDataInvoker(request *model.CreateMetricDataRequest) *ces.CreateMetricDataInvoker + CreateResourceGroup(request *model.CreateResourceGroupRequest) (*model.CreateResourceGroupResponse, error) + CreateResourceGroupInvoker(request *model.CreateResourceGroupRequest) *ces.CreateResourceGroupInvoker + DeleteAlarm(request *model.DeleteAlarmRequest) (*model.DeleteAlarmResponse, error) + DeleteAlarmInvoker(request *model.DeleteAlarmRequest) *ces.DeleteAlarmInvoker + DeleteAlarmTemplate(request *model.DeleteAlarmTemplateRequest) (*model.DeleteAlarmTemplateResponse, error) + DeleteAlarmTemplateInvoker(request *model.DeleteAlarmTemplateRequest) *ces.DeleteAlarmTemplateInvoker + DeleteResourceGroup(request *model.DeleteResourceGroupRequest) (*model.DeleteResourceGroupResponse, error) + DeleteResourceGroupInvoker(request *model.DeleteResourceGroupRequest) *ces.DeleteResourceGroupInvoker + ListAlarmHistories(request *model.ListAlarmHistoriesRequest) (*model.ListAlarmHistoriesResponse, error) + ListAlarmHistoriesInvoker(request *model.ListAlarmHistoriesRequest) *ces.ListAlarmHistoriesInvoker + ListAlarmTemplates(request *model.ListAlarmTemplatesRequest) (*model.ListAlarmTemplatesResponse, error) + ListAlarmTemplatesInvoker(request *model.ListAlarmTemplatesRequest) *ces.ListAlarmTemplatesInvoker + ListAlarms(request *model.ListAlarmsRequest) (*model.ListAlarmsResponse, error) + ListAlarmsInvoker(request *model.ListAlarmsRequest) *ces.ListAlarmsInvoker + ListEventDetail(request *model.ListEventDetailRequest) (*model.ListEventDetailResponse, error) + ListEventDetailInvoker(request *model.ListEventDetailRequest) *ces.ListEventDetailInvoker + ListEvents(request *model.ListEventsRequest) (*model.ListEventsResponse, error) + ListEventsInvoker(request *model.ListEventsRequest) *ces.ListEventsInvoker + ListMetrics(request *model.ListMetricsRequest) (*model.ListMetricsResponse, error) + ListMetricsInvoker(request *model.ListMetricsRequest) *ces.ListMetricsInvoker + ListResourceGroup(request *model.ListResourceGroupRequest) (*model.ListResourceGroupResponse, error) + ListResourceGroupInvoker(request *model.ListResourceGroupRequest) *ces.ListResourceGroupInvoker + ShowAlarm(request *model.ShowAlarmRequest) (*model.ShowAlarmResponse, error) + ShowAlarmInvoker(request *model.ShowAlarmRequest) *ces.ShowAlarmInvoker + ShowEventData(request *model.ShowEventDataRequest) (*model.ShowEventDataResponse, error) + ShowEventDataInvoker(request *model.ShowEventDataRequest) *ces.ShowEventDataInvoker + ShowMetricData(request *model.ShowMetricDataRequest) (*model.ShowMetricDataResponse, error) + ShowMetricDataInvoker(request *model.ShowMetricDataRequest) *ces.ShowMetricDataInvoker + ShowQuotas(request *model.ShowQuotasRequest) (*model.ShowQuotasResponse, error) + ShowQuotasInvoker(request *model.ShowQuotasRequest) *ces.ShowQuotasInvoker + ShowResourceGroup(request *model.ShowResourceGroupRequest) (*model.ShowResourceGroupResponse, error) + ShowResourceGroupInvoker(request *model.ShowResourceGroupRequest) *ces.ShowResourceGroupInvoker + UpdateAlarm(request *model.UpdateAlarmRequest) (*model.UpdateAlarmResponse, error) + UpdateAlarmAction(request *model.UpdateAlarmActionRequest) (*model.UpdateAlarmActionResponse, error) + UpdateAlarmActionInvoker(request *model.UpdateAlarmActionRequest) *ces.UpdateAlarmActionInvoker + UpdateAlarmInvoker(request *model.UpdateAlarmRequest) *ces.UpdateAlarmInvoker + UpdateAlarmTemplate(request *model.UpdateAlarmTemplateRequest) (*model.UpdateAlarmTemplateResponse, error) + UpdateAlarmTemplateInvoker(request *model.UpdateAlarmTemplateRequest) *ces.UpdateAlarmTemplateInvoker + UpdateResourceGroup(request *model.UpdateResourceGroupRequest) (*model.UpdateResourceGroupResponse, error) + UpdateResourceGroupInvoker(request *model.UpdateResourceGroupRequest) *ces.UpdateResourceGroupInvoker +} diff --git a/receiver/huaweicloudcesreceiver/config.go b/receiver/huaweicloudcesreceiver/config.go index 94c2266f6156..baeb6be0561e 100644 --- a/receiver/huaweicloudcesreceiver/config.go +++ b/receiver/huaweicloudcesreceiver/config.go @@ -7,10 +7,10 @@ import ( "errors" "fmt" "slices" - "strings" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" + "go.opentelemetry.io/collector/config/configopaque" "go.opentelemetry.io/collector/receiver/scraperhelper" "go.uber.org/multierr" ) @@ -60,6 +60,9 @@ type Config struct { } type HuaweiSessionConfig struct { + AccessKey configopaque.String `mapstructure:"access_key"` + + SecretKey configopaque.String `mapstructure:"secret_key"` // RegionName is the full name of the CES region exporter should send metrics to RegionName string `mapstructure:"region_name"` // Number of seconds before timing out a request. @@ -104,11 +107,3 @@ func (config *Config) Validate() error { return err } - -func KeysString(m map[string]any) string { - keys := make([]string, 0, len(m)) - for k := range m { - keys = append(keys, k) - } - return "[" + strings.Join(keys, ", ") + "]" -} diff --git a/receiver/huaweicloudcesreceiver/factory_test.go b/receiver/huaweicloudcesreceiver/factory_test.go new file mode 100644 index 000000000000..c5b90ac3952e --- /dev/null +++ b/receiver/huaweicloudcesreceiver/factory_test.go @@ -0,0 +1,40 @@ +package huaweicloudcesreceiver + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/receiver/receivertest" +) + +func TestNewFactory(t *testing.T) { + factory := NewFactory() + assert.NotNil(t, factory) + assert.Equal(t, component.MustNewType("huaweicloudcesreceiver"), factory.Type()) +} + +func TestCreateDefaultConfig(t *testing.T) { + factory := NewFactory() + config := factory.CreateDefaultConfig() + assert.NotNil(t, config) + assert.NoError(t, componenttest.CheckConfigStruct(config)) +} + +func TestCreateMetricsReceiver(t *testing.T) { + factory := NewFactory() + config := factory.CreateDefaultConfig() + + rConfig := config.(*Config) + rConfig.CollectionInterval = 60 * time.Second + rConfig.InitialDelay = time.Second + + nextConsumer := new(consumertest.MetricsSink) + receiver, err := factory.CreateMetricsReceiver(context.Background(), receivertest.NewNopSettings(), config, nextConsumer) + assert.NoError(t, err) + assert.NotNil(t, receiver) +} diff --git a/receiver/huaweicloudcesreceiver/generated_package_test.go b/receiver/huaweicloudcesreceiver/generated_package_test.go index ebacfa323d23..e3abd7c8e13f 100644 --- a/receiver/huaweicloudcesreceiver/generated_package_test.go +++ b/receiver/huaweicloudcesreceiver/generated_package_test.go @@ -3,8 +3,9 @@ package huaweicloudcesreceiver import ( - "go.uber.org/goleak" "testing" + + "go.uber.org/goleak" ) func TestMain(m *testing.M) { diff --git a/receiver/huaweicloudcesreceiver/go.mod b/receiver/huaweicloudcesreceiver/go.mod index a5dbe75ed696..17e62183b241 100644 --- a/receiver/huaweicloudcesreceiver/go.mod +++ b/receiver/huaweicloudcesreceiver/go.mod @@ -46,6 +46,7 @@ require ( github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rs/cors v1.11.0 // indirect + github.com/stretchr/objx v0.5.2 // indirect github.com/tjfoc/gmsm v1.4.1 // indirect go.mongodb.org/mongo-driver v1.15.0 // indirect go.opentelemetry.io/collector v0.106.1 // indirect diff --git a/receiver/huaweicloudcesreceiver/go.sum b/receiver/huaweicloudcesreceiver/go.sum index 10f5d7a9bd1d..41afff623409 100644 --- a/receiver/huaweicloudcesreceiver/go.sum +++ b/receiver/huaweicloudcesreceiver/go.sum @@ -101,6 +101,8 @@ github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= diff --git a/receiver/huaweicloudcesreceiver/internal/ces_to_otlp.go b/receiver/huaweicloudcesreceiver/internal/ces_to_otlp.go index 7baff930a7ca..d50ef431ff88 100644 --- a/receiver/huaweicloudcesreceiver/internal/ces_to_otlp.go +++ b/receiver/huaweicloudcesreceiver/internal/ces_to_otlp.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal +package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver/internal" import ( "time" diff --git a/receiver/huaweicloudcesreceiver/mocks/CesClient.go b/receiver/huaweicloudcesreceiver/mocks/CesClient.go new file mode 100644 index 000000000000..d242db9c9b57 --- /dev/null +++ b/receiver/huaweicloudcesreceiver/mocks/CesClient.go @@ -0,0 +1,1278 @@ +// Code generated by mockery v2.44.1. DO NOT EDIT. + +package mocks + +import ( + v1 "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1" + model "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model" + mock "github.com/stretchr/testify/mock" +) + +// CesClient is an autogenerated mock type for the CesClient type +type CesClient struct { + mock.Mock +} + +// BatchListMetricData provides a mock function with given fields: request +func (_m *CesClient) BatchListMetricData(request *model.BatchListMetricDataRequest) (*model.BatchListMetricDataResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for BatchListMetricData") + } + + var r0 *model.BatchListMetricDataResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.BatchListMetricDataRequest) (*model.BatchListMetricDataResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.BatchListMetricDataRequest) *model.BatchListMetricDataResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.BatchListMetricDataResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.BatchListMetricDataRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// BatchListMetricDataInvoker provides a mock function with given fields: request +func (_m *CesClient) BatchListMetricDataInvoker(request *model.BatchListMetricDataRequest) *v1.BatchListMetricDataInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for BatchListMetricDataInvoker") + } + + var r0 *v1.BatchListMetricDataInvoker + if rf, ok := ret.Get(0).(func(*model.BatchListMetricDataRequest) *v1.BatchListMetricDataInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.BatchListMetricDataInvoker) + } + } + + return r0 +} + +// CreateAlarm provides a mock function with given fields: request +func (_m *CesClient) CreateAlarm(request *model.CreateAlarmRequest) (*model.CreateAlarmResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateAlarm") + } + + var r0 *model.CreateAlarmResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.CreateAlarmRequest) (*model.CreateAlarmResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.CreateAlarmRequest) *model.CreateAlarmResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.CreateAlarmResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.CreateAlarmRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateAlarmInvoker provides a mock function with given fields: request +func (_m *CesClient) CreateAlarmInvoker(request *model.CreateAlarmRequest) *v1.CreateAlarmInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateAlarmInvoker") + } + + var r0 *v1.CreateAlarmInvoker + if rf, ok := ret.Get(0).(func(*model.CreateAlarmRequest) *v1.CreateAlarmInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.CreateAlarmInvoker) + } + } + + return r0 +} + +// CreateAlarmTemplate provides a mock function with given fields: request +func (_m *CesClient) CreateAlarmTemplate(request *model.CreateAlarmTemplateRequest) (*model.CreateAlarmTemplateResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateAlarmTemplate") + } + + var r0 *model.CreateAlarmTemplateResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.CreateAlarmTemplateRequest) (*model.CreateAlarmTemplateResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.CreateAlarmTemplateRequest) *model.CreateAlarmTemplateResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.CreateAlarmTemplateResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.CreateAlarmTemplateRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateAlarmTemplateInvoker provides a mock function with given fields: request +func (_m *CesClient) CreateAlarmTemplateInvoker(request *model.CreateAlarmTemplateRequest) *v1.CreateAlarmTemplateInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateAlarmTemplateInvoker") + } + + var r0 *v1.CreateAlarmTemplateInvoker + if rf, ok := ret.Get(0).(func(*model.CreateAlarmTemplateRequest) *v1.CreateAlarmTemplateInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.CreateAlarmTemplateInvoker) + } + } + + return r0 +} + +// CreateEvents provides a mock function with given fields: request +func (_m *CesClient) CreateEvents(request *model.CreateEventsRequest) (*model.CreateEventsResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateEvents") + } + + var r0 *model.CreateEventsResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.CreateEventsRequest) (*model.CreateEventsResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.CreateEventsRequest) *model.CreateEventsResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.CreateEventsResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.CreateEventsRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateEventsInvoker provides a mock function with given fields: request +func (_m *CesClient) CreateEventsInvoker(request *model.CreateEventsRequest) *v1.CreateEventsInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateEventsInvoker") + } + + var r0 *v1.CreateEventsInvoker + if rf, ok := ret.Get(0).(func(*model.CreateEventsRequest) *v1.CreateEventsInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.CreateEventsInvoker) + } + } + + return r0 +} + +// CreateMetricData provides a mock function with given fields: request +func (_m *CesClient) CreateMetricData(request *model.CreateMetricDataRequest) (*model.CreateMetricDataResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateMetricData") + } + + var r0 *model.CreateMetricDataResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.CreateMetricDataRequest) (*model.CreateMetricDataResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.CreateMetricDataRequest) *model.CreateMetricDataResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.CreateMetricDataResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.CreateMetricDataRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateMetricDataInvoker provides a mock function with given fields: request +func (_m *CesClient) CreateMetricDataInvoker(request *model.CreateMetricDataRequest) *v1.CreateMetricDataInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateMetricDataInvoker") + } + + var r0 *v1.CreateMetricDataInvoker + if rf, ok := ret.Get(0).(func(*model.CreateMetricDataRequest) *v1.CreateMetricDataInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.CreateMetricDataInvoker) + } + } + + return r0 +} + +// CreateResourceGroup provides a mock function with given fields: request +func (_m *CesClient) CreateResourceGroup(request *model.CreateResourceGroupRequest) (*model.CreateResourceGroupResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateResourceGroup") + } + + var r0 *model.CreateResourceGroupResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.CreateResourceGroupRequest) (*model.CreateResourceGroupResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.CreateResourceGroupRequest) *model.CreateResourceGroupResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.CreateResourceGroupResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.CreateResourceGroupRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateResourceGroupInvoker provides a mock function with given fields: request +func (_m *CesClient) CreateResourceGroupInvoker(request *model.CreateResourceGroupRequest) *v1.CreateResourceGroupInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for CreateResourceGroupInvoker") + } + + var r0 *v1.CreateResourceGroupInvoker + if rf, ok := ret.Get(0).(func(*model.CreateResourceGroupRequest) *v1.CreateResourceGroupInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.CreateResourceGroupInvoker) + } + } + + return r0 +} + +// DeleteAlarm provides a mock function with given fields: request +func (_m *CesClient) DeleteAlarm(request *model.DeleteAlarmRequest) (*model.DeleteAlarmResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for DeleteAlarm") + } + + var r0 *model.DeleteAlarmResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.DeleteAlarmRequest) (*model.DeleteAlarmResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.DeleteAlarmRequest) *model.DeleteAlarmResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeleteAlarmResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.DeleteAlarmRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteAlarmInvoker provides a mock function with given fields: request +func (_m *CesClient) DeleteAlarmInvoker(request *model.DeleteAlarmRequest) *v1.DeleteAlarmInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for DeleteAlarmInvoker") + } + + var r0 *v1.DeleteAlarmInvoker + if rf, ok := ret.Get(0).(func(*model.DeleteAlarmRequest) *v1.DeleteAlarmInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.DeleteAlarmInvoker) + } + } + + return r0 +} + +// DeleteAlarmTemplate provides a mock function with given fields: request +func (_m *CesClient) DeleteAlarmTemplate(request *model.DeleteAlarmTemplateRequest) (*model.DeleteAlarmTemplateResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for DeleteAlarmTemplate") + } + + var r0 *model.DeleteAlarmTemplateResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.DeleteAlarmTemplateRequest) (*model.DeleteAlarmTemplateResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.DeleteAlarmTemplateRequest) *model.DeleteAlarmTemplateResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeleteAlarmTemplateResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.DeleteAlarmTemplateRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteAlarmTemplateInvoker provides a mock function with given fields: request +func (_m *CesClient) DeleteAlarmTemplateInvoker(request *model.DeleteAlarmTemplateRequest) *v1.DeleteAlarmTemplateInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for DeleteAlarmTemplateInvoker") + } + + var r0 *v1.DeleteAlarmTemplateInvoker + if rf, ok := ret.Get(0).(func(*model.DeleteAlarmTemplateRequest) *v1.DeleteAlarmTemplateInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.DeleteAlarmTemplateInvoker) + } + } + + return r0 +} + +// DeleteResourceGroup provides a mock function with given fields: request +func (_m *CesClient) DeleteResourceGroup(request *model.DeleteResourceGroupRequest) (*model.DeleteResourceGroupResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for DeleteResourceGroup") + } + + var r0 *model.DeleteResourceGroupResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.DeleteResourceGroupRequest) (*model.DeleteResourceGroupResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.DeleteResourceGroupRequest) *model.DeleteResourceGroupResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeleteResourceGroupResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.DeleteResourceGroupRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteResourceGroupInvoker provides a mock function with given fields: request +func (_m *CesClient) DeleteResourceGroupInvoker(request *model.DeleteResourceGroupRequest) *v1.DeleteResourceGroupInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for DeleteResourceGroupInvoker") + } + + var r0 *v1.DeleteResourceGroupInvoker + if rf, ok := ret.Get(0).(func(*model.DeleteResourceGroupRequest) *v1.DeleteResourceGroupInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.DeleteResourceGroupInvoker) + } + } + + return r0 +} + +// ListAlarmHistories provides a mock function with given fields: request +func (_m *CesClient) ListAlarmHistories(request *model.ListAlarmHistoriesRequest) (*model.ListAlarmHistoriesResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListAlarmHistories") + } + + var r0 *model.ListAlarmHistoriesResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ListAlarmHistoriesRequest) (*model.ListAlarmHistoriesResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ListAlarmHistoriesRequest) *model.ListAlarmHistoriesResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ListAlarmHistoriesResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ListAlarmHistoriesRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListAlarmHistoriesInvoker provides a mock function with given fields: request +func (_m *CesClient) ListAlarmHistoriesInvoker(request *model.ListAlarmHistoriesRequest) *v1.ListAlarmHistoriesInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListAlarmHistoriesInvoker") + } + + var r0 *v1.ListAlarmHistoriesInvoker + if rf, ok := ret.Get(0).(func(*model.ListAlarmHistoriesRequest) *v1.ListAlarmHistoriesInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ListAlarmHistoriesInvoker) + } + } + + return r0 +} + +// ListAlarmTemplates provides a mock function with given fields: request +func (_m *CesClient) ListAlarmTemplates(request *model.ListAlarmTemplatesRequest) (*model.ListAlarmTemplatesResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListAlarmTemplates") + } + + var r0 *model.ListAlarmTemplatesResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ListAlarmTemplatesRequest) (*model.ListAlarmTemplatesResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ListAlarmTemplatesRequest) *model.ListAlarmTemplatesResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ListAlarmTemplatesResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ListAlarmTemplatesRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListAlarmTemplatesInvoker provides a mock function with given fields: request +func (_m *CesClient) ListAlarmTemplatesInvoker(request *model.ListAlarmTemplatesRequest) *v1.ListAlarmTemplatesInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListAlarmTemplatesInvoker") + } + + var r0 *v1.ListAlarmTemplatesInvoker + if rf, ok := ret.Get(0).(func(*model.ListAlarmTemplatesRequest) *v1.ListAlarmTemplatesInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ListAlarmTemplatesInvoker) + } + } + + return r0 +} + +// ListAlarms provides a mock function with given fields: request +func (_m *CesClient) ListAlarms(request *model.ListAlarmsRequest) (*model.ListAlarmsResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListAlarms") + } + + var r0 *model.ListAlarmsResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ListAlarmsRequest) (*model.ListAlarmsResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ListAlarmsRequest) *model.ListAlarmsResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ListAlarmsResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ListAlarmsRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListAlarmsInvoker provides a mock function with given fields: request +func (_m *CesClient) ListAlarmsInvoker(request *model.ListAlarmsRequest) *v1.ListAlarmsInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListAlarmsInvoker") + } + + var r0 *v1.ListAlarmsInvoker + if rf, ok := ret.Get(0).(func(*model.ListAlarmsRequest) *v1.ListAlarmsInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ListAlarmsInvoker) + } + } + + return r0 +} + +// ListEventDetail provides a mock function with given fields: request +func (_m *CesClient) ListEventDetail(request *model.ListEventDetailRequest) (*model.ListEventDetailResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListEventDetail") + } + + var r0 *model.ListEventDetailResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ListEventDetailRequest) (*model.ListEventDetailResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ListEventDetailRequest) *model.ListEventDetailResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ListEventDetailResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ListEventDetailRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListEventDetailInvoker provides a mock function with given fields: request +func (_m *CesClient) ListEventDetailInvoker(request *model.ListEventDetailRequest) *v1.ListEventDetailInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListEventDetailInvoker") + } + + var r0 *v1.ListEventDetailInvoker + if rf, ok := ret.Get(0).(func(*model.ListEventDetailRequest) *v1.ListEventDetailInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ListEventDetailInvoker) + } + } + + return r0 +} + +// ListEvents provides a mock function with given fields: request +func (_m *CesClient) ListEvents(request *model.ListEventsRequest) (*model.ListEventsResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListEvents") + } + + var r0 *model.ListEventsResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ListEventsRequest) (*model.ListEventsResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ListEventsRequest) *model.ListEventsResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ListEventsResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ListEventsRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListEventsInvoker provides a mock function with given fields: request +func (_m *CesClient) ListEventsInvoker(request *model.ListEventsRequest) *v1.ListEventsInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListEventsInvoker") + } + + var r0 *v1.ListEventsInvoker + if rf, ok := ret.Get(0).(func(*model.ListEventsRequest) *v1.ListEventsInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ListEventsInvoker) + } + } + + return r0 +} + +// ListMetrics provides a mock function with given fields: request +func (_m *CesClient) ListMetrics(request *model.ListMetricsRequest) (*model.ListMetricsResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListMetrics") + } + + var r0 *model.ListMetricsResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ListMetricsRequest) (*model.ListMetricsResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ListMetricsRequest) *model.ListMetricsResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ListMetricsResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ListMetricsRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListMetricsInvoker provides a mock function with given fields: request +func (_m *CesClient) ListMetricsInvoker(request *model.ListMetricsRequest) *v1.ListMetricsInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListMetricsInvoker") + } + + var r0 *v1.ListMetricsInvoker + if rf, ok := ret.Get(0).(func(*model.ListMetricsRequest) *v1.ListMetricsInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ListMetricsInvoker) + } + } + + return r0 +} + +// ListResourceGroup provides a mock function with given fields: request +func (_m *CesClient) ListResourceGroup(request *model.ListResourceGroupRequest) (*model.ListResourceGroupResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListResourceGroup") + } + + var r0 *model.ListResourceGroupResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ListResourceGroupRequest) (*model.ListResourceGroupResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ListResourceGroupRequest) *model.ListResourceGroupResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ListResourceGroupResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ListResourceGroupRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListResourceGroupInvoker provides a mock function with given fields: request +func (_m *CesClient) ListResourceGroupInvoker(request *model.ListResourceGroupRequest) *v1.ListResourceGroupInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ListResourceGroupInvoker") + } + + var r0 *v1.ListResourceGroupInvoker + if rf, ok := ret.Get(0).(func(*model.ListResourceGroupRequest) *v1.ListResourceGroupInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ListResourceGroupInvoker) + } + } + + return r0 +} + +// ShowAlarm provides a mock function with given fields: request +func (_m *CesClient) ShowAlarm(request *model.ShowAlarmRequest) (*model.ShowAlarmResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowAlarm") + } + + var r0 *model.ShowAlarmResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ShowAlarmRequest) (*model.ShowAlarmResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ShowAlarmRequest) *model.ShowAlarmResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ShowAlarmResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ShowAlarmRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ShowAlarmInvoker provides a mock function with given fields: request +func (_m *CesClient) ShowAlarmInvoker(request *model.ShowAlarmRequest) *v1.ShowAlarmInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowAlarmInvoker") + } + + var r0 *v1.ShowAlarmInvoker + if rf, ok := ret.Get(0).(func(*model.ShowAlarmRequest) *v1.ShowAlarmInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ShowAlarmInvoker) + } + } + + return r0 +} + +// ShowEventData provides a mock function with given fields: request +func (_m *CesClient) ShowEventData(request *model.ShowEventDataRequest) (*model.ShowEventDataResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowEventData") + } + + var r0 *model.ShowEventDataResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ShowEventDataRequest) (*model.ShowEventDataResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ShowEventDataRequest) *model.ShowEventDataResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ShowEventDataResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ShowEventDataRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ShowEventDataInvoker provides a mock function with given fields: request +func (_m *CesClient) ShowEventDataInvoker(request *model.ShowEventDataRequest) *v1.ShowEventDataInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowEventDataInvoker") + } + + var r0 *v1.ShowEventDataInvoker + if rf, ok := ret.Get(0).(func(*model.ShowEventDataRequest) *v1.ShowEventDataInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ShowEventDataInvoker) + } + } + + return r0 +} + +// ShowMetricData provides a mock function with given fields: request +func (_m *CesClient) ShowMetricData(request *model.ShowMetricDataRequest) (*model.ShowMetricDataResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowMetricData") + } + + var r0 *model.ShowMetricDataResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ShowMetricDataRequest) (*model.ShowMetricDataResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ShowMetricDataRequest) *model.ShowMetricDataResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ShowMetricDataResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ShowMetricDataRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ShowMetricDataInvoker provides a mock function with given fields: request +func (_m *CesClient) ShowMetricDataInvoker(request *model.ShowMetricDataRequest) *v1.ShowMetricDataInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowMetricDataInvoker") + } + + var r0 *v1.ShowMetricDataInvoker + if rf, ok := ret.Get(0).(func(*model.ShowMetricDataRequest) *v1.ShowMetricDataInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ShowMetricDataInvoker) + } + } + + return r0 +} + +// ShowQuotas provides a mock function with given fields: request +func (_m *CesClient) ShowQuotas(request *model.ShowQuotasRequest) (*model.ShowQuotasResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowQuotas") + } + + var r0 *model.ShowQuotasResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ShowQuotasRequest) (*model.ShowQuotasResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ShowQuotasRequest) *model.ShowQuotasResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ShowQuotasResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ShowQuotasRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ShowQuotasInvoker provides a mock function with given fields: request +func (_m *CesClient) ShowQuotasInvoker(request *model.ShowQuotasRequest) *v1.ShowQuotasInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowQuotasInvoker") + } + + var r0 *v1.ShowQuotasInvoker + if rf, ok := ret.Get(0).(func(*model.ShowQuotasRequest) *v1.ShowQuotasInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ShowQuotasInvoker) + } + } + + return r0 +} + +// ShowResourceGroup provides a mock function with given fields: request +func (_m *CesClient) ShowResourceGroup(request *model.ShowResourceGroupRequest) (*model.ShowResourceGroupResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowResourceGroup") + } + + var r0 *model.ShowResourceGroupResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.ShowResourceGroupRequest) (*model.ShowResourceGroupResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.ShowResourceGroupRequest) *model.ShowResourceGroupResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ShowResourceGroupResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.ShowResourceGroupRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ShowResourceGroupInvoker provides a mock function with given fields: request +func (_m *CesClient) ShowResourceGroupInvoker(request *model.ShowResourceGroupRequest) *v1.ShowResourceGroupInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ShowResourceGroupInvoker") + } + + var r0 *v1.ShowResourceGroupInvoker + if rf, ok := ret.Get(0).(func(*model.ShowResourceGroupRequest) *v1.ShowResourceGroupInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.ShowResourceGroupInvoker) + } + } + + return r0 +} + +// UpdateAlarm provides a mock function with given fields: request +func (_m *CesClient) UpdateAlarm(request *model.UpdateAlarmRequest) (*model.UpdateAlarmResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for UpdateAlarm") + } + + var r0 *model.UpdateAlarmResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmRequest) (*model.UpdateAlarmResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmRequest) *model.UpdateAlarmResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.UpdateAlarmResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.UpdateAlarmRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UpdateAlarmAction provides a mock function with given fields: request +func (_m *CesClient) UpdateAlarmAction(request *model.UpdateAlarmActionRequest) (*model.UpdateAlarmActionResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for UpdateAlarmAction") + } + + var r0 *model.UpdateAlarmActionResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmActionRequest) (*model.UpdateAlarmActionResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmActionRequest) *model.UpdateAlarmActionResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.UpdateAlarmActionResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.UpdateAlarmActionRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UpdateAlarmActionInvoker provides a mock function with given fields: request +func (_m *CesClient) UpdateAlarmActionInvoker(request *model.UpdateAlarmActionRequest) *v1.UpdateAlarmActionInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for UpdateAlarmActionInvoker") + } + + var r0 *v1.UpdateAlarmActionInvoker + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmActionRequest) *v1.UpdateAlarmActionInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.UpdateAlarmActionInvoker) + } + } + + return r0 +} + +// UpdateAlarmInvoker provides a mock function with given fields: request +func (_m *CesClient) UpdateAlarmInvoker(request *model.UpdateAlarmRequest) *v1.UpdateAlarmInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for UpdateAlarmInvoker") + } + + var r0 *v1.UpdateAlarmInvoker + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmRequest) *v1.UpdateAlarmInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.UpdateAlarmInvoker) + } + } + + return r0 +} + +// UpdateAlarmTemplate provides a mock function with given fields: request +func (_m *CesClient) UpdateAlarmTemplate(request *model.UpdateAlarmTemplateRequest) (*model.UpdateAlarmTemplateResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for UpdateAlarmTemplate") + } + + var r0 *model.UpdateAlarmTemplateResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmTemplateRequest) (*model.UpdateAlarmTemplateResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmTemplateRequest) *model.UpdateAlarmTemplateResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.UpdateAlarmTemplateResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.UpdateAlarmTemplateRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UpdateAlarmTemplateInvoker provides a mock function with given fields: request +func (_m *CesClient) UpdateAlarmTemplateInvoker(request *model.UpdateAlarmTemplateRequest) *v1.UpdateAlarmTemplateInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for UpdateAlarmTemplateInvoker") + } + + var r0 *v1.UpdateAlarmTemplateInvoker + if rf, ok := ret.Get(0).(func(*model.UpdateAlarmTemplateRequest) *v1.UpdateAlarmTemplateInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.UpdateAlarmTemplateInvoker) + } + } + + return r0 +} + +// UpdateResourceGroup provides a mock function with given fields: request +func (_m *CesClient) UpdateResourceGroup(request *model.UpdateResourceGroupRequest) (*model.UpdateResourceGroupResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for UpdateResourceGroup") + } + + var r0 *model.UpdateResourceGroupResponse + var r1 error + if rf, ok := ret.Get(0).(func(*model.UpdateResourceGroupRequest) (*model.UpdateResourceGroupResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*model.UpdateResourceGroupRequest) *model.UpdateResourceGroupResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.UpdateResourceGroupResponse) + } + } + + if rf, ok := ret.Get(1).(func(*model.UpdateResourceGroupRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UpdateResourceGroupInvoker provides a mock function with given fields: request +func (_m *CesClient) UpdateResourceGroupInvoker(request *model.UpdateResourceGroupRequest) *v1.UpdateResourceGroupInvoker { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for UpdateResourceGroupInvoker") + } + + var r0 *v1.UpdateResourceGroupInvoker + if rf, ok := ret.Get(0).(func(*model.UpdateResourceGroupRequest) *v1.UpdateResourceGroupInvoker); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*v1.UpdateResourceGroupInvoker) + } + } + + return r0 +} + +// NewCesClient creates a new instance of CesClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCesClient(t interface { + mock.TestingT + Cleanup(func()) +}) *CesClient { + mock := &CesClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/receiver/huaweicloudcesreceiver/receiver.go b/receiver/huaweicloudcesreceiver/receiver.go index 9dec9d5113e1..8d172a9e20af 100644 --- a/receiver/huaweicloudcesreceiver/receiver.go +++ b/receiver/huaweicloudcesreceiver/receiver.go @@ -1,13 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package huaweicloudcesreceiver +package huaweicloudcesreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver" import ( "context" "errors" "net/url" - "os" "strconv" "time" @@ -26,7 +25,7 @@ import ( type cesReceiver struct { logger *zap.Logger - client *ces.CesClient + client CesClient cancel context.CancelFunc host component.Host @@ -44,16 +43,17 @@ func newHuaweiCloudCesReceiver(settings receiver.Settings, cfg *Config, next con return rcvr } -func (rcvr *cesReceiver) Start(ctx context.Context, host component.Host) (err error) { +func (rcvr *cesReceiver) Start(ctx context.Context, host component.Host) error { rcvr.host = host ctx, rcvr.cancel = context.WithCancel(ctx) if rcvr.client == nil { - rcvr.client, err = rcvr.createClient() + client, err := rcvr.createClient() if err != nil { rcvr.logger.Error(err.Error()) - return + return nil } + rcvr.client = client } go func() { @@ -102,10 +102,8 @@ func (rcvr *cesReceiver) createHTTPConfig() (*config.HttpConfig, error) { func (rcvr *cesReceiver) createClient() (*ces.CesClient, error) { auth, err := basic.NewCredentialsBuilder(). - // Authentication can be configured through environment variables and other methods. - // Please refer to Chapter 2.4 Authentication Management - WithAk(os.Getenv("HUAWEICLOUD_SDK_AK")). - WithSk(os.Getenv("HUAWEICLOUD_SDK_SK")). + WithAk(string(rcvr.config.AccessKey)). + WithSk(string(rcvr.config.SecretKey)). WithProjectId(rcvr.config.ProjectID). SafeBuild() @@ -138,6 +136,9 @@ func (rcvr *cesReceiver) createClient() (*ces.CesClient, error) { } func (rcvr *cesReceiver) pollMetricsAndConsume(ctx context.Context) error { + if rcvr.client == nil { + return errors.New("invalid client") + } metricDefinitions, err := rcvr.listMetricDefinitions() if err != nil { return err diff --git a/receiver/huaweicloudcesreceiver/receiver_test.go b/receiver/huaweicloudcesreceiver/receiver_test.go new file mode 100644 index 000000000000..64fbe5df0a7b --- /dev/null +++ b/receiver/huaweicloudcesreceiver/receiver_test.go @@ -0,0 +1,141 @@ +package huaweicloudcesreceiver + +import ( + "context" + "errors" + "testing" + "time" + + "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver/mocks" + + "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/receiver/receivertest" + "go.opentelemetry.io/collector/receiver/scraperhelper" +) + +func stringPtr(s string) *string { + return &s +} + +func float64Ptr(f float64) *float64 { + return &f +} + +func TestNewReceiver(t *testing.T) { + cfg := &Config{ + ControllerConfig: scraperhelper.ControllerConfig{ + CollectionInterval: 1 * time.Second, + }, + } + mr := newHuaweiCloudCesReceiver(receivertest.NewNopSettings(), cfg, new(consumertest.MetricsSink)) + assert.NotNil(t, mr) +} + +func TestListMetricDefinitionsSuccess(t *testing.T) { + mockCes := mocks.NewCesClient(t) + + mockResponse := &model.ListMetricsResponse{ + Metrics: &[]model.MetricInfoList{ + { + Namespace: "SYS.ECS", + MetricName: "cpu_util", + Dimensions: []model.MetricsDimension{ + { + Name: "instance_id", + Value: "12345", + }, + }, + }, + }, + } + + mockCes.On("ListMetrics", mock.Anything).Return(mockResponse, nil) + + receiver := &cesReceiver{ + client: mockCes, + } + + metrics, err := receiver.listMetricDefinitions() + + assert.NoError(t, err) + assert.NotNil(t, metrics) + assert.Equal(t, "SYS.ECS", metrics[0].Namespace) + assert.Equal(t, "cpu_util", metrics[0].MetricName) + assert.Equal(t, "instance_id", metrics[0].Dimensions[0].Name) + assert.Equal(t, "12345", metrics[0].Dimensions[0].Value) + mockCes.AssertExpectations(t) +} + +func TestListMetricDefinitionsFailure(t *testing.T) { + mockCes := mocks.NewCesClient(t) + + mockCes.On("ListMetrics", mock.Anything).Return(nil, errors.New("failed to list metrics")) + receiver := &cesReceiver{ + client: mockCes, + } + + metrics, err := receiver.listMetricDefinitions() + + assert.Error(t, err) + assert.Len(t, metrics, 0) + assert.Equal(t, "failed to list metrics", err.Error()) + mockCes.AssertExpectations(t) +} + +func TestPollMetricsAndConsumeSuccess(t *testing.T) { + mockCes := mocks.NewCesClient(t) + next := new(consumertest.MetricsSink) + receiver := newHuaweiCloudCesReceiver(receivertest.NewNopSettings(), &Config{}, next) + receiver.client = mockCes + + mockCes.On("ListMetrics", mock.Anything).Return(&model.ListMetricsResponse{ + Metrics: &[]model.MetricInfoList{ + { + Namespace: "SYS.ECS", + MetricName: "cpu_util", + Dimensions: []model.MetricsDimension{ + { + Name: "instance_id", + Value: "12345", + }, + }, + }, + }, + }, nil) + + mockCes.On("BatchListMetricData", mock.Anything).Return(&model.BatchListMetricDataResponse{ + Metrics: &[]model.BatchMetricData{ + { + Namespace: stringPtr("SYS.ECS"), + MetricName: "cpu_util", + Dimensions: &[]model.MetricsDimension{ + { + Name: "instance_id", + Value: "faea5b75-e390-4e2b-8733-9226a9026070", + }, + }, + Datapoints: []model.DatapointForBatchMetric{ + { + Average: float64Ptr(45.67), + Timestamp: 1556625610000, + }, + { + Average: float64Ptr(89.01), + Timestamp: 1556625715000, + }, + }, + Unit: stringPtr("%"), + }, + }, + }, nil) + + err := receiver.pollMetricsAndConsume(context.Background()) + + require.NoError(t, err) + assert.Equal(t, 2, next.DataPointCount()) +}