-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve AzureMonitorScraper Error Handling for Time Series Missi…
…ng Requested Dimension Value (#2345) * improve error handling for when a time series is returned without dimension value * small fixes address comments * add to changelog * use targeted exception time for missing dimension + add basic tests * formatting fix * address a few small comments from Tom * address a few small comments from Tom * code style fix * fix R sharper style warnings * change measuredmetric test to support multiple dimensions * change measuredmetric test to support multiple dimensions * fix: Remove redundant using statement * Code quality * Code quality --------- Co-authored-by: Tom Kerkhove <[email protected]>
- Loading branch information
1 parent
45c56c8
commit 35ebbe5
Showing
6 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Promitor.Core/Metrics/Exceptions/MissingDimensionException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using GuardNet; | ||
using Microsoft.Azure.Management.Monitor.Fluent.Models; | ||
|
||
namespace Promitor.Core.Metrics.Exceptions | ||
{ | ||
public class MissingDimensionException : Exception | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="dimensionName">Name of the dimension</param> | ||
/// <param name="timeSeries">Time series element missing the dimension</param> | ||
public MissingDimensionException(string dimensionName, TimeSeriesElement timeSeries) : base($"No value found for dimension '{dimensionName}'") | ||
{ | ||
Guard.NotNullOrWhitespace(dimensionName, nameof(dimensionName)); | ||
|
||
DimensionName = dimensionName; | ||
TimeSeries = timeSeries; | ||
} | ||
|
||
/// <summary> | ||
/// Name of the dimension | ||
/// </summary> | ||
public string DimensionName { get; } | ||
|
||
/// <summary> | ||
/// Time series element producing the exception | ||
/// </summary> | ||
public TimeSeriesElement TimeSeries { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using Promitor.Core.Metrics; | ||
using Microsoft.Azure.Management.Monitor.Fluent.Models; | ||
using Xunit; | ||
using Promitor.Core.Metrics.Exceptions; | ||
|
||
namespace Promitor.Tests.Unit.Metrics | ||
{ | ||
[Category("Unit")] | ||
public class MeasuredMetricTest : UnitTest | ||
{ | ||
[Fact] | ||
public void Create_MeasuredMetric_With_Single_Dimension_HappyPath_Succeeds() | ||
{ | ||
var dimensionNames = new List<string> { "dimTest"}; | ||
var dimensionValue = "dimTest1"; | ||
var timeSeries = new TimeSeriesElement(new List<MetadataValue> { new(name: new LocalizableString(dimensionNames[0]), value: dimensionValue)}); | ||
var measuredMetric = MeasuredMetric.CreateForDimensions(1, dimensionNames, timeSeries); | ||
Assert.Single(measuredMetric.Dimensions); | ||
Assert.Equal(dimensionNames[0], measuredMetric.Dimensions[0].Name); | ||
Assert.Equal(dimensionValue, measuredMetric.Dimensions[0].Value); | ||
Assert.Equal(1, measuredMetric.Value); | ||
} | ||
|
||
[Fact] | ||
public void Create_MeasuredMetric_Missing_Dimension_Throws_Targeted_Exception() | ||
{ | ||
var dimensionName = new List<string> { "dimTest"}; | ||
var timeSeries = new TimeSeriesElement(new List<MetadataValue>()); | ||
MissingDimensionException ex = Assert.Throws<MissingDimensionException>(() => MeasuredMetric.CreateForDimensions(1, dimensionName, timeSeries)); | ||
Assert.Equal(ex.DimensionName, dimensionName[0]); | ||
} | ||
} | ||
} |