diff --git a/.chloggen/mo-silent_fix-34315.yaml b/.chloggen/mo-silent_fix-34315.yaml new file mode 100644 index 000000000000..bf8146fa1f3a --- /dev/null +++ b/.chloggen/mo-silent_fix-34315.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: azuremonitorreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add Azure China as a `cloud` option. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [34315] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/receiver/azuremonitorreceiver/README.md b/receiver/azuremonitorreceiver/README.md index c973cc1f1d23..709f73753676 100644 --- a/receiver/azuremonitorreceiver/README.md +++ b/receiver/azuremonitorreceiver/README.md @@ -30,7 +30,7 @@ The following settings are optional: - `maximum_number_of_metrics_in_a_call` (default = 20): Maximum number of metrics to fetch in per API call, current limit in Azure is 20 (as of 03/27/2023). - `maximum_number_of_records_per_resource` (default = 10): Maximum number of records to fetch per resource. - `initial_delay` (default = `1s`): defines how long this receiver waits before starting. -- `cloud` (default = `AzureCloud`): defines which Azure cloud to use. Either `AzureCloud` or `AzureUSGovernment` +- `cloud` (default = `AzureCloud`): defines which Azure cloud to use. Valid values: `AzureCloud`, `AzureUSGovernment`, `AzureChinaCloud`. Authenticating using service principal requires following additional settings: diff --git a/receiver/azuremonitorreceiver/config.go b/receiver/azuremonitorreceiver/config.go index 90f7d7ef6292..6e835003e781 100644 --- a/receiver/azuremonitorreceiver/config.go +++ b/receiver/azuremonitorreceiver/config.go @@ -16,6 +16,7 @@ import ( const ( azureCloud = "AzureCloud" azureGovernmentCloud = "AzureUSGovernment" + azureChinaCloud = "AzureChinaCloud" ) var ( @@ -292,7 +293,7 @@ func (c Config) Validate() (err error) { return fmt.Errorf("authentication %v is not supported. supported authentications include [%v,%v,%v,%v]", c.Authentication, servicePrincipal, workloadIdentity, managedIdentity, defaultCredentials) } - if c.Cloud != azureCloud && c.Cloud != azureGovernmentCloud { + if c.Cloud != azureCloud && c.Cloud != azureGovernmentCloud && c.Cloud != azureChinaCloud { err = multierr.Append(err, errInvalidCloud) } diff --git a/receiver/azuremonitorreceiver/scraper.go b/receiver/azuremonitorreceiver/scraper.go index 8e5440dae0cd..1e4449016647 100644 --- a/receiver/azuremonitorreceiver/scraper.go +++ b/receiver/azuremonitorreceiver/scraper.go @@ -126,6 +126,8 @@ func (s *azureScraper) getArmClientOptions() *arm.ClientOptions { switch s.cfg.Cloud { case azureGovernmentCloud: cloudToUse = cloud.AzureGovernment + case azureChinaCloud: + cloudToUse = cloud.AzureChina default: cloudToUse = cloud.AzurePublic } diff --git a/receiver/azuremonitorreceiver/scraper_test.go b/receiver/azuremonitorreceiver/scraper_test.go index 68e643884b6b..b915b4bdc4dc 100644 --- a/receiver/azuremonitorreceiver/scraper_test.go +++ b/receiver/azuremonitorreceiver/scraper_test.go @@ -6,12 +6,14 @@ package azuremonitorreceiver // import "github.com/open-telemetry/opentelemetry- import ( "context" "path/filepath" + "reflect" "strings" "sync" "testing" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor" @@ -722,3 +724,64 @@ func getMetricsValuesMockData() map[string]map[string]armmonitor.MetricsClientLi }, } } + +func TestAzureScraperClientOptions(t *testing.T) { + type fields struct { + cfg *Config + } + tests := []struct { + name string + fields fields + want *arm.ClientOptions + }{ + { + name: "AzureCloud_options", + fields: fields{ + cfg: &Config{ + Cloud: azureCloud, + }, + }, + want: &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Cloud: cloud.AzurePublic, + }, + }, + }, + { + name: "AzureGovernmentCloud_options", + fields: fields{ + cfg: &Config{ + Cloud: azureGovernmentCloud, + }, + }, + want: &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Cloud: cloud.AzureGovernment, + }, + }, + }, + { + name: "AzureChinaCloud_options", + fields: fields{ + cfg: &Config{ + Cloud: azureChinaCloud, + }, + }, + want: &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Cloud: cloud.AzureChina, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &azureScraper{ + cfg: tt.fields.cfg, + } + if got := s.getArmClientOptions(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("getArmClientOptions() = %v, want %v", got, tt.want) + } + }) + } +}