Skip to content

Commit fd5bbb7

Browse files
mo-silentcrobert-1
authored andcommitted
fix Azure receiver not azure china (open-telemetry#34402)
Fixes open-telemetry#34315 --------- Co-authored-by: Curtis Robert <[email protected]>
1 parent d9a2053 commit fd5bbb7

File tree

5 files changed

+95
-2
lines changed

5 files changed

+95
-2
lines changed

.chloggen/mo-silent_fix-34315.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'bug_fix'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: azuremonitorreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add Azure China as a `cloud` option.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [34315]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/azuremonitorreceiver/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The following settings are optional:
3030
- `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).
3131
- `maximum_number_of_records_per_resource` (default = 10): Maximum number of records to fetch per resource.
3232
- `initial_delay` (default = `1s`): defines how long this receiver waits before starting.
33-
- `cloud` (default = `AzureCloud`): defines which Azure cloud to use. Either `AzureCloud` or `AzureUSGovernment`
33+
- `cloud` (default = `AzureCloud`): defines which Azure cloud to use. Valid values: `AzureCloud`, `AzureUSGovernment`, `AzureChinaCloud`.
3434

3535
Authenticating using service principal requires following additional settings:
3636

receiver/azuremonitorreceiver/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
const (
1717
azureCloud = "AzureCloud"
1818
azureGovernmentCloud = "AzureUSGovernment"
19+
azureChinaCloud = "AzureChinaCloud"
1920
)
2021

2122
var (
@@ -292,7 +293,7 @@ func (c Config) Validate() (err error) {
292293
return fmt.Errorf("authentication %v is not supported. supported authentications include [%v,%v,%v,%v]", c.Authentication, servicePrincipal, workloadIdentity, managedIdentity, defaultCredentials)
293294
}
294295

295-
if c.Cloud != azureCloud && c.Cloud != azureGovernmentCloud {
296+
if c.Cloud != azureCloud && c.Cloud != azureGovernmentCloud && c.Cloud != azureChinaCloud {
296297
err = multierr.Append(err, errInvalidCloud)
297298
}
298299

receiver/azuremonitorreceiver/scraper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ func (s *azureScraper) getArmClientOptions() *arm.ClientOptions {
126126
switch s.cfg.Cloud {
127127
case azureGovernmentCloud:
128128
cloudToUse = cloud.AzureGovernment
129+
case azureChinaCloud:
130+
cloudToUse = cloud.AzureChina
129131
default:
130132
cloudToUse = cloud.AzurePublic
131133
}

receiver/azuremonitorreceiver/scraper_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ package azuremonitorreceiver // import "github.com/open-telemetry/opentelemetry-
66
import (
77
"context"
88
"path/filepath"
9+
"reflect"
910
"strings"
1011
"sync"
1112
"testing"
1213

1314
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
1415
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
16+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
1517
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
1618
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1719
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
@@ -722,3 +724,64 @@ func getMetricsValuesMockData() map[string]map[string]armmonitor.MetricsClientLi
722724
},
723725
}
724726
}
727+
728+
func TestAzureScraperClientOptions(t *testing.T) {
729+
type fields struct {
730+
cfg *Config
731+
}
732+
tests := []struct {
733+
name string
734+
fields fields
735+
want *arm.ClientOptions
736+
}{
737+
{
738+
name: "AzureCloud_options",
739+
fields: fields{
740+
cfg: &Config{
741+
Cloud: azureCloud,
742+
},
743+
},
744+
want: &arm.ClientOptions{
745+
ClientOptions: azcore.ClientOptions{
746+
Cloud: cloud.AzurePublic,
747+
},
748+
},
749+
},
750+
{
751+
name: "AzureGovernmentCloud_options",
752+
fields: fields{
753+
cfg: &Config{
754+
Cloud: azureGovernmentCloud,
755+
},
756+
},
757+
want: &arm.ClientOptions{
758+
ClientOptions: azcore.ClientOptions{
759+
Cloud: cloud.AzureGovernment,
760+
},
761+
},
762+
},
763+
{
764+
name: "AzureChinaCloud_options",
765+
fields: fields{
766+
cfg: &Config{
767+
Cloud: azureChinaCloud,
768+
},
769+
},
770+
want: &arm.ClientOptions{
771+
ClientOptions: azcore.ClientOptions{
772+
Cloud: cloud.AzureChina,
773+
},
774+
},
775+
},
776+
}
777+
for _, tt := range tests {
778+
t.Run(tt.name, func(t *testing.T) {
779+
s := &azureScraper{
780+
cfg: tt.fields.cfg,
781+
}
782+
if got := s.getArmClientOptions(); !reflect.DeepEqual(got, tt.want) {
783+
t.Errorf("getArmClientOptions() = %v, want %v", got, tt.want)
784+
}
785+
})
786+
}
787+
}

0 commit comments

Comments
 (0)