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

fix: Improve AzureMonitorScraper Error Handling for Time Series Missing Requested Dimension Value #2345

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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/content/experimental/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version:

- {{% tag changed %}} Switch to Mariner distroless base images
- {{% tag security %}} Patch for [CVE-2023-29331](https://github.com/advisories/GHSA-555c-2p6r-68mm) (High)
- {{% tag fixed %}} Better handle time series missing requested dimension in AzureMonitorClient [#2331](https://github.com/tomkerkhove/promitor/issues/2331))
hkfgo marked this conversation as resolved.
Show resolved Hide resolved

#### Resource Discovery

Expand Down
6 changes: 4 additions & 2 deletions src/Promitor.Core/Metrics/MeasuredMetric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public static MeasuredMetric CreateForDimension(double? value, string dimensionN
{
Guard.NotNullOrWhitespace(dimensionName, nameof(dimensionName));
Guard.NotNull(timeseries, nameof(timeseries));
Guard.For<ArgumentException>(() => timeseries.Metadatavalues.Any() == false);

var dimensionMetadataValue = timeseries.Metadatavalues.Where(metadataValue => metadataValue.Name?.Value.Equals(dimensionName, StringComparison.InvariantCultureIgnoreCase) == true);
Guard.For<ArgumentException>(() => dimensionMetadataValue.Count() == 0);
hkfgo marked this conversation as resolved.
Show resolved Hide resolved

var dimensionValue = timeseries.Metadatavalues.Single(metadataValue => metadataValue.Name?.Value.Equals(dimensionName, StringComparison.InvariantCultureIgnoreCase) == true);
var dimensionValue = dimensionMetadataValue.First();
hkfgo marked this conversation as resolved.
Show resolved Hide resolved
hkfgo marked this conversation as resolved.
Show resolved Hide resolved
return CreateForDimension(value, dimensionName, dimensionValue.Value);
}

Expand Down
14 changes: 11 additions & 3 deletions src/Promitor.Integrations.AzureMonitor/AzureMonitorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Azure.Management.Monitor.Fluent.Models;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using Newtonsoft.Json;
tomkerkhove marked this conversation as resolved.
Show resolved Hide resolved
using GuardNet;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Extensions.Caching.Memory;
Expand Down Expand Up @@ -108,9 +109,16 @@

// Get the metric value according to the requested aggregation type
var requestedMetricAggregate = InterpretMetricValue(aggregationType, mostRecentMetricValue);

var measuredMetric = string.IsNullOrWhiteSpace(metricDimension) ? MeasuredMetric.CreateWithoutDimension(requestedMetricAggregate) : MeasuredMetric.CreateForDimension(requestedMetricAggregate, metricDimension, timeseries);
measuredMetrics.Add(measuredMetric);
try
{
var measuredMetric = string.IsNullOrWhiteSpace(metricDimension) ? MeasuredMetric.CreateWithoutDimension(requestedMetricAggregate) : MeasuredMetric.CreateForDimension(requestedMetricAggregate, metricDimension, timeseries);
hkfgo marked this conversation as resolved.
Show resolved Hide resolved
measuredMetrics.Add(measuredMetric);
}
catch (ArgumentException)
{
_logger.LogWarning("{MetricName} has return a time series with empty value for {Dimension} and the measurements will be dropped", metricName, metricDimension);
tomkerkhove marked this conversation as resolved.
Show resolved Hide resolved
_logger.LogDebug("The violating time series has content {TimeSeriesJson}}", JsonConvert.SerializeObject(timeseries));

Check warning on line 120 in src/Promitor.Integrations.AzureMonitor/AzureMonitorClient.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[StructuredMessageTemplateProblem] Unmatched closing brace in message template" on /home/runner/work/promitor/promitor/src/Promitor.Integrations.AzureMonitor/AzureMonitorClient.cs(120,7899)
hkfgo marked this conversation as resolved.
Show resolved Hide resolved
}
}

return measuredMetrics;
Expand Down
Loading