diff --git a/src/SlimData/SlimData.csproj b/src/SlimData/SlimData.csproj index 6fb71be3..df9d9e31 100644 --- a/src/SlimData/SlimData.csproj +++ b/src/SlimData/SlimData.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/SlimData/SlimPersistentState.cs b/src/SlimData/SlimPersistentState.cs index 07d9db64..9a0a56c6 100644 --- a/src/SlimData/SlimPersistentState.cs +++ b/src/SlimData/SlimPersistentState.cs @@ -17,7 +17,7 @@ public sealed class SlimPersistentState : MemoryBasedStateMachine, ISupplier ticksMemory) { + logger.LogInformation("HistorySynchronizationWorker: Synchronizing history for {Function} to {Ticks} from Database", function.Deployment, ticksInDatabase); historyHttpMemoryService.SetTickLastCall(function.Deployment, ticksInDatabase); } else if (ticksInDatabase < ticksMemory) { + logger.LogInformation("HistorySynchronizationWorker: Synchronizing history for {Function} to {Ticks} from Memory", function.Deployment, ticksMemory); await historyHttpDatabaseService.SetTickLastCallAsync(function.Deployment, ticksMemory); } } diff --git a/src/SlimFaas/Kubernetes/KubernetesService.cs b/src/SlimFaas/Kubernetes/KubernetesService.cs index 0436683b..96f105b5 100644 --- a/src/SlimFaas/Kubernetes/KubernetesService.cs +++ b/src/SlimFaas/Kubernetes/KubernetesService.cs @@ -67,7 +67,8 @@ public record DeploymentInformation(string Deployment, string Namespace, IList

? SubscribeEvents = null, FunctionVisibility Visibility = FunctionVisibility.Public, IList? PathsStartWithVisibility = null, - IList? ExcludeDeploymentsFromVisibilityPrivate = null + IList? ExcludeDeploymentsFromVisibilityPrivate = null, + string ResourceVersion = "" ); public record PodInformation(string Name, bool? Started, bool? Ready, string Ip, string DeploymentName); @@ -249,7 +250,8 @@ private static void AddDeployments(string kubeNamespace, V1DeploymentList deploy annotations.TryGetValue(PathsStartWithVisibility, out string? valueUrlsStartWithVisibility) ? valueUrlsStartWithVisibility.Split(',').ToList() : new List(), - annotations.TryGetValue(ExcludeDeploymentsFromVisibilityPrivate, out string? valueExcludeDeploymentsFromVisibilityPrivate) ? valueExcludeDeploymentsFromVisibilityPrivate.Split(',').ToList() : new List() + annotations.TryGetValue(ExcludeDeploymentsFromVisibilityPrivate, out string? valueExcludeDeploymentsFromVisibilityPrivate) ? valueExcludeDeploymentsFromVisibilityPrivate.Split(',').ToList() : new List(), + deploymentListItem.Metadata.ResourceVersion ); deploymentInformationList.Add(deploymentInformation); } @@ -323,7 +325,11 @@ private static void AddStatefulSets(string kubeNamespace, V1StatefulSetList depl annotations.TryGetValue(DefaultVisibility, out string? visibility) ? Enum.Parse(visibility) : FunctionVisibility.Public, - annotations.TryGetValue(ExcludeDeploymentsFromVisibilityPrivate, out string? valueExcludeDeploymentsFromVisibilityPrivate) ? valueExcludeDeploymentsFromVisibilityPrivate.Split(',').ToList() : new List()); + annotations.TryGetValue(PathsStartWithVisibility, out string? valueUrlsStartWithVisibility) + ? valueUrlsStartWithVisibility.Split(',').ToList() + : new List(), + annotations.TryGetValue(ExcludeDeploymentsFromVisibilityPrivate, out string? valueExcludeDeploymentsFromVisibilityPrivate) ? valueExcludeDeploymentsFromVisibilityPrivate.Split(',').ToList() : new List(), + deploymentListItem.Metadata.ResourceVersion); deploymentInformationList.Add(deploymentInformation); } diff --git a/src/SlimFaas/ReplicasService.cs b/src/SlimFaas/ReplicasService.cs index ca894970..8ce4562e 100644 --- a/src/SlimFaas/ReplicasService.cs +++ b/src/SlimFaas/ReplicasService.cs @@ -53,6 +53,35 @@ public async Task SyncDeploymentsAsync(string kubeNames DeploymentsInformations deployments = await kubernetesService.ListFunctionsAsync(kubeNamespace); lock (Lock) { + if (logger.IsEnabled(LogLevel.Information)) + { + foreach (DeploymentInformation deploymentInformation in deployments.Functions) + { + var currentDeployment = _deployments.Functions.FirstOrDefault(f => + f.Deployment == deploymentInformation.Deployment && + f.ResourceVersion == deploymentInformation.ResourceVersion); + if (currentDeployment == null) + { + // Un log information avec toutes les informations de toutes les propriété de la fonction + logger.LogInformation("New deployment {Deployment} \n" + + "with {Replicas} replicas \n" + + "with {ReplicasAtStart} replicas at start \n" + + "with {ReplicasMin} replicas min \n" + + "with {ReplicasStartAsSoonAsOneFunctionRetrieveARequest} replicas start as soon as one function retrieve a request \n" + + "with {TimeoutSecondBeforeSetReplicasMin} timeout second before set replicas min \n" + + "with {PodType} pod type \n" + + "with {ResourceVersion} resource version \n"+ + "with {NumberParallelRequest} number parallel request \n", + deploymentInformation.Deployment, deploymentInformation.Replicas, deploymentInformation.ReplicasAtStart, deploymentInformation.ReplicasMin, + deploymentInformation.ReplicasStartAsSoonAsOneFunctionRetrieveARequest, deploymentInformation.TimeoutSecondBeforeSetReplicasMin, + deploymentInformation.PodType, deploymentInformation.ResourceVersion, deploymentInformation.NumberParallelRequest); + + } + } + + } + + _deployments = deployments; } return deployments; @@ -101,7 +130,6 @@ public async Task CheckScaleAsync(string kubeNamespace) TimeSpan.FromSeconds(GetTimeoutSecondBeforeSetReplicasMin(deploymentInformation, DateTime.UtcNow)) < TimeSpan.FromTicks(DateTime.UtcNow.Ticks); int currentScale = deploymentInformation.Replicas; - if (timeElapsedWithoutRequest) { if (currentScale <= deploymentInformation.ReplicasMin) @@ -109,6 +137,7 @@ public async Task CheckScaleAsync(string kubeNamespace) continue; } + logger.LogInformation("Scale down {Deployment} from {currentScale} to {ReplicasMin}", deploymentInformation.Deployment, currentScale, deploymentInformation.ReplicasMin); Task task = kubernetesService.ScaleAsync(new ReplicaRequest( Replicas: deploymentInformation.ReplicasMin, Deployment: deploymentInformation.Deployment, @@ -118,8 +147,9 @@ public async Task CheckScaleAsync(string kubeNamespace) tasks.Add(task); } - else if (currentScale is 0 && DependsOnReady(deploymentInformation)) + else if ((currentScale is 0 || currentScale < deploymentInformation.ReplicasMin) && DependsOnReady(deploymentInformation)) { + logger.LogInformation("Scale up {Deployment} from {currentScale} to {Replica at start}", deploymentInformation.Deployment, currentScale, deploymentInformation.ReplicasAtStart); Task task = kubernetesService.ScaleAsync(new ReplicaRequest( Replicas: deploymentInformation.ReplicasAtStart, Deployment: deploymentInformation.Deployment, diff --git a/src/SlimFaas/SlimProxyMiddleware.cs b/src/SlimFaas/SlimProxyMiddleware.cs index 6bf74ef2..82f0bff4 100644 --- a/src/SlimFaas/SlimProxyMiddleware.cs +++ b/src/SlimFaas/SlimProxyMiddleware.cs @@ -299,22 +299,29 @@ private async Task BuildPublishResponseAsync(HttpContext context, HistoryHttpMem var slimFaasSubscribeEvents = _slimFaasSubscribeEvents.Where(s => s.Key == eventName); if (functions.Count <= 0 && !slimFaasSubscribeEvents.Any()) { - logger.LogDebug("Return 404 from event: {EventName}", eventName); + logger.LogDebug("Publish-event {EventName} : Return 404 from event", eventName); context.Response.StatusCode = 404; return; } var lastSetTicks = DateTime.UtcNow.Ticks; + List calledFunctions = new(); + List> tasks = new(); foreach (DeploymentInformation function in functions) { foreach (var pod in function.Pods) { - logger.LogDebug("Pod {PodName} is ready: {PodReady}", pod.Name, pod.Ready); - if (pod.Ready != true) + if (pod.Ready is not true) { continue; } + + if (!calledFunctions.Contains(function)) + { + calledFunctions.Add(function); + } + logger.LogInformation("Publish-event {EventName} : Deployment {Deployment} Pod {PodName} is ready: {PodReady}", eventName, function.Deployment, pod.Name, pod.Ready); historyHttpService.SetTickLastCall(function.Deployment, lastSetTicks); string baseFunctionPodUrl = @@ -350,7 +357,7 @@ private async Task BuildPublishResponseAsync(HttpContext context, HistoryHttpMem } lastSetTicks = DateTime.UtcNow.Ticks; - foreach (DeploymentInformation function in functions) + foreach (DeploymentInformation function in calledFunctions) { historyHttpService.SetTickLastCall(function.Deployment, lastSetTicks); } diff --git a/src/SlimFaas/appsettings.json b/src/SlimFaas/appsettings.json index 443523a9..440bfff7 100644 --- a/src/SlimFaas/appsettings.json +++ b/src/SlimFaas/appsettings.json @@ -5,7 +5,7 @@ "Microsoft.AspNetCore": "Error", "DotNext.Net.Cluster": "Error", "SlimData": "Error", - "SlimFaas": "Error" + "SlimFaas": "Information" } }, "UseKubeConfig": false, diff --git a/tests/SlimData.Tests/SlimData.Tests.csproj b/tests/SlimData.Tests/SlimData.Tests.csproj index d6b9d79b..3706635b 100644 --- a/tests/SlimData.Tests/SlimData.Tests.csproj +++ b/tests/SlimData.Tests/SlimData.Tests.csproj @@ -17,7 +17,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive