Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename region_name to region_id and simplify CesClient interface #43

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions receiver/huaweicloudcesreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This receiver contains the implementation of the Huawei Cloud [Cloud Eye Service

The following settings are required:

- `region_name`: The name of the Huawei Cloud region from which metrics are collected. For example, `eu-west-101`. The full list of the available regions can be found [here](https://pkg.go.dev/github.com/huaweicloud/[email protected]/services/ces/v1/region).
- `region_id`: The ID of the Huawei Cloud region from which metrics are collected. For example, `eu-west-101`. The full list of the available regions can be found [here](https://pkg.go.dev/github.com/huaweicloud/[email protected]/services/ces/v1/region).

- `project_id`: The ID of the project in Huawei Cloud. This is used to identify which project's metrics are to be collected. See [Obtaining a Project ID](https://support.huaweicloud.com/intl/en-us/devg-apisign/api-sign-provide-proid.html).

Expand Down Expand Up @@ -63,7 +63,7 @@ receivers:
huaweicloudcesreceiver:
collection_interval: 3h
initial_delay: 5s
region_name: eu-west-101
region_id: eu-west-101
access_key: ${env:HUAWEICLOUD_SDK_AK}
secret_key: ${env:HUAWEICLOUD_SDK_SK}
project_id: "project_1"
Expand Down Expand Up @@ -112,7 +112,7 @@ If you encounter any CES errors, please refer to the [Huawei Cloud Error Codes](
| **dimensions.name** | key of `metrics.metadata` | The dimension name stored as metadata key. |
| **dimensions.value** | value of `metrics.metadata` | The dimension value stored as metadata value. |
| **Receiver Config** | `resource.attributes.project.id` | The project id used in the configuration file of the receiver. |
| **Receiver Config** | `resource.attributes.region` | The region name used in the configuration file of the receiver. |
| **Receiver Config** | `resource.attributes.region.id` | The region id used in the configuration file of the receiver. |
| *N/A* | `resource.attributes.cloud.provider` | Set to `"huawei_cloud"` as the cloud provider. |
| *N/A* | `resource.attributes.service.name` | Set to `"ces_service"` to indicate the service name. |
| *N/A* | `resource.attributes.service.version` | Set to `"v1"` as the service version. |
Expand Down Expand Up @@ -171,7 +171,7 @@ converts to
"attributes": {
"cloud.provider": "huawei_cloud",
"project.id": "project_1",
"region": "eu-west-101"
"region.id": "eu-west-101"
}
},
"scopeMetrics": [
Expand Down
10 changes: 5 additions & 5 deletions receiver/huaweicloudcesreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var (
// Predefined error responses for configuration validation failures
errMissingRegionName = errors.New(`"region_name" is not specified in config`)
errMissingRegionID = errors.New(`"region_id" is not specified in config`)
errMissingProjectID = errors.New(`"project_id" is not specified in config`)
errInvalidCollectionInterval = errors.New(`invalid period; must be less than "collection_interval"`)
errInvalidProxy = errors.New(`"proxy_address" must be specified if "proxy_user" or "proxy_password" is set"`)
Expand Down Expand Up @@ -47,8 +47,8 @@ type Config struct {
// If ProjectID is not filled in, the SDK will automatically call the IAM service to query the project id corresponding to the region.
ProjectID string `mapstructure:"project_id"`

// RegionName is the full name of the CES region exporter should send metrics to
RegionName string `mapstructure:"region_name"`
// RegionID is the ID of the CES region.
RegionID string `mapstructure:"region_id"`

// How retrieved data from Cloud Eye is aggregated.
// Possible values are 1, 300, 1200, 3600, 14400, and 86400.
Expand Down Expand Up @@ -96,8 +96,8 @@ var validFilters = map[string]model.ShowMetricDataRequestFilter{
// Validate config
func (config *Config) Validate() error {
var err error
if config.RegionName == "" {
err = multierr.Append(err, errMissingRegionName)
if config.RegionID == "" {
err = multierr.Append(err, errMissingRegionID)
}

if config.ProjectID == "" {
Expand Down
58 changes: 29 additions & 29 deletions receiver/huaweicloudcesreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"go.opentelemetry.io/collector/receiver/scraperhelper"
)

func TestConfig_Validate(t *testing.T) {
func TestConfigValidate(t *testing.T) {
tests := []struct {
name string
config Config
Expand All @@ -23,10 +23,10 @@ func TestConfig_Validate(t *testing.T) {
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: time.Hour,
},
RegionName: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "min",
RegionID: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "min",
},
expectedError: "",
},
Expand All @@ -36,20 +36,20 @@ func TestConfig_Validate(t *testing.T) {
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: time.Hour,
},
RegionName: "cn-north-1",
ProjectID: "my_project",
Period: 100,
Filter: "min",
RegionID: "cn-north-1",
ProjectID: "my_project",
Period: 100,
Filter: "min",
},
expectedError: "invalid period",
},
{
name: "Invalid Filter",
config: Config{
RegionName: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "invalid",
RegionID: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "invalid",
},
expectedError: "invalid filter",
},
Expand All @@ -63,17 +63,17 @@ func TestConfig_Validate(t *testing.T) {
Period: 300,
Filter: "min",
},
expectedError: errMissingRegionName.Error(),
expectedError: errMissingRegionID.Error(),
},
{
name: "Missing project id",
config: Config{
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: time.Hour,
},
RegionName: "cn-north-1",
Period: 300,
Filter: "min",
RegionID: "cn-north-1",
Period: 300,
Filter: "min",
},
expectedError: errMissingProjectID.Error(),
},
Expand All @@ -86,10 +86,10 @@ func TestConfig_Validate(t *testing.T) {
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: time.Hour,
},
RegionName: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "min",
RegionID: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "min",
},
expectedError: errInvalidProxy.Error(),
},
Expand All @@ -102,10 +102,10 @@ func TestConfig_Validate(t *testing.T) {
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: time.Hour,
},
RegionName: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "min",
RegionID: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "min",
},
expectedError: errInvalidProxy.Error(),
},
Expand All @@ -120,10 +120,10 @@ func TestConfig_Validate(t *testing.T) {
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: time.Hour,
},
RegionName: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "min",
RegionID: "cn-north-1",
ProjectID: "my_project",
Period: 300,
Filter: "min",
},
expectedError: "",
},
Expand Down
3 changes: 1 addition & 2 deletions receiver/huaweicloudcesreceiver/generated_package_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions receiver/huaweicloudcesreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.107.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.107.0
go.opentelemetry.io/collector/config/confighttp v0.107.0
go.opentelemetry.io/collector/config/configopaque v1.13.0
go.opentelemetry.io/collector/component v0.108.1
go.opentelemetry.io/collector/config/confighttp v0.108.1
go.opentelemetry.io/collector/config/configopaque v1.14.1
go.opentelemetry.io/collector/config/configretry v1.13.0
go.opentelemetry.io/collector/confmap v0.107.0
go.opentelemetry.io/collector/consumer v0.107.0
go.opentelemetry.io/collector/consumer/consumertest v0.107.0
go.opentelemetry.io/collector/confmap v1.14.1
go.opentelemetry.io/collector/consumer v0.108.1
go.opentelemetry.io/collector/consumer/consumertest v0.108.1
go.opentelemetry.io/collector/pdata v1.14.1
go.opentelemetry.io/collector/receiver v0.106.1
go.opentelemetry.io/collector/receiver v0.108.1
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
Expand All @@ -32,7 +32,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand All @@ -49,27 +49,27 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.108.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_golang v1.20.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
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.107.0 // indirect
go.opentelemetry.io/collector/client v1.13.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.107.0 // indirect
go.opentelemetry.io/collector/config/configcompression v1.13.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.107.0 // indirect
go.opentelemetry.io/collector/config/configtls v1.13.0 // indirect
go.opentelemetry.io/collector/config/internal v0.107.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.107.0 // indirect
go.opentelemetry.io/collector/extension v0.107.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.107.0 // indirect
go.opentelemetry.io/collector/featuregate v1.13.0 // indirect
go.opentelemetry.io/collector v0.108.1 // indirect
go.opentelemetry.io/collector/client v1.14.1 // indirect
go.opentelemetry.io/collector/config/configauth v0.108.1 // indirect
go.opentelemetry.io/collector/config/configcompression v1.14.1 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.108.1 // indirect
go.opentelemetry.io/collector/config/configtls v1.14.1 // indirect
go.opentelemetry.io/collector/config/internal v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/extension v0.108.1 // indirect
go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect
go.opentelemetry.io/collector/featuregate v1.14.1 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.107.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.107.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.50.0 // indirect
Expand Down
Loading
Loading