Skip to content

Commit

Permalink
feature(slimfaas): status-functions (#65)
Browse files Browse the repository at this point in the history
* update

* update

* fix

* update

* update

* update

* update

* update

* update

* dte

* update

* update
  • Loading branch information
guillaume-chervet authored Jun 24, 2024
1 parent f8cc3a7 commit 8999eb6
Show file tree
Hide file tree
Showing 18 changed files with 5,422 additions and 151 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ Why use SlimFaas?
- Allows you to limit the number of parallel HTTP requests for each underlying function
- Synchronous Publish event via HTTP calls (events) to every replicas which deployment subscribe to the event name
- Retry: 3 times with graduation: 2 seconds, 4 seconds, 8 seconds
- Private and Public functions
- Private functions can be accessed only by internal namespace http call from pods
- Mind Changer: REST API that show the status of your functions and allow to wake up your infrastructure
- Very useful to inform end users that your infrastructure is starting
- Plug and Play: just deploy a standard pod
- No impact on your current kubernetes manifests: just add an annotation to the pod you want to auto-scale

- Very **Slim** and very **Fast**

![slim-faas-ram-cpu.png](https://github.com/AxaFrance/SlimFaas/blob/main/documentation/slim-faas-ram-cpu.png)
Expand All @@ -38,7 +41,7 @@ kubectl apply -f deployment-functions.yml
# Install MySql
kubectl apply -f deployment-mysql.yml
# to run Single Page webapp demo (optional) on http://localhost:8000
docker run -p 8000:8000 --rm axaguildev/fibonacci-webapp:latest
docker run -p 8000:8000 --rm axaguildev/fibonacci-webapp:pr-65-592
```


Expand All @@ -60,9 +63,14 @@ Just wake up function:
- http://localhost:30021/wake-function/fibonacci3

Get function status:
- http://localhost:30021/status-function/fibonacci1 => {"NumberReady":1,"numberRequested":1}
- http://localhost:30021/status-function/fibonacci2 => {"NumberReady":1,"numberRequested":1}
- http://localhost:30021/status-function/fibonacci3 => {"NumberReady":1,"numberRequested":1}
- http://localhost:30021/status-function/fibonacci1 => {"NumberReady":1,"numberRequested":1,PodType":"Deployment","Visibility":"Public","Name":"fibonacci1"}
- http://localhost:30021/status-function/fibonacci2 => {"NumberReady":1,"numberRequested":1,PodType":"Deployment","Visibility":"Public","Name":"fibonacci2"}
- http://localhost:30021/status-function/fibonacci3 => {"NumberReady":1,"numberRequested":1,PodType":"Deployment","Visibility":"Public","Name":"fibonacci3"}

List all function status:
- http://localhost:30021/status-functions => [{"NumberReady":1,"numberRequested":1,PodType":"Deployment","Visibility":"Public","Name":"fibonacci1"},
{"NumberReady":1,"numberRequested":1,PodType":"Deployment","Visibility":"Public","Name":"fibonacci2"},
{"NumberReady":1,"numberRequested":1,PodType":"Deployment","Visibility":"Public","Name":"fibonacci3"}]

Send event to every function replicas (which deployment subscribe to the event name) in synchronous way:

Expand Down Expand Up @@ -205,7 +213,7 @@ spec:
- name: BASE_FUNCTION_URL
value: "http://{function_name}.{namespace}.svc.cluster.local:8080"
- name: BASE_FUNCTION_POD_URL # require for publish route
value: "http://{pod_ip}.svc.cluster.local:8080"
value: "http://{pod_ip}:5000"
- name: BASE_SLIMDATA_URL
value: "http://{pod_name}.slimfaas.{namespace}.svc.cluster.local:3262/" # Don't expose this port, it can also be like "http://{pod_ip}:3262/" but if you can use DNS it's better
- name: SLIMFAAS_PORTS
Expand Down Expand Up @@ -382,6 +390,9 @@ Instead of creating many pods, SlimFaas use internally many workers in the same
By default, **SlimData** use a second HTTP port 3262 to expose its API. Don't expose it and keep it internal.

SlimFaas requires at least 3 nodes in production. 2 nodes are required to keep the database in a consistent state.

![slimdata.PNG](https://github.com/AxaFrance/slimfaas/blob/main/documentation/slimdata.png)

If you want to use just one pod for testing purpose, you can use this env variable:
- SLIMDATA_CONFIGURATION: '{"coldStart":"true"}'

Expand Down
6 changes: 6 additions & 0 deletions demo/deployment-functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
SlimFaas/TimeoutSecondBeforeSetReplicasMin: "10"
SlimFaas/NumberParallelRequest: "10"
SlimFaas/DependsOn: "fibonacci2"
SlimFaas/SubscribeEvents : "Public:fibo-public,Private:fibo-private"
#SlimFaas/Schedule: |
# {"Culture":"fr-FR","Default":{"WakeUp":["07:00"],"ScaleDownTimeout":[{"Time": "21:00","Value":20},{"Time":"07:00","Value": 10}]}}
spec:
Expand Down Expand Up @@ -66,6 +67,7 @@ spec:
SlimFaas/ReplicasAtStart: "1"
SlimFaas/TimeoutSecondBeforeSetReplicasMin: "10"
SlimFaas/NumberParallelRequest : "10"
SlimFaas/SubscribeEvents : "Public:fibo-public,Private:fibo-private"
spec:
serviceAccountName: default
containers:
Expand Down Expand Up @@ -112,6 +114,7 @@ spec:
SlimFaas/TimeoutSecondBeforeSetReplicasMin: "10"
SlimFaas/NumberParallelRequest : "10"
SlimFaas/DependsOn: "mysql"
SlimFaas/SubscribeEvents : "Public:fibo-public,Private:fibo-private"
spec:
serviceAccountName: default
containers:
Expand Down Expand Up @@ -157,6 +160,9 @@ spec:
SlimFaas/ReplicasStartAsSoonAsOneFunctionRetrieveARequest: "false"
SlimFaas/TimeoutSecondBeforeSetReplicasMin: "10"
SlimFaas/NumberParallelRequest : "10"
SlimFaas/DefaultVisibility : "Private"
SlimFaas/SubscribeEvents : "Public:fibo-public,Private:fibo-private"

spec:
serviceAccountName: default
containers:
Expand Down
2 changes: 1 addition & 1 deletion demo/deployment-slimfaas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ spec:
- name: BASE_FUNCTION_URL
value: "http://{function_name}.{namespace}.svc.cluster.local:5000"
- name: BASE_FUNCTION_POD_URL # require for publish route
value: "http://{pod_name}.{function_name}.{namespace}.svc.cluster.local:8080"
value: "http://{pod_ip}:5000"
- name: BASE_SLIMDATA_URL
value: "http://{pod_ip}:3262/"
- name: NAMESPACE
Expand Down
Binary file modified documentation/async_http_call.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified documentation/publish_sync_call.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/slimdata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified documentation/slimfaas.pptx
Binary file not shown.
Binary file modified documentation/sync_http_call.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 32 additions & 1 deletion src/Fibonacci/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,44 @@

app.MapGet("/hello/{name}", ([FromServices] ILogger<Fibonacci> logger, string name) =>
{
logger.LogInformation("Hello Called");
logger.LogInformation("Hello Called with name: {Name}", name);
return $"Hello {name}!";
});


app.MapGet("/health", () => "OK");


app.MapPost("/fibonacci4", (
[FromServices] ILogger<Fibonacci> logger,
[FromServices] Fibonacci fibonacci,
FibonacciInput input) =>
{
logger.LogInformation("Fibonacci Internal Called");
using HttpClient client = new();
var response = client.PostAsJsonAsync("http://slimfaas.slimfaas-demo.svc.cluster.local:5000/function/fibonacci4/fibonacci", input).Result;
var output = response.Content.ReadFromJsonAsync<FibonacciOutput>().Result;
logger.LogInformation("Fibonacci Internal output: {Output}", output.Result);
return output;
});


app.MapPost("/send-private-fibonacci-event", (
[FromServices] ILogger<Fibonacci> logger,
[FromServices] Fibonacci fibonacci,
FibonacciInput input) =>
{
logger.LogInformation("Fibonacci Internal Event Called");
using HttpClient client = new();
var response = client.PostAsJsonAsync("http://slimfaas.slimfaas-demo.svc.cluster.local:5000/publish-event/fibo-private/fibonacci", input).Result;
logger.LogInformation("Response status code: {StatusCode}", response.StatusCode);
logger.LogInformation("Fibonacci Internal Event End");
});





app.Run();

internal class Fibonacci
Expand Down
3 changes: 3 additions & 0 deletions src/FibonacciReact/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
legacy-peer-deps=true
strict-ssl=false
registry=https://registry.npmjs.org/
Loading

0 comments on commit 8999eb6

Please sign in to comment.