-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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] Overwriting patch serialization methods to support sending null #22457
Conversation
if (Optional.IsDefined(DataFeedName)) | ||
{ | ||
writer.WritePropertyName("dataFeedName"); | ||
writer.WriteStringValue(DataFeedName); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see, the serialization method does not send null to the service. Unfortunately, we need to overwrite all serialization methods for Patch models (used during Update operations only) in order to send null when a property is not present.
|
||
namespace Azure.AI.MetricsAdvisor.Models | ||
{ | ||
internal partial class DataFeedDetailPatch : IUtf8JsonSerializable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this to another folder (Models/CodeGenInternal/PatchModels)
writer.WritePropertyName("dataSourceParameter"); | ||
writer.WriteObjectValue(DataSourceParameter); | ||
} | ||
SerializeCommonProperties(writer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All <...>DataFeedPatch
models, including this one, are subclasses of DataFeedDetailPatch
. I put serialization of all properties of the base class in SerializeCommonProperties
to avoid repeating (a lot of) code, specially since we have 13 subtypes.
if (Optional.IsDefined(ApiKey)) | ||
{ | ||
writer.WritePropertyName("apiKey"); | ||
writer.WriteStringValue(ApiKey); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not sending null for secrets, though. There's a good reason for this. The service does not return secrets to us, so this would happen:
var dataFeed = client.GetDataFeed(...);
// Here, dataFeed.DataSource.ApiKey is null because it was not returned by the service.
// Update some properties here
// This would send apiKey = null to the service, even though we didn't touch it.
client.UpdateDataFeed(dataFeed);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and will that cause an error in the service? if this was allowed before, would it be better to add an entry to the changelog saying how this "bug" got fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and will that cause an error in the service?
Correct. We get back an error message saying the secret is required.
if this was allowed before, would it be better to add an entry to the changelog saying how this "bug" got fixed?
We were not overwriting the serialization method before, so we were not sending null. My point in this comment is "let's keep the ApiKey behaving as it already was. If we change it, it breaks".
|
||
namespace Azure.AI.MetricsAdvisor | ||
{ | ||
internal static class Utf8JsonWriterExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convenience methods to make serialization code shorter. We can reduce:
if (value != null)
{
writer.WritePropertyName(...);
writer.Write<Something>Value(...);
}
else
{
writer.WriteNull(propertyName);
}
to a single line.
|
||
string dataFeedName = Recording.GenerateAlphaNumericId("dataFeed"); | ||
DataFeedSource dataSource = CreateMockDataFeedSource(dataSourceKind); | ||
var dataFeedToCreate = new DataFeed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set initial values for required properties and for anything that can be updated.
dataFeedToUpdate.IngestionSettings.IngestionStartOffset = null; | ||
dataFeedToUpdate.IngestionSettings.IngestionRetryDelay = null; | ||
dataFeedToUpdate.IngestionSettings.StopRetryAfter = null; | ||
dataFeedToUpdate.IngestionSettings.DataSourceRequestConcurrency = null; | ||
dataFeedToUpdate.Schema.TimestampColumn = null; | ||
dataFeedToUpdate.Description = null; | ||
dataFeedToUpdate.RollupSettings.RollupType = null; | ||
dataFeedToUpdate.RollupSettings.AutoRollupMethod = null; | ||
dataFeedToUpdate.RollupSettings.RollupIdentificationValue = null; | ||
dataFeedToUpdate.MissingDataPointFillSettings = null; | ||
dataFeedToUpdate.AccessMode = null; | ||
dataFeedToUpdate.ActionLinkTemplate = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set everything that can be updated to null to restore the default values.
Assert.That(updatedDataFeed.IngestionSettings.IngestionStartOffset, Is.EqualTo(TimeSpan.Zero)); | ||
Assert.That(updatedDataFeed.IngestionSettings.IngestionRetryDelay, Is.EqualTo(TimeSpan.FromSeconds(-1))); | ||
Assert.That(updatedDataFeed.IngestionSettings.StopRetryAfter, Is.EqualTo(TimeSpan.FromSeconds(-1))); | ||
Assert.That(updatedDataFeed.IngestionSettings.DataSourceRequestConcurrency, Is.EqualTo(-1)); | ||
Assert.That(updatedDataFeed.Schema.TimestampColumn, Is.Empty); | ||
Assert.That(updatedDataFeed.Description, Is.Empty); | ||
Assert.That(updatedDataFeed.RollupSettings.RollupType, Is.EqualTo(DataFeedRollupType.NoRollupNeeded)); | ||
Assert.That(updatedDataFeed.RollupSettings.AutoRollupMethod, Is.EqualTo(DataFeedAutoRollupMethod.None)); | ||
Assert.That(updatedDataFeed.RollupSettings.RollupIdentificationValue, Is.Null); | ||
Assert.That(updatedDataFeed.MissingDataPointFillSettings.FillType, Is.EqualTo(DataFeedMissingDataPointFillType.SmartFilling)); | ||
Assert.That(updatedDataFeed.AccessMode, Is.EqualTo(DataFeedAccessMode.Private)); | ||
Assert.That(updatedDataFeed.ActionLinkTemplate, Is.Empty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if default values are correct.
} | ||
|
||
[RecordedTest] | ||
public async Task UpdateAzureBlobDataFeedAuthenticationWithNullSetsToDefault() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following tests handle properties specific to each data feed source. The test above was for common properties only.
This pull request is protected by Check Enforcer. What is Check Enforcer?Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass. Why am I getting this message?You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged. What should I do now?If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows: What if I am onboarding a new service?Often, new services do not have validation pipelines associated with them. In order to bootstrap pipelines for a new service, please perform following steps: For data-plane/track 2 SDKs Issue the following command as a pull request comment:
For track 1 management-plane SDKsPlease open a separate PR and to your service SDK path in this file. Once that PR has been merged, you can re-run the pipeline to trigger the verification. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a changelog entry and some samples will be good to showcase this new feature to the user
if (Optional.IsDefined(ApiKey)) | ||
{ | ||
writer.WritePropertyName("apiKey"); | ||
writer.WriteStringValue(ApiKey); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and will that cause an error in the service? if this was allowed before, would it be better to add an entry to the changelog saying how this "bug" got fixed?
{ | ||
internal static class Utf8JsonWriterExtensions | ||
{ | ||
public static void WriteNullStringValue(this Utf8JsonWriter writer, string propertyName, string value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if to simplify all this code, you could do something like this https://github.com/Azure/autorest.csharp/blob/f790582c450f6f90e173a12e96c8e83a745a0b0f/src/assets/Generator.Shared/Utf8JsonWriterExtensions.cs#L52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really liked the suggestion. Created an issue to track it (#22472). Won't update the code now since it's only an internal change and it may affect 4 open PRs right now.
Added a changelog entry in the Regarding samples, I made a small addition to the // Some properties, such as IngestionStartOffset, can be reset to their default value
// when set to null during an Update operation. Check the API documentation to verify
// when a property supports this feature.
dataFeed.IngestionSettings.IngestionStartOffset = null;
response = await adminClient.UpdateDataFeedAsync(dataFeed);
// ... Print new value Do you think it may be worth adding more properties to the sample? I'm going through all docstrings in the library and fixing anything that sounds off or poor written. I'm also adding remarks pointing out when a property can be reset to its default value during an Update operation. The Update scenario is not one of our core scenarios for this library, so this is not a big change from the customers' point of view (even though it gave us so much trouble in terms of code). Update and management operations in general usually are a single-time event, so we expect users to do this through the portal more often. |
Not all of them but make sure that in the more advanced samples this is showcased. If, after release, we hear from the community that they need more documentation, then you can add more specific samples |
Networking 2022-09-01 release (Azure#22639) * Adds base for updating Microsoft.Network from version stable/2022-07-01 to version 2022-09-01 * Updates readme * Updates API version in new specs and examples * Added flowlog property in virtual network (Azure#21790) Co-authored-by: Krishna Mishra <krmishr@microsoft.com> * commit1 (Azure#22111) Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> * adding auth status property to circuit (Azure#22024) * Make auth status readonly (Azure#22365) * make auth status read only * fixing model validation * prettier fix * Add support for State flag in Custom Rule (Azure#22457) * Fix LRO header model validation (Azure#22506) * Add new status code for application gateway custom error page (Azure#22151) * Add new status code for application gateway custom error page * Fix prettier * Adding words to Custom-Words list * Fix missing resource id in application gateway list example (Azure#22509) * Resolving merge conflicts with main branch --------- Co-authored-by: Mikhail <mitryakh@microsoft.com> Co-authored-by: KRISHNA MISHRA <krishmi139@gmail.com> Co-authored-by: Krishna Mishra <krmishr@microsoft.com> Co-authored-by: Khushboo Baheti <37917868+Khushboo-Baheti@users.noreply.github.com> Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> Co-authored-by: utbarn-ms <66377251+utbarn-ms@users.noreply.github.com> Co-authored-by: tejasshah7 <49326906+tejasshah7@users.noreply.github.com> Co-authored-by: Prateek Sachan <42961174+prateek2211@users.noreply.github.com>
Networking 2022-09-01 release (Azure#22639) * Adds base for updating Microsoft.Network from version stable/2022-07-01 to version 2022-09-01 * Updates readme * Updates API version in new specs and examples * Added flowlog property in virtual network (Azure#21790) Co-authored-by: Krishna Mishra <krmishr@microsoft.com> * commit1 (Azure#22111) Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> * adding auth status property to circuit (Azure#22024) * Make auth status readonly (Azure#22365) * make auth status read only * fixing model validation * prettier fix * Add support for State flag in Custom Rule (Azure#22457) * Fix LRO header model validation (Azure#22506) * Add new status code for application gateway custom error page (Azure#22151) * Add new status code for application gateway custom error page * Fix prettier * Adding words to Custom-Words list * Fix missing resource id in application gateway list example (Azure#22509) * Resolving merge conflicts with main branch --------- Co-authored-by: Mikhail <mitryakh@microsoft.com> Co-authored-by: KRISHNA MISHRA <krishmi139@gmail.com> Co-authored-by: Krishna Mishra <krmishr@microsoft.com> Co-authored-by: Khushboo Baheti <37917868+Khushboo-Baheti@users.noreply.github.com> Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> Co-authored-by: utbarn-ms <66377251+utbarn-ms@users.noreply.github.com> Co-authored-by: tejasshah7 <49326906+tejasshah7@users.noreply.github.com> Co-authored-by: Prateek Sachan <42961174+prateek2211@users.noreply.github.com>
Networking 2022-09-01 release (Azure#22639) * Adds base for updating Microsoft.Network from version stable/2022-07-01 to version 2022-09-01 * Updates readme * Updates API version in new specs and examples * Added flowlog property in virtual network (Azure#21790) Co-authored-by: Krishna Mishra <krmishr@microsoft.com> * commit1 (Azure#22111) Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> * adding auth status property to circuit (Azure#22024) * Make auth status readonly (Azure#22365) * make auth status read only * fixing model validation * prettier fix * Add support for State flag in Custom Rule (Azure#22457) * Fix LRO header model validation (Azure#22506) * Add new status code for application gateway custom error page (Azure#22151) * Add new status code for application gateway custom error page * Fix prettier * Adding words to Custom-Words list * Fix missing resource id in application gateway list example (Azure#22509) * Resolving merge conflicts with main branch --------- Co-authored-by: Mikhail <mitryakh@microsoft.com> Co-authored-by: KRISHNA MISHRA <krishmi139@gmail.com> Co-authored-by: Krishna Mishra <krmishr@microsoft.com> Co-authored-by: Khushboo Baheti <37917868+Khushboo-Baheti@users.noreply.github.com> Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> Co-authored-by: utbarn-ms <66377251+utbarn-ms@users.noreply.github.com> Co-authored-by: tejasshah7 <49326906+tejasshah7@users.noreply.github.com> Co-authored-by: Prateek Sachan <42961174+prateek2211@users.noreply.github.com>
Networking 2022-09-01 release (Azure#22639) * Adds base for updating Microsoft.Network from version stable/2022-07-01 to version 2022-09-01 * Updates readme * Updates API version in new specs and examples * Added flowlog property in virtual network (Azure#21790) Co-authored-by: Krishna Mishra <krmishr@microsoft.com> * commit1 (Azure#22111) Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> * adding auth status property to circuit (Azure#22024) * Make auth status readonly (Azure#22365) * make auth status read only * fixing model validation * prettier fix * Add support for State flag in Custom Rule (Azure#22457) * Fix LRO header model validation (Azure#22506) * Add new status code for application gateway custom error page (Azure#22151) * Add new status code for application gateway custom error page * Fix prettier * Adding words to Custom-Words list * Fix missing resource id in application gateway list example (Azure#22509) * Resolving merge conflicts with main branch --------- Co-authored-by: Mikhail <mitryakh@microsoft.com> Co-authored-by: KRISHNA MISHRA <krishmi139@gmail.com> Co-authored-by: Krishna Mishra <krmishr@microsoft.com> Co-authored-by: Khushboo Baheti <37917868+Khushboo-Baheti@users.noreply.github.com> Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> Co-authored-by: utbarn-ms <66377251+utbarn-ms@users.noreply.github.com> Co-authored-by: tejasshah7 <49326906+tejasshah7@users.noreply.github.com> Co-authored-by: Prateek Sachan <42961174+prateek2211@users.noreply.github.com>
Networking 2022-09-01 release (Azure#22639) * Adds base for updating Microsoft.Network from version stable/2022-07-01 to version 2022-09-01 * Updates readme * Updates API version in new specs and examples * Added flowlog property in virtual network (Azure#21790) Co-authored-by: Krishna Mishra <krmishr@microsoft.com> * commit1 (Azure#22111) Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> * adding auth status property to circuit (Azure#22024) * Make auth status readonly (Azure#22365) * make auth status read only * fixing model validation * prettier fix * Add support for State flag in Custom Rule (Azure#22457) * Fix LRO header model validation (Azure#22506) * Add new status code for application gateway custom error page (Azure#22151) * Add new status code for application gateway custom error page * Fix prettier * Adding words to Custom-Words list * Fix missing resource id in application gateway list example (Azure#22509) * Resolving merge conflicts with main branch --------- Co-authored-by: Mikhail <mitryakh@microsoft.com> Co-authored-by: KRISHNA MISHRA <krishmi139@gmail.com> Co-authored-by: Krishna Mishra <krmishr@microsoft.com> Co-authored-by: Khushboo Baheti <37917868+Khushboo-Baheti@users.noreply.github.com> Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> Co-authored-by: utbarn-ms <66377251+utbarn-ms@users.noreply.github.com> Co-authored-by: tejasshah7 <49326906+tejasshah7@users.noreply.github.com> Co-authored-by: Prateek Sachan <42961174+prateek2211@users.noreply.github.com>
Networking 2022-09-01 release (Azure#22639) * Adds base for updating Microsoft.Network from version stable/2022-07-01 to version 2022-09-01 * Updates readme * Updates API version in new specs and examples * Added flowlog property in virtual network (Azure#21790) Co-authored-by: Krishna Mishra <krmishr@microsoft.com> * commit1 (Azure#22111) Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> * adding auth status property to circuit (Azure#22024) * Make auth status readonly (Azure#22365) * make auth status read only * fixing model validation * prettier fix * Add support for State flag in Custom Rule (Azure#22457) * Fix LRO header model validation (Azure#22506) * Add new status code for application gateway custom error page (Azure#22151) * Add new status code for application gateway custom error page * Fix prettier * Adding words to Custom-Words list * Fix missing resource id in application gateway list example (Azure#22509) * Resolving merge conflicts with main branch --------- Co-authored-by: Mikhail <mitryakh@microsoft.com> Co-authored-by: KRISHNA MISHRA <krishmi139@gmail.com> Co-authored-by: Krishna Mishra <krmishr@microsoft.com> Co-authored-by: Khushboo Baheti <37917868+Khushboo-Baheti@users.noreply.github.com> Co-authored-by: Khushboo Baheti <khbaheti@microsoft.com> Co-authored-by: utbarn-ms <66377251+utbarn-ms@users.noreply.github.com> Co-authored-by: tejasshah7 <49326906+tejasshah7@users.noreply.github.com> Co-authored-by: Prateek Sachan <42961174+prateek2211@users.noreply.github.com>
Part of #21509.
The service allows sending
null
during an Update operation to reset a property to its default value. So an Update has the three possible scenarios for each property:CodeGen does not support this differentiation. Currently, our code only supports the first two scenarios. If a property is null, we'll simply not send it. This prevents users from resetting settings to default but, most important, it prevents users from removing configurations. For example, we have the following class in one of our configuration APIs:
Each property adds a new behavior to the configuration. You need to specify at least one of them, and both can be set for the same config. Let's say the customer does not want to use the
HardThresholdCondition
anymore. Naturally, they would do:However, since CodeGen does not send the property when it's null, we're not sending anything to the service, and they have no way of knowing we want to remove this behavior.
This PR fixes this behavior for Data Feeds only (next PRs will contain other classes). Implementation details explained in the comments.