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

[MetricsAdvisor] Fix Update methods issues #16696

Merged
merged 3 commits into from
Nov 9, 2020
Merged

Conversation

kinelski
Copy link
Member

@kinelski kinelski commented Nov 6, 2020

Fixes #16168.

@kinelski kinelski added Client This issue points to a problem in the data-plane of the library. Cognitive - Metrics Advisor labels Nov 6, 2020
@kinelski kinelski self-assigned this Nov 6, 2020
@@ -78,7 +78,7 @@ internal AnomalyAlertingConfigurationPatch GetPatchModel()
{
return new AnomalyAlertingConfigurationPatch()
{
CrossMetricsOperator = CrossMetricsOperator.HasValue ? new AnomalyAlertingConfigurationPatchCrossMetricsOperator(CrossMetricsOperator.Value.ToString()) : default,
CrossMetricsOperator = CrossMetricsOperator.HasValue ? new AnomalyAlertingConfigurationPatchCrossMetricsOperator(CrossMetricsOperator.Value.ToString()) : default(AnomalyAlertingConfigurationPatchCrossMetricsOperator?),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the source of the issue in UpdateAlertConfiguration. CrossMetricsOperator is a nullable struct, and we were mistakenly expecting default to be null.

To make it easier to illustrate, let's use a clearer example:

bool condition = ...;
int? a = condition ? 10 : default; 

If condition == true, we'll have a = 10. If condition == false, we'll have a = 0 (instead of null).

The ternary operator is evaluated before the attribution, and the compiler guesses the result must be an int, so it makes default(int) instead of default(int?). For this reason, we need to make it clear:

int? a = condition ? 10 : default(int?);

I have updated other parts of the code in which we had the same issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting bug - Seems like it is defined in this issue dotnet/csharplang#33

Comment on lines -22 to +24
CustomFillValue = dataFeedDetail.FillMissingPointValue;
CustomFillValue = dataFeedDetail.FillMissingPointType == DataFeedMissingDataPointFillType.CustomValue
? dataFeedDetail.FillMissingPointValue
: null;
Copy link
Member Author

@kinelski kinelski Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the source of the issue in UpdateDataFeed. DataFeedMissingDataPointFillSettings has two properties.

One of them is FillMissingPointType (the strategy used to fill missing points in time series: NoFilling, PreviousValue, CustomValue, ...).

There's another property that must be specified when type is CustomValue: CustomFillValue, the const value used to fill the missing point.

When the fill type is NOT CustomValue, I'd expect the service to not return the CustomFillValue (or return null). However, it returns 0.0. When we call Get followed by Update, we store the 0 returned by the service and try to send it back (which is not allowed, because type is not CustomValue).

We're doing a workaround, but it may be something to fix on the service side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kinelski kinelski marked this pull request as ready for review November 6, 2020 20:11
@kinelski kinelski merged commit 1f2d3de into Azure:master Nov 9, 2020
@kinelski kinelski deleted the ma-bug branch November 9, 2020 15:17
annelo-msft pushed a commit to annelo-msft/azure-sdk-for-net that referenced this pull request Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Cognitive - Metrics Advisor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MetricsAdvisor] Fix Update sample issues
2 participants