Skip to content

Commit

Permalink
Add cost warning messages to azure get metric values calls (elastic#1…
Browse files Browse the repository at this point in the history
…5356)

* Add cost warnings to azure api calls

* Add changelog entry

* run fmt update
  • Loading branch information
narph authored Jan 9, 2020
1 parent 33a638b commit 2e8e4e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add overview dashboard for AWS SNS module {pull}14977[14977]
- Add `index` option to all modules to specify a module-specific output index. {pull}15100[15100]
- Add a `system/service` metricset for systemd data. {pull}14206[14206]
- Add cost warnings for the azure module. {pull}15356[15356]

*Packetbeat*

Expand Down
9 changes: 9 additions & 0 deletions x-pack/metricbeat/module/azure/monitor_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"fmt"
"strings"

"github.com/elastic/beats/libbeat/logp"

"github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-03-01/resources"
"github.com/Azure/go-autorest/autorest/azure/auth"
Expand All @@ -21,6 +23,7 @@ type MonitorService struct {
metricNamespaceClient *insights.MetricNamespacesClient
resourceClient *resources.Client
context context.Context
log *logp.Logger
}

const metricNameLimit = 20
Expand All @@ -46,6 +49,7 @@ func NewService(clientID string, clientSecret string, tenantID string, subscript
metricNamespaceClient: &metricNamespaceClient,
resourceClient: &resourceClient,
context: context.Background(),
log: logp.NewLogger("azure monitor service"),
}
return service, nil
}
Expand Down Expand Up @@ -100,6 +104,11 @@ func (service *MonitorService) GetMetricValues(resourceID string, namespace stri
}
resp, err := service.metricsClient.List(service.context, resourceID, timespan, tg, strings.Join(metricNames[i:end], ","),
aggregations, nil, "", filter, insights.Data, namespace)

// check for applied charges before returning any errors
if resp.Cost != nil && *resp.Cost != 0 {
service.log.Warnf("Charges amounted to %v are being applied while retrieving the metric values from the resource %s ", *resp.Cost, resourceID)
}
if err != nil {
return metrics, err
}
Expand Down

0 comments on commit 2e8e4e6

Please sign in to comment.