Skip to content

Commit

Permalink
Fix value mapping for min and max aggregation type in Azure Monitor (#…
Browse files Browse the repository at this point in the history
…37643) (#37648)

* Fix value mapping for min and max aggregation type

Metric values for `min` and `max` aggregation types were picked up
from the wrong place.

---------

Co-authored-by: Andrew Gizas <andreas.gkizas@elastic.co>
(cherry picked from commit 1554d7d)

Co-authored-by: Maurizio Branca <maurizio.branca@elastic.co>
  • Loading branch information
mergify[bot] and zmoog authored Jan 16, 2024
1 parent a1cb251 commit 7a24419
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Fix EC2 host.cpu.usage {pull}35717[35717]
- Add option in SQL module to execute queries for all dbs. {pull}35688[35688]
- Add remaining dimensions for azure storage account to make them available for tsdb enablement. {pull}36331[36331]
- Fix Azure Resource Metrics missing metrics (min and max aggregations) after upgrade to 8.11.3 {issue}37642[37642] {pull}37643[37643]

*Osquerybeat*

Expand Down
4 changes: 2 additions & 2 deletions x-pack/metricbeat/module/azure/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ func mapToKeyValuePoints(metrics []Metric) []KeyValuePoint {
switch {
case value.min != nil:
point.Key = fmt.Sprintf("%s.%s", metricName, "min")
point.Value = value.avg
point.Value = value.min
case value.max != nil:
point.Key = fmt.Sprintf("%s.%s", metricName, "max")
point.Value = value.avg
point.Value = value.max
case value.avg != nil:
point.Key = fmt.Sprintf("%s.%s", metricName, "avg")
point.Value = value.avg
Expand Down
116 changes: 116 additions & 0 deletions x-pack/metricbeat/module/azure/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
package azure

import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -46,3 +48,117 @@ func TestManagePropertyName(t *testing.T) {
result = managePropertyName("Percentage CPU")
assert.Equal(t, result, "percentage_cpu")
}

func TestMapToKeyValuePoints(t *testing.T) {
timestamp := time.Now().UTC()
metricName := "test"
minValue := 4.0
maxValue := 42.0
avgValue := 13.0
totalValue := 46.0
countValue := 2.0
namespace := "test"
resourceId := "test"
resourceSubId := "test"
timeGrain := "PT1M"

t.Run("test aggregation types", func(t *testing.T) {

metrics := []Metric{{
Namespace: namespace,
Names: []string{"test"},
Aggregations: "min",
Values: []MetricValue{{name: metricName, min: &minValue, timestamp: timestamp}},
TimeGrain: timeGrain,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
}, {
Namespace: namespace,
Names: []string{"test"},
Aggregations: "max",
Values: []MetricValue{{name: metricName, max: &maxValue, timestamp: timestamp}},
TimeGrain: timeGrain,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
}, {
Namespace: namespace,
Names: []string{"test"},
Aggregations: "avg",
Values: []MetricValue{{name: metricName, avg: &avgValue, timestamp: timestamp}},
TimeGrain: timeGrain,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
}, {
Namespace: namespace,
Names: []string{"test"},
Aggregations: "total",
Values: []MetricValue{{name: metricName, total: &totalValue, timestamp: timestamp}},
TimeGrain: timeGrain,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
}, {
Namespace: namespace,
Names: []string{"test"},
Aggregations: "count",
Values: []MetricValue{{name: metricName, count: &countValue, timestamp: timestamp}},
TimeGrain: timeGrain,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
}}

actual := mapToKeyValuePoints(metrics)

expected := []KeyValuePoint{
{
Key: fmt.Sprintf("%s.%s", metricName, "min"),
Value: &minValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
}, {
Key: fmt.Sprintf("%s.%s", metricName, "max"),
Value: &maxValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
}, {
Key: fmt.Sprintf("%s.%s", metricName, "avg"),
Value: &avgValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "total"),
Value: &totalValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "count"),
Value: &countValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
}

assert.Equal(t, expected, actual)
})
}

0 comments on commit 7a24419

Please sign in to comment.