Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 additions & 4 deletions src/Client/Grpc/GrpcDurableEntityClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ public override async Task SignalEntityAsync(
RequestId = requestId.ToString(),
Name = operationName,
Input = this.dataConverter.Serialize(input),
ScheduledTime = scheduledTime?.ToTimestamp(),
ScheduledTime = scheduledTime?.ToTimestamp(),
RequestTime = DateTimeOffset.UtcNow.ToTimestamp(),
};
};

if (Activity.Current is { } activity)
{
request.ParentTraceContext ??= new P.TraceContext();
request.ParentTraceContext.TraceParent = activity.Id;
request.ParentTraceContext.TraceState = activity.TraceStateString;
}

// TODO this.logger.LogSomething
this.logger.SignalingEntity(id.ToString(), operationName);
try
{
await this.sidecarClient.SignalEntityAsync(request, cancellationToken: cancellation);
Expand Down Expand Up @@ -107,6 +107,7 @@ public override async Task<CleanEntityStorageResult> CleanEntityStorageAsync(
int emptyEntitiesRemoved = 0;
int orphanedLocksReleased = 0;

this.logger.CleaningEntityStorage();
try
{
do
Expand Down Expand Up @@ -156,6 +157,7 @@ public override async Task<CleanEntityStorageResult> CleanEntityStorageAsync(
IncludeState = includeState,
};

this.logger.GettingEntity(id.ToString());
try
{
P.GetEntityResponse response = await this.sidecarClient
Expand All @@ -180,6 +182,7 @@ AsyncPageable<TMetadata> GetAllEntitiesCoreAsync<TMetadata>(
DateTimeOffset? lastModifiedFrom = filter?.LastModifiedFrom;
DateTimeOffset? lastModifiedTo = filter?.LastModifiedTo;

this.logger.QueryingEntities(startsWith, lastModifiedFrom, lastModifiedTo);
return Pageable.Create(async (continuation, pageSize, cancellation) =>
{
pageSize ??= filter?.PageSize;
Expand Down
12 changes: 12 additions & 0 deletions src/Client/Grpc/Logs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ static partial class Logs
[LoggerMessage(EventId = 46, Level = LogLevel.Information, Message = "Purging instances with filter: {{ CreatedFrom = {createdFrom}, CreatedTo = {createdTo}, Statuses = {statuses} }}")]
public static partial void PurgingInstances(this ILogger logger, DateTimeOffset? createdFrom, DateTimeOffset? createdTo, string? statuses);

[LoggerMessage(EventId = 47, Level = LogLevel.Information, Message = "Signaling entity '{instanceId}' with operation '{operationName}'.")]
public static partial void SignalingEntity(this ILogger logger, string instanceId, string operationName);

[LoggerMessage(EventId = 48, Level = LogLevel.Information, Message = "Getting entity '{instanceId}'.")]
public static partial void GettingEntity(this ILogger logger, string instanceId);

[LoggerMessage(EventId = 49, Level = LogLevel.Information, Message = "Querying entities with filter: {{ StartsWith = {startsWith}, LastModifiedFrom = {lastModifiedFrom}, LastModifiedTo = {lastModifiedTo} }}")]
public static partial void QueryingEntities(this ILogger logger, string? startsWith, DateTimeOffset? lastModifiedFrom, DateTimeOffset? lastModifiedTo);

[LoggerMessage(EventId = 50, Level = LogLevel.Information, Message = "Cleaning entity storage.")]
public static partial void CleaningEntityStorage(this ILogger logger);

/// <summary>
/// <see cref="PurgingInstances(ILogger, DateTimeOffset?, DateTimeOffset?, string?)" />.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Licensed under the MIT License.

using Microsoft.DurableTask.Entities;
using Microsoft.Extensions.Logging;

namespace Microsoft.DurableTask.ScheduledTasks;

// TODO: logging
// TODO: May need separate orchs, result is obj now

/// <summary>
Expand All @@ -18,7 +18,22 @@ public class ExecuteScheduleOperationOrchestrator : TaskOrchestrator<ScheduleOpe
/// <inheritdoc/>
public override async Task<object> RunAsync(TaskOrchestrationContext context, ScheduleOperationRequest input)
{
return await context.Entities.CallEntityAsync<object>(input.EntityId, input.OperationName, input.Input);
ILogger logger = context.CreateReplaySafeLogger<ExecuteScheduleOperationOrchestrator>();
string scheduleId = input.EntityId.Key;

logger.ScheduleOperationInfo(scheduleId, input.OperationName, "Executing schedule operation via orchestrator");

try
{
object result = await context.Entities.CallEntityAsync<object>(input.EntityId, input.OperationName, input.Input);
logger.ScheduleOperationInfo(scheduleId, input.OperationName, "Schedule operation completed successfully");
return result;
}
catch (Exception ex)
{
logger.ScheduleOperationError(scheduleId, input.OperationName, "Failed to execute schedule operation via orchestrator", ex);
throw;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.DurableTask.Client;
using Microsoft.DurableTask.Client.Entities;
using Microsoft.DurableTask.Entities;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

Expand All @@ -20,6 +21,9 @@ public ExecuteScheduleOperationOrchestratorTests()
this.mockContext = new Mock<TaskOrchestrationContext>(MockBehavior.Strict);
this.mockEntityClient = new Mock<TaskOrchestrationEntityFeature>(MockBehavior.Loose);
this.mockContext.Setup(c => c.Entities).Returns(this.mockEntityClient.Object);
this.mockContext
.Setup(c => c.CreateReplaySafeLogger<ExecuteScheduleOperationOrchestrator>())
.Returns(NullLogger.Instance);
this.orchestrator = new ExecuteScheduleOperationOrchestrator();
}

Expand Down
Loading