Skip to content

Commit

Permalink
[receiver/azuremonitorreceiver] feat: Allow to not split result by di…
Browse files Browse the repository at this point in the history
…mension

Signed-off-by: Célian Garcia <[email protected]>
  • Loading branch information
celian-garcia committed Nov 6, 2024
1 parent 8daf962 commit aa46e6e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .chloggen/split-dimensions-optout.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: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: receiver/azuremonitorreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add split_by_dimensions which allows to opt out from automatically split by all the dimensions of the resource type"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36240]

# (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: []
1 change: 1 addition & 0 deletions receiver/azuremonitorreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following settings are optional:
- `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. Valid values: `AzureCloud`, `AzureUSGovernment`, `AzureChinaCloud`.
- `split_by_dimensions` (default = `true`): allows to opt out from automatically split by all the dimensions of the resource type.

Authenticating using service principal requires following additional settings:

Expand Down
1 change: 1 addition & 0 deletions receiver/azuremonitorreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ type Config struct {
MaximumNumberOfMetricsInACall int `mapstructure:"maximum_number_of_metrics_in_a_call"`
MaximumNumberOfRecordsPerResource int32 `mapstructure:"maximum_number_of_records_per_resource"`
AppendTagsAsAttributes bool `mapstructure:"append_tags_as_attributes"`
SplitByDimensions *bool `mapstructure:"split_by_dimensions"`
}

const (
Expand Down
4 changes: 4 additions & 0 deletions receiver/azuremonitorreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"errors"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
Expand All @@ -19,6 +21,7 @@ import (
const (
defaultCollectionInterval = 10 * time.Second
defaultCloud = azureCloud
defaultSplitByDimensions = true
)

var errConfigNotAzureMonitor = errors.New("Config was not a Azure Monitor receiver config")
Expand All @@ -45,6 +48,7 @@ func createDefaultConfig() component.Config {
Services: monitorServices,
Authentication: servicePrincipal,
Cloud: defaultCloud,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
}
}

Expand Down
3 changes: 3 additions & 0 deletions receiver/azuremonitorreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumertest"
Expand Down Expand Up @@ -47,6 +49,7 @@ func TestNewFactory(t *testing.T) {
MaximumNumberOfRecordsPerResource: 10,
Authentication: servicePrincipal,
Cloud: defaultCloud,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
}

require.Equal(t, expectedCfg, factory.CreateDefaultConfig())
Expand Down
4 changes: 3 additions & 1 deletion receiver/azuremonitorreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ func (s *azureScraper) getResourceMetricsValues(ctx context.Context, resourceID
start,
end,
s.cfg.MaximumNumberOfRecordsPerResource,
*s.cfg.SplitByDimensions,
)
start = end

Expand Down Expand Up @@ -438,6 +439,7 @@ func getResourceMetricsValuesRequestOptions(
start int,
end int,
top int32,
splitByDimensions bool,
) armmonitor.MetricsClientListOptions {
resType := strings.Join(metrics[start:end], ",")
filter := armmonitor.MetricsClientListOptions{
Expand All @@ -448,7 +450,7 @@ func getResourceMetricsValuesRequestOptions(
Top: to.Ptr(top),
}

if len(dimensionsStr) > 0 {
if splitByDimensions && len(dimensionsStr) > 0 {
var dimensionsFilter bytes.Buffer
dimensions := strings.Split(dimensionsStr, ",")
for i, dimension := range dimensions {
Expand Down
15 changes: 12 additions & 3 deletions receiver/azuremonitorreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"sync"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"

"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"
Expand Down Expand Up @@ -101,6 +103,7 @@ func TestAzureScraperStart(t *testing.T) {
MaximumNumberOfMetricsInACall: 20,
Services: monitorServices,
Authentication: servicePrincipal,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
}
s := &azureScraper{
cfg: customCfg,
Expand Down Expand Up @@ -129,6 +132,7 @@ func TestAzureScraperStart(t *testing.T) {
MaximumNumberOfMetricsInACall: 20,
Services: monitorServices,
Authentication: workloadIdentity,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
}
s := &azureScraper{
cfg: customCfg,
Expand Down Expand Up @@ -157,6 +161,7 @@ func TestAzureScraperStart(t *testing.T) {
MaximumNumberOfMetricsInACall: 20,
Services: monitorServices,
Authentication: managedIdentity,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
}
s := &azureScraper{
cfg: customCfg,
Expand Down Expand Up @@ -185,6 +190,7 @@ func TestAzureScraperStart(t *testing.T) {
MaximumNumberOfMetricsInACall: 20,
Services: monitorServices,
Authentication: defaultCredentials,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
}
s := &azureScraper{
cfg: customCfg,
Expand Down Expand Up @@ -736,7 +742,8 @@ func TestAzureScraperClientOptions(t *testing.T) {
name: "AzureCloud_options",
fields: fields{
cfg: &Config{
Cloud: azureCloud,
Cloud: azureCloud,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
},
},
want: &arm.ClientOptions{
Expand All @@ -749,7 +756,8 @@ func TestAzureScraperClientOptions(t *testing.T) {
name: "AzureGovernmentCloud_options",
fields: fields{
cfg: &Config{
Cloud: azureGovernmentCloud,
Cloud: azureGovernmentCloud,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
},
},
want: &arm.ClientOptions{
Expand All @@ -762,7 +770,8 @@ func TestAzureScraperClientOptions(t *testing.T) {
name: "AzureChinaCloud_options",
fields: fields{
cfg: &Config{
Cloud: azureChinaCloud,
Cloud: azureChinaCloud,
SplitByDimensions: to.Ptr(defaultSplitByDimensions),
},
},
want: &arm.ClientOptions{
Expand Down

0 comments on commit aa46e6e

Please sign in to comment.