Skip to content

Commit

Permalink
Cleaned up logging. Reverted ReadyToRun setting on .Server and .Actor…
Browse files Browse the repository at this point in the history
…s to cut build time.
  • Loading branch information
ScottArbeit committed Oct 28, 2023
1 parent 0c0b5bb commit c69e60a
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:

jobs:
build:
runs-on: arc-runner-set
#runs-on: arc-runner-set
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
Expand Down
13 changes: 8 additions & 5 deletions src/Grace.Actors/Branch.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ module Branch =
}

override this.OnActivateAsync() =
let activateStartTime = getCurrentInstant()
let stateManager = this.StateManager
log.LogInformation($"{getCurrentInstantExtended()} Activated BranchActor {host.Id}.")
task {
let! retrievedDto = Storage.RetrieveState<BranchDto> stateManager dtoStateName
match retrievedDto with
| Some retrievedDto -> branchDto <- retrievedDto
| None -> branchDto <- BranchDto.Default

let duration = getCurrentInstant().Minus(activateStartTime)
log.LogInformation("{CurrentInstant}: Activated {ActorType} {ActorId}. Retrieved from storage in {duration}ms.", getCurrentInstantExtended(), actorName, host.Id, duration.TotalMilliseconds.ToString("F3"))
} :> Task

member private this.SetMaintenanceReminder() =
Expand All @@ -115,7 +118,7 @@ module Branch =
actorStartTime <- getCurrentInstant()
logScope <- log.BeginScope("Actor {actorName}", actorName)
currentCommand <- String.Empty
//log.LogInformation("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId())
//log.LogInformation("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id)

// This checks if the actor is still active, but in an undefined state, which will _almost_ never happen.
// isDisposed is set when the actor is deleted, or if an error occurs where we're not sure of the state and want to reload from the database.
Expand All @@ -126,11 +129,11 @@ module Branch =
Task.CompletedTask

override this.OnPostActorMethodAsync(context) =
let duration = getCurrentInstant().Minus(actorStartTime)
let durationμs = (getCurrentInstant().Minus(actorStartTime).TotalMilliseconds * 1000.0).ToString("F0")
if String.IsNullOrEmpty(currentCommand) then
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Id: {Id}; Duration: {duration}ms.", $"{getCurrentInstantExtended(),-28}", actorName, context.MethodName, this.Id.GetId(), duration.TotalMilliseconds.ToString("F3"))
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Id: {Id}; Duration: {duration}μs.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id, durationμs)
else
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Command: {Command}; Id: {Id}; Duration: {duration}ms.", $"{getCurrentInstantExtended(),-28}", actorName, context.MethodName, currentCommand, this.Id.GetId(), duration.TotalMilliseconds.ToString("F3"))
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Command: {Command}; Id: {Id}; Duration: {duration}μs.", getCurrentInstantExtended(), actorName, context.MethodName, currentCommand, this.Id, durationμs)
logScope.Dispose()
Task.CompletedTask

Expand Down
6 changes: 3 additions & 3 deletions src/Grace.Actors/BranchName.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ module BranchName =
override this.OnPreActorMethodAsync(context) =
actorStartTime <- getCurrentInstant()
logScope <- log.BeginScope("Actor {actorName}", actorName)
//log.LogInformation("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId())
log.LogTrace("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id)
Task.CompletedTask

override this.OnPostActorMethodAsync(context) =
let duration = getCurrentInstant().Minus(actorStartTime)
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName} Id: {Id}; Duration: {duration}ms.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId(), duration.TotalMilliseconds.ToString("F3"))
let durationμs = (getCurrentInstant().Minus(actorStartTime).TotalMilliseconds * 1000.0).ToString("F0")
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Id: {Id}; Duration: {duration}μs.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id, durationμs)
logScope.Dispose()
Task.CompletedTask

Expand Down
11 changes: 7 additions & 4 deletions src/Grace.Actors/Diff.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,27 @@ module Diff =
task.Wait()

override this.OnActivateAsync() =
let activateStartTime = getCurrentInstant()
let stateManager = this.StateManager
log.LogInformation("{CurrentInstant}: Activated {ActorType} {ActorId}.", getCurrentInstantExtended(), this.GetType().Name, host.Id)
task {
let! retrievedDto = Storage.RetrieveState<DiffDto> stateManager dtoStateName
match retrievedDto with
| Some retrievedDto -> diffDto <- retrievedDto
| None -> diffDto <- DiffDto.Default

let duration = getCurrentInstant().Minus(activateStartTime)
log.LogInformation("{CurrentInstant}: Activated {ActorType} {ActorId}. Retrieved from storage in {duration}ms.", getCurrentInstantExtended(), actorName, host.Id, duration.TotalMilliseconds.ToString("F3"))
} :> Task

