Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.12](backport #37643) Fix value mapping for min and max aggregation type in Azure Monitor #37649

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
Loading