Skip to content

Commit c4e2efb

Browse files
mergify[bot]zmoog
andauthored
[Azure Monitor] Add default timegrain to Azure Storage Account metricset (#46786) (#46852)
Adds a new `default_timegrain` configuration option to allow users to customize the timegrain used in the Storage Account metricset. The default value remains PT5M, but users can now choose a different value. Without this option, users can only collect metrics with a PT5M time grain. It is a sensible default, but some users want to collect metrics with a PT1M time grain. To learn more, see elastic/integrations#15464. (cherry picked from commit 8f145b9) Co-authored-by: Maurizio Branca <[email protected]>
1 parent 60890f8 commit c4e2efb

File tree

9 files changed

+137
-25
lines changed

9 files changed

+137
-25
lines changed

CHANGELOG.next.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
260260
- Add new metricset network for the vSphere module. {pull}40559[40559]
261261
- Add new metricset resourcepool for the vSphere module. {pull}40456[40456]
262262
- Add new metrics to vSphere Virtual Machine dataset (CPU usage percentage, disk average usage, disk read/write rate, number of disk reads/writes, memory usage percentage). {pull}44205[44205]
263+
- Added checks for the Resty response object in all Meraki module API calls to ensure proper handling of nil responses. {pull}44193[44193]
264+
- Add latency config option to Azure Monitor module. {pull}44366[44366]
265+
- Increase default polling period for MongoDB module from 10s to 60s {pull}44781[44781]
266+
- Upgrade github.com/microsoft/go-mssqldb from v1.7.2 to v1.8.2 {pull}44990[44990]
267+
- Add SSL support for sql module: drivers mysql, postgres, and mssql. {pull}44748[44748]
268+
- Add support for Kafka 4.0 in the Kafka module. {pull}44723[44723]
269+
- Add NTP response validation for system/ntp module. {pull}46184[46184]
270+
- Add vertexai_logs metricset to GCP for prompt response collection from VertexAI service. {pull}46383[46383]
271+
- Add default timegrain to Azure Storage Account metricset. {pull}46786[46786]
263272

264273
*Metricbeat*
265274

docs/reference/metricbeat/metricbeat-metricset-azure-storage.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ This is the storage metricset of the module azure.
1313

1414
This metricset allows users to retrieve all metrics from specified storage accounts.
1515

16-
1716
## Metricset-specific configuration notes [_metricset_specific_configuration_notes_11]
1817

1918
`refresh_list_interval`
@@ -22,7 +21,6 @@ This metricset allows users to retrieve all metrics from specified storage accou
2221
`resources`
2322
: This will contain all options for identifying resources and configuring the desired metrics
2423

25-
2624
### Config options to identify resources [_config_options_to_identify_resources_11]
2725

2826
`resource_id`
@@ -42,12 +40,61 @@ resources:
4240
service_type: ["queue", "file"]
4341
```
4442

45-
it will filter the metric values to be returned by specific metric namespaces. The supported metrics and namespaces can be found here [https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftstoragestorageaccounts](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftstoragestorageaccounts). The service type values allowed are `blob`, `table`, `queue`, `file` based on the namespaces `Microsoft.Storage/storageAccounts/blobServices`,`Microsoft.Storage/storageAccounts/tableServices`,`Microsoft.Storage/storageAccounts/fileServices`,`Microsoft.Storage/storageAccounts/queueServices`. If no service_type is specified all values are applied.
43+
It will filter the metric values to be returned by specific metric namespaces. The supported metrics and namespaces can be found here [https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftstoragestorageaccounts](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftstoragestorageaccounts). The service type values allowed are `blob`, `table`, `queue`, `file` based on the namespaces `Microsoft.Storage/storageAccounts/blobServices`,`Microsoft.Storage/storageAccounts/tableServices`,`Microsoft.Storage/storageAccounts/fileServices`,`Microsoft.Storage/storageAccounts/queueServices`. If no service_type is specified all values are applied.
4644

4745
Also, if the `resources` option is not specified, then all the storage accounts from the entire subscription will be selected. The primary aggregation value will be retrieved for all the metrics contained in the namespaces. The aggregation options are `avg`, `sum`, `min`, `max`, `total`, `count`.
4846

4947
A default non configurable timegrain of 5 min is set so users are advised to configure an interval of 300s or a multiply of it.
5048

49+
`default_timegrain`:
50+
: (*string*) Sets the default time grain to use when collecting storage account metrics. Defaults to PT5M.
51+
52+
To collect storage account metrics with a PT1M time grain, we recommend using one of the following configurations:
53+
54+
```yaml
55+
# (1) With `period: 60s` and `default_timegrain: "PT1M"`, the metricset
56+
# collects 1 data point every 60s.
57+
- module: azure
58+
metricsets:
59+
- storage
60+
enabled: true
61+
period: 60s
62+
client_id: '${AZURE_CLIENT_ID:""}'
63+
client_secret: '${AZURE_CLIENT_SECRET:""}'
64+
tenant_id: '${AZURE_TENANT_ID:""}'
65+
subscription_id: '${AZURE_SUBSCRIPTION_ID:""}'
66+
refresh_list_interval: 3600s # 1h
67+
enable_batch_api: true
68+
default_timegrain: "PT1M"
69+
```
70+
71+
```yaml
72+
# (2) With `period: 300s` and `default_timegrain: "PT1M"`, the metricset
73+
# collects 5 data points every 300s (5 minutes) — one for each minute,
74+
# but all data points arrive after 5 minutes
75+
- module: azure
76+
metricsets:
77+
- storage
78+
enabled: true
79+
period: 300s
80+
client_id: '${AZURE_CLIENT_ID:""}'
81+
client_secret: '${AZURE_CLIENT_SECRET:""}'
82+
tenant_id: '${AZURE_TENANT_ID:""}'
83+
subscription_id: '${AZURE_SUBSCRIPTION_ID:""}'
84+
refresh_list_interval: 3600s # 1h
85+
enable_batch_api: true
86+
default_timegrain: "PT1M"
87+
```
88+
89+
These two configurations trade off scalability and freshness. Configuration (1) prioritizes freshness over scalability, while configuration (2) prioritizes scalability over freshness.
90+
91+
Suggested changes:
92+
93+
- `enable_batch_api: true`: Retrieves metric values for multiple Azure resources in one API call, supporting more storage accounts.
94+
- `refresh_list_interval: 3600s`: Looks for new storage accounts every 60 minutes instead of 10 minutes, helping to avoid or reduce gaps when monitoring many storage accounts.
95+
96+
Note: By setting the collection `period: 1m`, the metricset only has 60s to collect all metric values instead of 300s, so it can handle fewer storage accounts. Keep in mind that the storage accounts metricset collects metrics for five different namespaces (storage account, blob, file, queue, and table).
97+
5198
## Fields [_fields]
5299

53100
For a description of each field in the metricset, see the [exported fields](/reference/metricbeat/exported-fields-azure.md) section.

x-pack/metricbeat/module/azure/azure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var supportedMonitorMetricsets = []string{"monitor", "container_registry", "cont
7373
// NewMetricSet will instantiate a new azure metricset
7474
func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) {
7575
metricsetName := base.Name()
76-
var config Config
76+
config := createDefaultConfig()
7777
err := base.Module().UnpackConfig(&config)
7878
if err != nil {
7979
return nil, fmt.Errorf("error unpack raw module config using UnpackConfig: %w", err)

x-pack/metricbeat/module/azure/client_utils.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ import (
1717
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
1818
)
1919

20-
// DefaultTimeGrain is set as default timegrain for the azure metrics
21-
const DefaultTimeGrain = "PT5M"
22-
2320
var instanceIdRegex = regexp.MustCompile(`.*?(\d+)$`)
2421

2522
// mapMetricValues should map the metric values

x-pack/metricbeat/module/azure/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ type Config struct {
4949
BillingScopeAccountId string `config:"billing_scope_account_id"` // retrieve usage details from billing account ID scope
5050
// Use BatchApi for metric values collection
5151
EnableBatchApi bool `config:"enable_batch_api"` // defaults to false
52+
// DefaultTimeGrain sets the default time interval when the resource config
53+
// doesn't specify one. If no time grain is configured, this value will be
54+
// used whenever possible.
55+
//
56+
// When the metric definition doesn't support this time grain, we fall back
57+
// to the smallest supported interval.
58+
//
59+
// Note: currently, this is only used for the storage metricset.
60+
DefaultTimeGrain string `config:"default_timegrain"` // defaults to PT5M
61+
}
62+
63+
// createDefaultConfig creates a default config for the metricset.
64+
func createDefaultConfig() Config {
65+
return Config{
66+
DefaultTimeGrain: "PT5M",
67+
}
5268
}
5369

5470
// ResourceConfig contains resource and metric list specific configuration.

x-pack/metricbeat/module/azure/storage/_meta/docs.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ This is the storage metricset of the module azure.
22

33
This metricset allows users to retrieve all metrics from specified storage accounts.
44

5-
65
## Metricset-specific configuration notes [_metricset_specific_configuration_notes_11]
76

87
`refresh_list_interval`
@@ -11,7 +10,6 @@ This metricset allows users to retrieve all metrics from specified storage accou
1110
`resources`
1211
: This will contain all options for identifying resources and configuring the desired metrics
1312

14-
1513
### Config options to identify resources [_config_options_to_identify_resources_11]
1614

1715
`resource_id`
@@ -31,8 +29,57 @@ resources:
3129
service_type: ["queue", "file"]
3230
```
3331

34-
it will filter the metric values to be returned by specific metric namespaces. The supported metrics and namespaces can be found here [https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftstoragestorageaccounts](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftstoragestorageaccounts). The service type values allowed are `blob`, `table`, `queue`, `file` based on the namespaces `Microsoft.Storage/storageAccounts/blobServices`,`Microsoft.Storage/storageAccounts/tableServices`,`Microsoft.Storage/storageAccounts/fileServices`,`Microsoft.Storage/storageAccounts/queueServices`. If no service_type is specified all values are applied.
32+
It will filter the metric values to be returned by specific metric namespaces. The supported metrics and namespaces can be found here [https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftstoragestorageaccounts](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftstoragestorageaccounts). The service type values allowed are `blob`, `table`, `queue`, `file` based on the namespaces `Microsoft.Storage/storageAccounts/blobServices`,`Microsoft.Storage/storageAccounts/tableServices`,`Microsoft.Storage/storageAccounts/fileServices`,`Microsoft.Storage/storageAccounts/queueServices`. If no service_type is specified all values are applied.
3533

3634
Also, if the `resources` option is not specified, then all the storage accounts from the entire subscription will be selected. The primary aggregation value will be retrieved for all the metrics contained in the namespaces. The aggregation options are `avg`, `sum`, `min`, `max`, `total`, `count`.
3735

3836
A default non configurable timegrain of 5 min is set so users are advised to configure an interval of 300s or a multiply of it.
37+
38+
`default_timegrain`:
39+
: (*string*) Sets the default time grain to use when collecting storage account metrics. Defaults to PT5M.
40+
41+
To collect storage account metrics with a PT1M time grain, we recommend using one of the following configurations:
42+
43+
```yaml
44+
# (1) With `period: 60s` and `default_timegrain: "PT1M"`, the metricset
45+
# collects 1 data point every 60s.
46+
- module: azure
47+
metricsets:
48+
- storage
49+
enabled: true
50+
period: 60s
51+
client_id: '${AZURE_CLIENT_ID:""}'
52+
client_secret: '${AZURE_CLIENT_SECRET:""}'
53+
tenant_id: '${AZURE_TENANT_ID:""}'
54+
subscription_id: '${AZURE_SUBSCRIPTION_ID:""}'
55+
refresh_list_interval: 3600s # 1h
56+
enable_batch_api: true
57+
default_timegrain: "PT1M"
58+
```
59+
60+
```yaml
61+
# (2) With `period: 300s` and `default_timegrain: "PT1M"`, the metricset
62+
# collects 5 data points every 300s (5 minutes) — one for each minute,
63+
# but all data points arrive after 5 minutes
64+
- module: azure
65+
metricsets:
66+
- storage
67+
enabled: true
68+
period: 300s
69+
client_id: '${AZURE_CLIENT_ID:""}'
70+
client_secret: '${AZURE_CLIENT_SECRET:""}'
71+
tenant_id: '${AZURE_TENANT_ID:""}'
72+
subscription_id: '${AZURE_SUBSCRIPTION_ID:""}'
73+
refresh_list_interval: 3600s # 1h
74+
enable_batch_api: true
75+
default_timegrain: "PT1M"
76+
```
77+
78+
These two configurations trade off scalability and freshness. Configuration (1) prioritizes freshness over scalability, while configuration (2) prioritizes scalability over freshness.
79+
80+
Suggested changes:
81+
82+
- `enable_batch_api: true`: Retrieves metric values for multiple Azure resources in one API call, supporting more storage accounts.
83+
- `refresh_list_interval: 3600s`: Looks for new storage accounts every 60 minutes instead of 10 minutes, helping to avoid or reduce gaps when monitoring many storage accounts.
84+
85+
Note: By setting the collection `period: 1m`, the metricset only has 60s to collect all metric values instead of 300s, so it can handle fewer storage accounts. Keep in mind that the storage accounts metricset collects metrics for five different namespaces (storage account, blob, file, queue, and table).

x-pack/metricbeat/module/azure/storage/client_helper.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func mapMetrics(client *azure.Client, resources []*armresources.GenericResourceE
5656
}
5757

5858
// some metrics do not support the default PT5M timegrain so they will have to be grouped in a different API call, else call will fail
59-
groupedMetrics := groupOnTimeGrain(filteredMetricDefinitions)
59+
groupedMetrics := groupOnTimeGrain(filteredMetricDefinitions, client.Config.DefaultTimeGrain)
6060

6161
for time, groupedMetricList := range groupedMetrics {
6262
// metrics will have to be grouped by allowed dimensions
@@ -78,11 +78,11 @@ func mapMetrics(client *azure.Client, resources []*armresources.GenericResourceE
7878
}
7979

8080
// groupOnTimeGrain - some metrics do not support the default timegrain value so the closest supported timegrain will be selected
81-
func groupOnTimeGrain(list []armmonitor.MetricDefinition) map[string][]armmonitor.MetricDefinition {
81+
func groupOnTimeGrain(list []armmonitor.MetricDefinition, defaultTimeGrain string) map[string][]armmonitor.MetricDefinition {
8282
var groupedList = make(map[string][]armmonitor.MetricDefinition)
8383

8484
for _, metric := range list {
85-
timegrain := retrieveSupportedMetricAvailability(metric.MetricAvailabilities)
85+
timegrain := retrieveSupportedMetricAvailability(metric.MetricAvailabilities, defaultTimeGrain)
8686
if _, ok := groupedList[timegrain]; !ok {
8787
groupedList[timegrain] = make([]armmonitor.MetricDefinition, 0)
8888
}
@@ -92,21 +92,17 @@ func groupOnTimeGrain(list []armmonitor.MetricDefinition) map[string][]armmonito
9292
}
9393

9494
// retrieveSupportedMetricAvailability func will return the default timegrain if supported, else will return the next timegrain
95-
func retrieveSupportedMetricAvailability(availabilities []*armmonitor.MetricAvailability) string {
95+
func retrieveSupportedMetricAvailability(availabilities []*armmonitor.MetricAvailability, defaultTimeGrain string) string {
9696
// common case in metrics supported by storage account - one availability
9797
if len(availabilities) == 1 {
9898
return *availabilities[0].TimeGrain
9999
}
100100
// check if the default timegrain is supported
101101
for _, availability := range availabilities {
102-
if *availability.TimeGrain == azure.DefaultTimeGrain {
103-
return azure.DefaultTimeGrain
102+
if *availability.TimeGrain == defaultTimeGrain {
103+
return defaultTimeGrain
104104
}
105105
}
106-
// select first timegrain, should be bigger than the min timegrain of 1M, timegrains are returned in asc order
107-
if *availabilities[0].TimeGrain != "PT1M" {
108-
return *availabilities[0].TimeGrain
109-
}
110106
return *availabilities[1].TimeGrain
111107
}
112108

x-pack/metricbeat/module/azure/storage/client_helper_concurrent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func getStorageMappedResourceDefinitions(client *azure.BatchClient, resourceId s
6565
filteredMetricDefinitions = append(filteredMetricDefinitions, *metricDefinition)
6666
}
6767
// some metrics do not support the default PT5M timegrain so they will have to be grouped in a different API call, else call will fail
68-
groupedMetrics := groupOnTimeGrain(filteredMetricDefinitions)
68+
groupedMetrics := groupOnTimeGrain(filteredMetricDefinitions, client.Config.DefaultTimeGrain)
6969
for time, groupedMetricList := range groupedMetrics {
7070
// metrics will have to be grouped by allowed dimensions
7171
dimMetrics := groupMetricsByAllowedDimensions(groupedMetricList)

x-pack/metricbeat/module/azure/storage/client_helper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestFilterOnTimeGrain(t *testing.T) {
162162
{MetricAvailabilities: availability2},
163163
{MetricAvailabilities: availability3},
164164
}
165-
response := groupOnTimeGrain(list)
165+
response := groupOnTimeGrain(list, "PT5M")
166166
assert.Equal(t, len(response), 2)
167167
result := [][]armmonitor.MetricDefinition{
168168
{
@@ -180,11 +180,11 @@ func TestFilterOnTimeGrain(t *testing.T) {
180180
}
181181

182182
func TestRetrieveSupportedMetricAvailability(t *testing.T) {
183-
response := retrieveSupportedMetricAvailability(availability1)
183+
response := retrieveSupportedMetricAvailability(availability1, "PT5M")
184184
assert.Equal(t, response, time2)
185-
response = retrieveSupportedMetricAvailability(availability2)
185+
response = retrieveSupportedMetricAvailability(availability2, "PT5M")
186186
assert.Equal(t, response, time3)
187-
response = retrieveSupportedMetricAvailability(availability3)
187+
response = retrieveSupportedMetricAvailability(availability3, "PT5M")
188188
assert.Equal(t, response, time3)
189189
}
190190

0 commit comments

Comments
 (0)