override this.OnPreActorMethodAsync(context) =
actorStartTime <- getCurrentInstant()
logScope <- log.BeginScope("Actor {actorName}", actorName)
//log.LogInformation("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId())
//log.LogInformation("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id)
Task.CompletedTask

override this.OnPostActorMethodAsync(context) =
let duration = getCurrentInstant().Minus(actorStartTime)
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName} Id: {Id}; Duration: {duration}ms.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId(), duration.TotalMilliseconds.ToString("F3"))
let durationμs = (getCurrentInstant().Minus(actorStartTime).TotalMilliseconds * 1000.0).ToString("F0")
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Id: {Id}; Duration: {duration}μs.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id, durationμs)
logScope.Dispose()
Task.CompletedTask

Expand Down
15 changes: 9 additions & 6 deletions src/Grace.Actors/DirectoryVersion.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ module DirectoryVersion =
let mutable logScope: IDisposable = null

override this.OnActivateAsync() =
let activateStartTime = getCurrentInstant()
let stateManager = this.StateManager
log.LogInformation("{CurrentInstant} Activated {ActorType} {ActorId}.", getCurrentInstantExtended(), this.GetType().Name, host.Id)
task {
try
let! retrievedDto = Storage.RetrieveState<DirectoryVersion> stateManager dtoStateName
Expand All @@ -49,17 +49,20 @@ module DirectoryVersion =
let exc = createExceptionResponse ex
log.LogError("{CurrentInstant} Error in {ActorType} {ActorId}.", getCurrentInstantExtended(), this.GetType().Name, host.Id)
log.LogError("{CurrentInstant} {ExceptionDetails}", getCurrentInstantExtended(), exc.ToString())

let duration = getCurrentInstant().Minus(activateStartTime)
log.LogInformation("{CurrentInstant}: Activated {ActorType} {ActorId}. Retrieved from storage in {duration}ms.", getCurrentInstantExtended(), actorName, host.Id, duration.TotalMilliseconds.ToString("F3"))
} :> Task

override this.OnPreActorMethodAsync(context) =
actorStartTime <- getCurrentInstant()
logScope <- log.BeginScope("Actor {actorName}", actorName)
//log.LogInformation("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId())
log.LogTrace("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id)
Task.CompletedTask

override this.OnPostActorMethodAsync(context) =
let duration = getCurrentInstant().Minus(actorStartTime)
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName} Id: {Id}; Duration: {duration}ms.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId(), duration.TotalMilliseconds.ToString("F3"))
let durationμs = (getCurrentInstant().Minus(actorStartTime).TotalMilliseconds * 1000.0).ToString("F0")
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Id: {Id}; Duration: {duration}μs.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id, durationμs)
logScope.Dispose()
Task.CompletedTask

