@@ -19,7 +19,7 @@ import (
19
19
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
20
20
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
21
21
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
22
- "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery "
22
+ "github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics "
23
23
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
24
24
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
25
25
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions"
@@ -35,7 +35,7 @@ import (
35
35
type azureType struct {
36
36
name * string
37
37
attributes map [string ]* string
38
- resourceIDs []* string
38
+ resourceIDs []string
39
39
metricsByCompositeKey map [metricsCompositeKey ]* azureResourceMetrics
40
40
metricsDefinitionsUpdated time.Time
41
41
}
@@ -48,7 +48,6 @@ func newBatchScraper(conf *Config, settings receiver.Settings) *azureBatchScrape
48
48
azIDCredentialsFunc : azidentity .NewClientSecretCredential ,
49
49
azIDWorkloadFunc : azidentity .NewWorkloadIdentityCredential ,
50
50
armMonitorDefinitionsClientFunc : armmonitor .NewMetricDefinitionsClient ,
51
- azQueryMetricsBatchClientFunc : azquery .NewMetricsBatchClient ,
52
51
mutex : & sync.Mutex {},
53
52
}
54
53
}
@@ -73,8 +72,7 @@ type azureBatchScraper struct {
73
72
armClientOptions * arm.ClientOptions
74
73
armSubscriptionclient ArmsubscriptionClient
75
74
armMonitorDefinitionsClientFunc func (string , azcore.TokenCredential , * arm.ClientOptions ) (* armmonitor.MetricDefinitionsClient , error )
76
- azQueryMetricsBatchClientOptions * azquery.MetricsBatchClientOptions
77
- azQueryMetricsBatchClientFunc func (string , azcore.TokenCredential , * azquery.MetricsBatchClientOptions ) (* azquery.MetricsBatchClient , error )
75
+ azQueryMetricsBatchClientOptions * azmetrics.ClientOptions
78
76
mutex * sync.Mutex
79
77
}
80
78
@@ -95,7 +93,7 @@ func (s *azureBatchScraper) getArmClientOptions() *arm.ClientOptions {
95
93
return & options
96
94
}
97
95
98
- func (s * azureBatchScraper ) getAzQueryMetricsBatchClientOptions () * azquery. MetricsBatchClientOptions {
96
+ func (s * azureBatchScraper ) getAzQueryMetricsBatchClientOptions () * azmetrics. ClientOptions {
99
97
var cloudToUse cloud.Configuration
100
98
switch s .cfg .Cloud {
101
99
case azureGovernmentCloud :
@@ -104,7 +102,7 @@ func (s *azureBatchScraper) getAzQueryMetricsBatchClientOptions() *azquery.Metri
104
102
cloudToUse = cloud .AzurePublic
105
103
}
106
104
107
- options := azquery. MetricsBatchClientOptions {
105
+ options := azmetrics. ClientOptions {
108
106
ClientOptions : azcore.ClientOptions {
109
107
Cloud : cloudToUse ,
110
108
},
@@ -129,15 +127,15 @@ func (s *azureBatchScraper) getMetricsDefinitionsClient(subscriptionID string) m
129
127
}
130
128
131
129
type MetricBatchValuesClient interface {
132
- QueryBatch (ctx context.Context , subscriptionID string , metricNamespace string , metricNames []string , resourceIDs azquery .ResourceIDList , options * azquery. MetricsBatchClientQueryBatchOptions ) (
133
- azquery. MetricsBatchClientQueryBatchResponse , error ,
130
+ QueryResources (ctx context.Context , subscriptionID string , metricNamespace string , metricNames []string , resourceIDs azmetrics .ResourceIDList , options * azmetrics. QueryResourcesOptions ) (
131
+ azmetrics. QueryResourcesResponse , error ,
134
132
)
135
133
}
136
134
137
135
func (s * azureBatchScraper ) GetMetricsBatchValuesClient (region string ) MetricBatchValuesClient {
138
136
endpoint := "https://" + region + ".metrics.monitor.azure.com"
139
137
s .settings .Logger .Info ("Batch Endpoint" , zap .String ("endpoint" , endpoint ))
140
- client , _ := azquery . NewMetricsBatchClient (endpoint , s .cred , s .azQueryMetricsBatchClientOptions )
138
+ client , _ := azmetrics . NewClient (endpoint , s .cred , s .azQueryMetricsBatchClientOptions )
141
139
return client
142
140
}
143
141
@@ -292,10 +290,10 @@ func (s *azureBatchScraper) getResources(ctx context.Context, subscriptionID str
292
290
updatedTypes [* resource .Type ] = & azureType {
293
291
name : resource .Type ,
294
292
attributes : map [string ]* string {},
295
- resourceIDs : []* string {resource .ID },
293
+ resourceIDs : []string {* resource .ID },
296
294
}
297
295
} else {
298
- updatedTypes [* resource .Type ].resourceIDs = append (updatedTypes [* resource .Type ].resourceIDs , resource .ID )
296
+ updatedTypes [* resource .Type ].resourceIDs = append (updatedTypes [* resource .Type ].resourceIDs , * resource .ID )
299
297
}
300
298
}
301
299
delete (existingResources , * resource .ID )
@@ -335,12 +333,12 @@ func (s *azureBatchScraper) getResourceMetricsDefinitionsByType(ctx context.Cont
335
333
s.resourceTypes [* subscription.SubscriptionID ][resourceType ].metricsByCompositeKey = map [metricsCompositeKey ]* azureResourceMetrics {}
336
334
337
335
resourceIDs := s.resourceTypes [* subscription.SubscriptionID ][resourceType ].resourceIDs
338
- if len (resourceIDs ) == 0 && resourceIDs [0 ] != nil {
336
+ if len (resourceIDs ) == 0 && len ( resourceIDs [0 ]) > 0 {
339
337
return
340
338
}
341
339
342
340
clientMetricsDefinitions := s .getMetricsDefinitionsClient (* subscription .SubscriptionID )
343
- pager := clientMetricsDefinitions .NewListPager (* resourceIDs [0 ], nil )
341
+ pager := clientMetricsDefinitions .NewListPager (resourceIDs [0 ], nil )
344
342
for pager .More () {
345
343
nextResult , err := pager .NextPage (ctx )
346
344
if err != nil {
@@ -420,20 +418,23 @@ func (s *azureBatchScraper) getBatchMetricsValues(ctx context.Context, subscript
420
418
zap .String ("interval" , compositeKey .timeGrain ),
421
419
)
422
420
423
- response , err := clientMetrics .QueryBatch (
421
+ response , err := clientMetrics .QueryResources (
424
422
ctx ,
425
423
* subscription .SubscriptionID ,
426
424
resourceType ,
427
425
metricsByGrain .metrics [start :end ],
428
- azquery.ResourceIDList {ResourceIDs : resType .resourceIDs [startResources :endResources ]},
429
- & azquery.MetricsBatchClientQueryBatchOptions {
430
- Aggregation : to .SliceOfPtrs (
431
- azquery .AggregationTypeAverage ,
432
- azquery .AggregationTypeMaximum ,
433
- azquery .AggregationTypeMinimum ,
434
- azquery .AggregationTypeTotal ,
435
- azquery .AggregationTypeCount ,
436
- ),
426
+ azmetrics.ResourceIDList {ResourceIDs : resType .resourceIDs [startResources :endResources ]},
427
+ & azmetrics.QueryResourcesOptions {
428
+ Aggregation : to .Ptr (strings .Join (
429
+ []string {
430
+ string (armmonitor .AggregationTypeAverage ),
431
+ string (armmonitor .AggregationTypeMaximum ),
432
+ string (armmonitor .AggregationTypeMinimum ),
433
+ string (armmonitor .AggregationTypeTotal ),
434
+ string (armmonitor .AggregationTypeCount ),
435
+ },
436
+ "," ,
437
+ )),
437
438
StartTime : to .Ptr (startTime .Format (time .RFC3339 )),
438
439
EndTime : to .Ptr (now .Format (time .RFC3339 )),
439
440
Interval : to .Ptr (compositeKey .timeGrain ),
@@ -498,8 +499,8 @@ func (s *azureBatchScraper) getBatchMetricsValues(ctx context.Context, subscript
498
499
499
500
func (s * azureBatchScraper ) processQueryTimeseriesData (
500
501
resourceID string ,
501
- metric * azquery .Metric ,
502
- metricValue * azquery .MetricValue ,
502
+ metric azmetrics .Metric ,
503
+ metricValue azmetrics .MetricValue ,
503
504
attributes map [string ]* string ,
504
505
) {
505
506
s .mutex .Lock ()
0 commit comments