Skip to content

Commit

Permalink
fix Azure receiver not azure china (open-telemetry#34402)
Browse files Browse the repository at this point in the history
Fixes open-telemetry#34315

---------

Co-authored-by: Curtis Robert <crobert@splunk.com>
  • Loading branch information
2 people authored and f7o committed Sep 12, 2024
1 parent d9a2053 commit fd5bbb7
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .chloggen/mo-silent_fix-34315.yaml
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion receiver/azuremonitorreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 2 additions & 1 deletion receiver/azuremonitorreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
const (
azureCloud = "AzureCloud"
azureGovernmentCloud = "AzureUSGovernment"
azureChinaCloud = "AzureChinaCloud"
)

var (
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions receiver/azuremonitorreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
63 changes: 63 additions & 0 deletions receiver/azuremonitorreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
})
}
}

0 comments on commit fd5bbb7

Please sign in to comment.