Expand Down Expand Up @@ -136,10 +139,10 @@ module DirectoryVersion =
//let cachedSubdirectoryVersions = None
match cachedSubdirectoryVersions with
| Some subdirectoryVersions ->
logToConsole $"In DirectoryVersionActor.GetDirectoryVersionsRecursive({this.Id.GetId()}). SubdirectoryVersions already cached."
logToConsole $"In DirectoryVersionActor.GetDirectoryVersionsRecursive({this.Id}). SubdirectoryVersions already cached."
return subdirectoryVersions
| None ->
logToConsole $"In DirectoryVersionActor.GetDirectoryVersionsRecursive({this.Id.GetId()}). SubdirectoryVersions not cached; generating the list."
logToConsole $"In DirectoryVersionActor.GetDirectoryVersionsRecursive({this.Id}). SubdirectoryVersions not cached; generating the list."
let subdirectoryVersions = ConcurrentQueue<DirectoryVersion>()
subdirectoryVersions.Enqueue(directoryVersion)
do! Parallel.ForEachAsync(directoryVersion.Directories, Constants.ParallelOptions, (fun directoryId ct ->
Expand Down
2 changes: 1 addition & 1 deletion src/Grace.Actors/Grace.Actors.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<WarningsAsErrors>FS0025</WarningsAsErrors>
<NoWarn>1057</NoWarn>
<Platforms>AnyCPU;x64</Platforms>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 10 additions & 8 deletions src/Grace.Actors/Organization.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ module Organization =

let GetActorId (organizationId: OrganizationId) = ActorId($"{organizationId}")

type OrganizationActor(host: ActorHost) as this =
type OrganizationActor(host: ActorHost) =
inherit Actor(host)

let actorName = ActorName.Organization
let log = this.Logger
let log = host.LoggerFactory.CreateLogger(actorName)
let mutable actorStartTime = Instant.MinValue
let mutable logScope: IDisposable = null
let mutable currentCommand = String.Empty
Expand Down Expand Up @@ -63,13 +63,16 @@ module Organization =
{newOrganizationDto with UpdatedAt = Some (getCurrentInstant())}

override this.OnActivateAsync() =
let activateStartTime = getCurrentInstant()
let stateManager = this.StateManager
log.LogInformation("{CurrentInstant} Activated {ActorType} {ActorId}.", getCurrentInstantExtended(), this.GetType().Name, host.Id)
task {
let! retrievedDto = Storage.RetrieveState<OrganizationDto> stateManager dtoStateName
match retrievedDto with
| Some retrievedDto -> organizationDto <- retrievedDto
| None -> organizationDto <- OrganizationDto.Default

let duration = getCurrentInstant().Minus(activateStartTime)
log.LogInformation("{CurrentInstant}: Activated {ActorType} {ActorId}. Retrieved from storage in {duration}ms.", getCurrentInstantExtended(), actorName, host.Id, duration.TotalMilliseconds.ToString("F3"))
} :> Task

member private this.SetMaintenanceReminder() =
Expand All @@ -88,22 +91,21 @@ module Organization =
actorStartTime <- getCurrentInstant()
logScope <- log.BeginScope("Actor {actorName}", actorName)
currentCommand <- String.Empty
//log.LogInformation("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId())
log.LogTrace("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id)

// This checks if the actor is still active, but in an undefined state, which will _almost_ never happen.
// isDisposed is set when the actor is deleted, or if an error occurs where we're not sure of the state and want to reload from the database.
if isDisposed then
this.OnActivateAsync().Wait()
isDisposed <- false

Task.CompletedTask

override this.OnPostActorMethodAsync(context) =
let duration = getCurrentInstant().Minus(actorStartTime)
let durationμs = (getCurrentInstant().Minus(actorStartTime).TotalMilliseconds * 1000.0).ToString("F0")
if String.IsNullOrEmpty(currentCommand) then
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Id: {Id}; Duration: {duration}ms.", $"{getCurrentInstantExtended(),-28}", actorName, context.MethodName, this.Id.GetId(), duration.TotalMilliseconds.ToString("F3"))
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Id: {Id}; Duration: {duration}μs.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id, durationμs)
else
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Command: {Command}; Id: {Id}; Duration: {duration}ms.", $"{getCurrentInstantExtended(),-28}", actorName, context.MethodName, currentCommand, this.Id.GetId(), duration.TotalMilliseconds.ToString("F3"))
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Command: {Command}; Id: {Id}; Duration: {duration}μs.", getCurrentInstantExtended(), actorName, context.MethodName, currentCommand, this.Id, durationμs)
logScope.Dispose()
Task.CompletedTask

Expand Down
6 changes: 3 additions & 3 deletions src/Grace.Actors/OrganizationName.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ module OrganizationName =
override this.OnPreActorMethodAsync(context) =
actorStartTime <- getCurrentInstant()
logScope <- log.BeginScope("Actor {actorName}", actorName)
//log.LogInformation("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId())
log.LogTrace("{CurrentInstant}: Started {ActorName}.{MethodName} Id: {Id}.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id)
Task.CompletedTask

override this.OnPostActorMethodAsync(context) =
let duration = getCurrentInstant().Minus(actorStartTime)
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName} Id: {Id}; Duration: {duration}ms.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id.GetId(), duration.TotalMilliseconds.ToString("F3"))
let durationμs = (getCurrentInstant().Minus(actorStartTime).TotalMilliseconds * 1000.0).ToString("F0")
log.LogInformation("{CurrentInstant}: Finished {ActorName}.{MethodName}; Id: {Id}; Duration: {duration}μs.", getCurrentInstantExtended(), actorName, context.MethodName, this.Id, durationμs)
logScope.Dispose()
Task.CompletedTask

Expand Down
Loading

0 comments on commit c69e60a

Please sign in to comment.