From 2e8e4e6c3227dcf53c37b08f3e094fd25d66805c Mon Sep 17 00:00:00 2001 From: Mariana Dima Date: Thu, 9 Jan 2020 14:20:53 +0100 Subject: [PATCH] Add cost warning messages to azure get metric values calls (#15356) * Add cost warnings to azure api calls * Add changelog entry * run fmt update --- CHANGELOG.next.asciidoc | 1 + x-pack/metricbeat/module/azure/monitor_service.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index a02da57e5711..8458734e793c 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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* diff --git a/x-pack/metricbeat/module/azure/monitor_service.go b/x-pack/metricbeat/module/azure/monitor_service.go index f4a02a74917d..4800a9c9de54 100644 --- a/x-pack/metricbeat/module/azure/monitor_service.go +++ b/x-pack/metricbeat/module/azure/monitor_service.go @@ -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" @@ -21,6 +23,7 @@ type MonitorService struct { metricNamespaceClient *insights.MetricNamespacesClient resourceClient *resources.Client context context.Context + log *logp.Logger } const metricNameLimit = 20 @@ -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 } @@ -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 }