Skip to content

Commit

Permalink
[receiver/azuremonitor] Add parameter to overwrite azure's max record…
Browse files Browse the repository at this point in the history
… size (#32380)

**Description:**
When having lots of different records of one dimension in the metric,
azure by default only returns 10 of them. This setting adds the
possibility to overwrite the default and specify a custom number in the
config of the receiver.

Fixes #32165

**Testing:**
Tested fetching metrics with different configs. Do we need a unit test
for this?

**Documentation:** 
Added parameter to README
  • Loading branch information
cmergenthaler committed Jul 11, 2024
1 parent bcae858 commit 9a3e1de
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 30 deletions.
27 changes: 27 additions & 0 deletions .chloggen/azuremonitorreceiver-top.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: azuremonitorreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add `maximum_number_of_records_per_resource` config parameter in order to overwrite default

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

# (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 @@ -28,6 +28,7 @@ The following settings are optional:
- `cache_resources` (default = 86400): List of resources will be cached for the provided amount of time in seconds.
- `cache_resources_definitions` (default = 86400): List of metrics definitions will be cached for the provided amount of time in seconds.
- `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`

Expand Down
31 changes: 16 additions & 15 deletions receiver/azuremonitorreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,22 @@ var (

// Config defines the configuration for the various elements of the receiver agent.
type Config struct {
scraperhelper.ControllerConfig `mapstructure:",squash"`
MetricsBuilderConfig metadata.MetricsBuilderConfig `mapstructure:",squash"`
Cloud string `mapstructure:"cloud"`
SubscriptionID string `mapstructure:"subscription_id"`
Authentication string `mapstructure:"auth"`
TenantID string `mapstructure:"tenant_id"`
ClientID string `mapstructure:"client_id"`
ClientSecret string `mapstructure:"client_secret"`
FederatedTokenFile string `mapstructure:"federated_token_file"`
ResourceGroups []string `mapstructure:"resource_groups"`
Services []string `mapstructure:"services"`
CacheResources float64 `mapstructure:"cache_resources"`
CacheResourcesDefinitions float64 `mapstructure:"cache_resources_definitions"`
MaximumNumberOfMetricsInACall int `mapstructure:"maximum_number_of_metrics_in_a_call"`
AppendTagsAsAttributes bool `mapstructure:"append_tags_as_attributes"`
scraperhelper.ControllerConfig `mapstructure:",squash"`
MetricsBuilderConfig metadata.MetricsBuilderConfig `mapstructure:",squash"`
Cloud string `mapstructure:"cloud"`
SubscriptionID string `mapstructure:"subscription_id"`
Authentication string `mapstructure:"auth"`
TenantID string `mapstructure:"tenant_id"`
ClientID string `mapstructure:"client_id"`
ClientSecret string `mapstructure:"client_secret"`
FederatedTokenFile string `mapstructure:"federated_token_file"`
ResourceGroups []string `mapstructure:"resource_groups"`
Services []string `mapstructure:"services"`
CacheResources float64 `mapstructure:"cache_resources"`
CacheResourcesDefinitions float64 `mapstructure:"cache_resources_definitions"`
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"`
}

const (
Expand Down
17 changes: 9 additions & 8 deletions receiver/azuremonitorreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ func createDefaultConfig() component.Config {
cfg.CollectionInterval = defaultCollectionInterval

return &Config{
ControllerConfig: cfg,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
CacheResources: 24 * 60 * 60,
CacheResourcesDefinitions: 24 * 60 * 60,
MaximumNumberOfMetricsInACall: 20,
Services: monitorServices,
Authentication: servicePrincipal,
Cloud: defaultCloud,
ControllerConfig: cfg,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
CacheResources: 24 * 60 * 60,
CacheResourcesDefinitions: 24 * 60 * 60,
MaximumNumberOfMetricsInACall: 20,
MaximumNumberOfRecordsPerResource: 10,
Services: monitorServices,
Authentication: servicePrincipal,
Cloud: defaultCloud,
}
}

Expand Down
15 changes: 8 additions & 7 deletions receiver/azuremonitorreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ func TestNewFactory(t *testing.T) {
CollectionInterval: 10 * time.Second,
InitialDelay: time.Second,
},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Services: monitorServices,
CacheResources: 24 * 60 * 60,
CacheResourcesDefinitions: 24 * 60 * 60,
MaximumNumberOfMetricsInACall: 20,
Authentication: servicePrincipal,
Cloud: defaultCloud,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Services: monitorServices,
CacheResources: 24 * 60 * 60,
CacheResourcesDefinitions: 24 * 60 * 60,
MaximumNumberOfMetricsInACall: 20,
MaximumNumberOfRecordsPerResource: 10,
Authentication: servicePrincipal,
Cloud: defaultCloud,
}

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

Expand Down Expand Up @@ -441,13 +442,15 @@ func getResourceMetricsValuesRequestOptions(
timeGrain string,
start int,
end int,
top int32,
) armmonitor.MetricsClientListOptions {
resType := strings.Join(metrics[start:end], ",")
filter := armmonitor.MetricsClientListOptions{
Metricnames: &resType,
Interval: to.Ptr(timeGrain),
Timespan: to.Ptr(timeGrain),
Aggregation: to.Ptr(strings.Join(aggregations, ",")),
Top: to.Ptr(top),
}

if len(dimensionsStr) > 0 {
Expand Down

0 comments on commit 9a3e1de

Please sign in to comment.