Skip to content

Commit

Permalink
[Metricbeat][Azure]Check for metrics dimensions before matching two m…
Browse files Browse the repository at this point in the history
…etrics together (#42591)

* Check for metrics dimensions before matching two metrics together

* Add test case for metrics with different dimensions
  • Loading branch information
MichaelKatsoulis authored Feb 6, 2025
1 parent 81e2def commit d9f5498
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x-pack/metricbeat/module/azure/client_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func metricIsEmpty(metric armmonitor.MetricValue) bool {
// matchMetrics will compare current metrics
func matchMetrics(prevMet Metric, met Metric) bool {
if prevMet.Namespace == met.Namespace && reflect.DeepEqual(prevMet.Names, met.Names) && prevMet.ResourceId == met.ResourceId &&
prevMet.Aggregations == met.Aggregations && prevMet.TimeGrain == met.TimeGrain {
prevMet.Aggregations == met.Aggregations && prevMet.TimeGrain == met.TimeGrain && reflect.DeepEqual(prevMet.Dimensions, met.Dimensions) {
return true
}
return false
Expand Down
6 changes: 6 additions & 0 deletions x-pack/metricbeat/module/azure/client_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ func TestMatchMetrics(t *testing.T) {
Values: []MetricValue{},
TimeGrain: "1PM",
}
// match
result := matchMetrics(prev, current)
assert.True(t, result)
// different resourceId, not match
current.ResourceId = "id1"
result = matchMetrics(prev, current)
assert.False(t, result)
// different dimension, not match
current.Dimensions = []Dimension{{Name: "location", Value: "East Europe"}}
result = matchMetrics(prev, current)
assert.False(t, result)
}

func TestMetricIsEmpty(t *testing.T) {
Expand Down

0 comments on commit d9f5498

Please sign in to comment.