Skip to content

Revise EntityInstanceId implementation and add checking#205

Merged
sebastianburckhardt merged 5 commits intofeature/entitiesfrom
core-entities/entity-instance-id-normalization
Oct 9, 2023
Merged

Revise EntityInstanceId implementation and add checking#205
sebastianburckhardt merged 5 commits intofeature/entitiesfrom
core-entities/entity-instance-id-normalization

Conversation

@sebastianburckhardt
Copy link
Member

Changes to EntityInstanceId:

  • check non-null and non-empty
  • normalize name
  • support FromString
  • add custom JsonConverter

Changes to parameter checking throughout:

  • add checks where we do NOT expect entity ids to be passed in
  • add not-default-checks where the passed-in entities could be invalid

@sebastianburckhardt sebastianburckhardt added P1 durable-entities Related to the Durable Entities support milestone labels Oct 5, 2023
Copy link
Member

@jviau jviau left a comment

Choose a reason for hiding this comment

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

The Check.NotEntity addition is a behavior breaking change. We should discuss what impact this is to customers and if we have any alternatives.

/// </summary>
/// <param name="instanceId">The string representation of the entity ID.</param>
/// <returns>the constructed entity instance ID.</returns>
public static EntityInstanceId FromString(string instanceId)
Copy link
Member

Choose a reason for hiding this comment

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

nit: put static methods before instance.

public SubOrchestrationOptions(TaskRetryOptions? retry = null, string? instanceId = null)
: base(retry)
{
Check.NotEntity(instanceId);
Copy link
Member

Choose a reason for hiding this comment

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

This is a behavior breaking change. Customers scheduling orchestrations with @ before no longer can.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. Note that it does not break just because of this check. The backend also treats '@' instance ids differently. So the check is actually necessary for giving good error messages as opposed to mysterious internal errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we want to support an 'entity-opt-out' switch?

Copy link
Member

Choose a reason for hiding this comment

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

I suppose we could - would be a good use of AppContext. Default is opted in, add way to opt out.

/// Gets or sets a value indicating whether this client supports entities. If true, all instance ids starting with '@' are reserved for entities,
/// and validation checks are performed where appropriate.
/// </summary>
public bool SupportEntities { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of EnableEntitySupport?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, slightly better I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have changed it for both DurableTaskClientOptions and DurableTaskWorkerOptions.

{
if (argument?.Length > 0 && argument[0] == '@')
{
throw new ArgumentException("Parameter cannot be an entity instance id", name);
Copy link
Member

Choose a reason for hiding this comment

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

nit: should clarify what entity instance ID means:

Orchestration instance IDs cannot start '@' when entity support is enabled. '@' is reserved for entities. Instance ID: '{argument}'.

public override async Task<OrchestrationMetadata> WaitForInstanceStartAsync(
string instanceId, bool getInputsAndOutputs = false, CancellationToken cancellation = default)
{
if (this.options.SupportEntities)
Copy link
Member

Choose a reason for hiding this comment

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

Recommend add a helper to the options object:

internal void CheckNotEntity(string instanceId)
{
    if (this.SupportEntities)
    {
        Check.NotEntity(instanceId);
    }
}

Then all other calls can be this.options.CheckNotEntity(instanceId);

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I also have to add the [CallerArgumentExpression("argument")] string? name = default for the magic of compiler-generated argument descriptor to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we need the same thing for DurableTaskWorkerOptions I am instead going to just pass in the EnableEntitySupport as a boolean argument to Check.NotEntity.

}
else
{
throw new NotSupportedException($"Durable entities are disabled because DurableTaskWorkerOptions.SupportEntities=false");
Copy link
Member

Choose a reason for hiding this comment

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

It is long and ugly, but will save from any renames:

Suggested change
throw new NotSupportedException($"Durable entities are disabled because DurableTaskWorkerOptions.SupportEntities=false");
throw new NotSupportedException($"Durable entities are disabled because {nameof(DurableTaskWorkerOptions)}.{nameof(DurableTaskWorkerOptions.SupportEntities)}=false");

@sebastianburckhardt sebastianburckhardt merged commit 195aa61 into feature/entities Oct 9, 2023
@sebastianburckhardt sebastianburckhardt deleted the core-entities/entity-instance-id-normalization branch October 9, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

durable-entities Related to the Durable Entities support milestone P1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants