Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ScottArbeit/Grace
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottArbeit committed Nov 9, 2023
2 parents ecf9952 + 04049af commit 76e370c
Show file tree
Hide file tree
Showing 69 changed files with 2,295 additions and 1,335 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ on:

jobs:
build:

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

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
include-prerelease: true
dotnet-version: 8.0.x
dotnet-quality: 'preview'
- name: Restore dependencies
run: dotnet restore Grace.sln
working-directory: src
Expand Down
9 changes: 5 additions & 4 deletions src/CosmosSerializer/CosmosJsonSerializer.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>1057</NoWarn>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.30.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.32.1" />
<PackageReference Include="Azure.Core" Version="1.35.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.36.0" />
</ItemGroup>

</Project>
10 changes: 7 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project>
<PropertyGroup>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
</PropertyGroup>
<PropertyGroup>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<!--<RuntimeIdentifier>linux-x64</RuntimeIdentifier>-->
<PublishProfile>DefaultContainer</PublishProfile>
<OtherFlags>$(OtherFlags) --test:GraphBasedChecking</OtherFlags>
</PropertyGroup>
</Project>
10 changes: 6 additions & 4 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

#FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base
# Using the SDK image as the base instead of the aspnet image lets us run a shell for debugging.
#FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 5000
EXPOSE 5001

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Grace.Server/Grace.Server.fsproj", "./Grace.Server/"]
COPY ["Grace.Actors/Grace.Actors.fsproj", "./Grace.Actors/"]
Expand All @@ -21,8 +22,9 @@ FROM build AS publish
RUN dotnet publish "Grace.Server.fsproj" -c Debug -o /app/publish /p:UseAppHost=false

# Set environment variables to configure ASP.NET Core to use the certificate
ENV ASPNETCORE_URLS="https://+;http://+"
#ENV ASPNETCORE_URLS="https://+;http://+"
ENV ASPNETCORE_HTTPS_PORT=5001
ENV ASPNETCORE_HTTP_PORT=5000
ENV DOTNET_GENERATE_ASPNET_CERTIFICATE=false

FROM base AS final
Expand Down
23 changes: 23 additions & 0 deletions src/Get-KubernetesSecret.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param (
[Parameter(Mandatory=$true)]
[string]$SecretName,

[Parameter(Mandatory=$false)]
[switch]$CreateCommand
)

# Get the secret from Kubernetes
$encodedSecret = kubectl get secret $SecretName -o jsonpath="{.data}"

# Decode the secret
$deserialized = $encodedSecret | ConvertFrom-Json

$decodedSecret = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($deserialized.$SecretName))

# Display the secret
$decodedSecret

# Create a command to set the secret
if ($CreateCommand) {
"kubectl create secret generic $SecretName --from-literal=$SecretName=""$decodedSecret"""
}
20 changes: 12 additions & 8 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,22 +118,21 @@ 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.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 Expand Up @@ -164,7 +166,9 @@ module Branch =
returnValue.Properties.Add(nameof(BranchId), $"{branchDto.BranchId}")
returnValue.Properties.Add(nameof(BranchName), $"{branchDto.BranchName}")
returnValue.Properties.Add("ParentBranchId", $"{branchDto.ParentBranchId}")
returnValue.Properties.Add("EventType", $"{discriminatedUnionFullNameToString branchEvent.Event}")
returnValue.Properties.Add("EventType", $"{getDiscriminatedUnionFullName branchEvent.Event}")

// If the event has a referenceId, add it to the return properties.
if branchEvent.Metadata.Properties.ContainsKey(nameof(ReferenceId)) then
returnValue.Properties.Add(nameof(ReferenceId), branchEvent.Metadata.Properties[nameof(ReferenceId)])
return Ok returnValue
Expand Down Expand Up @@ -283,7 +287,7 @@ module Branch =
}

task {
currentCommand <- discriminatedUnionCaseNameToString command
currentCommand <- getDistributedUnionCaseName command
match! isValid command metadata with
| Ok command -> return! processCommand command metadata
| Error error -> return Error error
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
4 changes: 2 additions & 2 deletions src/Grace.Actors/ContainerName.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ module ContainerName =

let organizationActorId = ActorId($"{repositoryDto.OrganizationId}")
let organizationActorProxy = this.ProxyFactory.CreateActorProxy<IOrganizationActor>(organizationActorId, ActorName.Organization)
let! organizationDto = organizationActorProxy.GetDto()
let! organizationDto = organizationActorProxy.Get()

let ownerActorId = ActorId($"{repositoryDto.OwnerId}")
let ownerActorProxy = this.ProxyFactory.CreateActorProxy<IOwnerActor>(ownerActorId, ActorName.Owner)
let! ownerDto = ownerActorProxy.GetDto()
let! ownerDto = ownerActorProxy.Get()

containerName <- $"{ownerDto.OwnerName}-{organizationDto.OrganizationName}-{repositoryDto.RepositoryName}".ToLowerInvariant()
return Ok containerName
Expand Down
13 changes: 8 additions & 5 deletions src/Grace.Actors/Diff.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module Diff =
member private this.buildGraceIndex (directoryId: DirectoryId) =
task {
let graceIndex = ServerGraceIndex()
let directory = this.ProxyFactory.CreateActorProxy<IDirectoryVersionActor>(Directory.GetActorId(directoryId), ActorName.DirectoryVersion)
let directory = this.ProxyFactory.CreateActorProxy<IDirectoryVersionActor>(DirectoryVersion.GetActorId(directoryId), ActorName.DirectoryVersion)
let! directoryCreatedAt = directory.GetCreatedAt()
let! directoryContents = directory.GetDirectoryVersionsRecursive()
//logToConsole $"In DiffActor.buildGraceIndex(): directoryContents.Count: {directoryContents.Count}"
Expand Down 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.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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ open System.Threading.Tasks
open System.Collections.Concurrent
open System.Diagnostics

module Directory =
module DirectoryVersion =

let GetActorId (directoryId: DirectoryId) = ActorId($"{directoryId}")

Expand All @@ -37,8 +37,8 @@ module Directory =
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 Directory =
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 Directory =
//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
Loading

0 comments on commit 76e370c

Please sign in to comment.