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)

* 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)
  • Loading branch information
zmoog committed Jan 16, 2024
1 parent daf66b1 commit f500d85
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 @@ -127,6 +127,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Fix the "api-version query parameter (?api-version=) is required for all requests" error in Azure Billing. {pull}37158[37158]
- Add memory hard limit from container metadata and remove usage percentage in AWS Fargate. {pull}37194[37194]
- Fix the reference time rounding on Azure Metrics {issue}37204[37204] {pull}37365[37365]
- 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 f500d85

Please sign in to comment.