-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(slimfaas): call only at least when one pod is read #19
Conversation
please squash or rewrite the git history when time to merge comes. |
@@ -18,7 +18,7 @@ public class HistorySynchronizationWorker: BackgroundService | |||
_historyHttpMemoryService = historyHttpMemoryService; | |||
_historyHttpRedisService = historyHttpRedisService; | |||
_logger = logger; | |||
_delay = delay; | |||
_delay = int.Parse(Environment.GetEnvironmentVariable("HISTORY_SYNCHRONISATION_WORKER_DELAY_MILLISECONDS") ?? delay.ToString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't int.Parse throwing with null or empty values ? i would sugget using TryParse here
@@ -56,13 +65,13 @@ public KubernetesService(IConfiguration config, ILogger<KubernetesService> logge | |||
try | |||
{ | |||
using var client = new Kubernetes(_k8SConfig); | |||
var patchString = "{\"spec\": {\"replicas\": " + request.Replicas + "}}"; | |||
var patchString = $"{{\"spec\": {{\"replicas\": {request?.Replicas}}}}}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if request is null it will output null
in the json string
var patch = new V1Patch(patchString, V1Patch.PatchType.MergePatch); | ||
await client.PatchNamespacedDeploymentScaleAsync(patch, request.Deployment, request.Namespace); | ||
await client.PatchNamespacedDeploymentScaleAsync(patch, request?.Deployment, request?.Namespace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should client.PatchNamespacedDeploymentScaleAsync
be called when request is null ?
@@ -142,4 +157,43 @@ public async Task<DeploymentsInformations> ListFunctionsAsync(string kubeNamespa | |||
} | |||
} | |||
|
|||
private static IList<PodInformation> MapPodInformations(V1PodList list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we could return IEnumerable and yield return filetred results. The caller would call .ToList to get the List already filtered
@@ -27,6 +28,7 @@ public record DeploymentsInformations | |||
public record DeploymentInformation | |||
{ | |||
public string Deployment { get; set; } | |||
public IList<PodInformation>? Pods { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should enable add <WarningsAsErrors>Nullable</WarningsAsErrors>
in csproj files to enforce correct usage/handling of NRT
SonarCloud Quality Gate failed.
|
Pour le merge je ferais un squash merge |
src/SlimFaas/EnvironmentVariables.cs
Outdated
public static class EnvironmentVariables | ||
{ | ||
|
||
public static int ReadInteger<T>(ILogger<T> logger, string environmentVariableName, int defaultDelay) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultDelay => defaultValue
src/SlimFaas/EnvironmentVariables.cs
Outdated
public static class EnvironmentVariables | ||
{ | ||
|
||
public static int ReadInteger<T>(ILogger<T> logger, string environmentVariableName, int defaultDelay) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks strange to pass ILogger here. I would suggest something like
TryReadInteger(string environmentVariable, out int value).
The caller would interpret a false result to apply the correct default value and use its own ILogger instance.
src/SlimFaas/ReplicasService.cs
Outdated
foreach (var function in Deployments.Functions) | ||
{ | ||
var updatedFunction = tasks.FirstOrDefault(t => t.Result.Deployment == function.Deployment); | ||
updatedFunctions.Add(function with { Replicas = updatedFunction != null ? updatedFunction.Result.Replicas : function.Replicas }); | ||
var updatedFunction = tasks.Find(t => t.Result?.Deployment == function.Deployment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this foreach loop .Result
Task property is accessed. The may cause deadlocks. We should have the following code before entering this loop.
ReplicaRequest?[] replicaResuests = await Task.WhenAll(tasks);
and loop through this array.
@@ -12,19 +13,17 @@ public async Task SyncLastTicksBetweenDatabaseAndMemory() | |||
var redisMockService = new RedisMockService(); | |||
var historyHttpRedisService = new HistoryHttpRedisService(redisMockService); | |||
var kubernetesService = new Mock<IKubernetesService>(); | |||
var deploymentsInformations = new DeploymentsInformations() | |||
var deploymentsInformations = new DeploymentsInformations(Functions: new List<DeploymentInformation>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks weird to pass an empty list here, i think DeploymentsInformations should:
- be renamed DeploymentInformation
- initialize its own porperties internally
@@ -39,10 +38,10 @@ public async Task SyncLastTicksBetweenDatabaseAndMemory() | |||
await Task.Delay(200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a lot of magic values that should either be centralized somewhere (a static class with const) or moved as const of the type they belong to.
@@ -1,22 +1,24 @@ | |||
using System.Collections; | |||
using Microsoft.Extensions.Logging; | |||
using Moq; | |||
using SlimFaas.Kubernetes; | |||
|
|||
namespace SlimFaas.Tests; | |||
|
|||
public class DeploymentsTestData:IEnumerable<object[]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option to get strongly types is to inherit from TheoryData. Then in the constructor, just call Add() to add tests iterations. This allow to remove the noise of object[].
#16
Now we wait at least one pod is in started state before doing the first HTTP try.