Skip to content
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: Manage functions requests and limits by env vars #471

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apps/lenra/lib/lenra/services/openfaas_services.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule Lenra.OpenfaasServices do
@max_scale_label "com.openfaas.scale.max"
@min_scale_default "1"


defp get_http_context do
base_url = Application.fetch_env!(:lenra, :faas_url)
auth = Application.fetch_env!(:lenra, :faas_auth)
Expand All @@ -37,13 +38,13 @@ defmodule Lenra.OpenfaasServices do
"image" => Apps.image_name(service_name, build_number),
"service" => get_function_name(service_name, build_number),
"secrets" => Application.fetch_env!(:lenra, :faas_secrets),
"limits" => %{
"memory" => "384Mi",
"cpu" => "100m"
},
"requests" => %{
"memory" => "256Mi",
"cpu" => "50m"
"cpu" => Application.fetch_env!(:application_runner, :faas_request_cpu),
"memory" => Application.fetch_env!(:application_runner, :faas_request_memory)
},
"limits" => %{
"cpu" => Application.fetch_env!(:application_runner, :faas_limit_cpu),
"memory" => Application.fetch_env!(:application_runner, :faas_limit_memory)
},
"labels" => %{
@min_scale_label => @min_scale_default,
Expand Down
6 changes: 5 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ config :application_runner,
listeners_timeout: 1 * 60 * 60 * 1000,
view_timeout: 1 * 30 * 1000,
manifest_timeout: 1 * 30 * 1000,
scale_to_zero: false
scale_to_zero: false,
faas_request_cpu: System.get_env("FAAS_REQUEST_CPU", "50m"),
faas_request_memory: System.get_env("FAAS_REQUEST_MEMORY", "128Mi"),
faas_limit_cpu: System.get_env("FAAS_LIMIT_CPU", "100m"),
faas_limit_memory: System.get_env("FAAS_LIMIT_MEMORY", "256Mi")

config :application_runner, :mongo,
hostname: System.get_env("MONGO_HOSTNAME", "localhost"),
Expand Down
6 changes: 5 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ if config_env() == :prod do
username: System.get_env("MONGO_USERNAME"),
password: System.get_env("MONGO_PASSWORD"),
ssl: System.get_env("MONGO_SSL", "false"),
auth_source: System.get_env("MONGO_AUTH_SOURCE")
auth_source: System.get_env("MONGO_AUTH_SOURCE"),
faas_request_cpu: System.get_env("FAAS_REQUEST_CPU", "50m"),
faas_request_memory: System.get_env("FAAS_REQUEST_MEMORY", "128Mi"),
faas_limit_cpu: System.get_env("FAAS_LIMIT_CPU", "100m"),
faas_limit_memory: System.get_env("FAAS_LIMIT_MEMORY", "256Mi")

# Do not print debug messages in production
config :logger, level: String.to_atom(System.get_env("LOG_LEVEL", "info"))
Expand Down
4 changes: 4 additions & 0 deletions docs/env-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ This document provides a list of the environment variables that need to be set f
- `FAAS_URL`: The URL for the FaaS service.
- `FAAS_AUTH`: The authentication for the FaaS service.
- `FAAS_REGISTRY`: The registry for the FaaS service.
- `FAAS_REQUEST_CPU`: The CPU request for the FaaS service. Default is "50m".
- `FAAS_REQUEST_MEMORY`: The memory request for the FaaS service. Default is "128Mi".
- `FAAS_LIMIT_CPU`: The CPU limit for the FaaS service. Default is "100m".
- `FAAS_LIMIT_MEMORY`: The memory limit for the FaaS service. Default is "256Mi".

## Pipeline Configuration

Expand Down
6 changes: 5 additions & 1 deletion libs/application_runner/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ config :application_runner,
faas_url: System.get_env("FAAS_URL", "https://openfaas-dev.lenra.me"),
faas_auth: System.get_env("FAAS_AUTH", "Basic YWRtaW46Z0Q4VjNHR1YxeUpS"),
faas_registry: System.get_env("FAAS_REGISTRY", "registry.gitlab.com/lenra/platform/lenra-ci"),
scale_to_zero: true
scale_to_zero: true,
faas_request_cpu: System.get_env("FAAS_REQUEST_CPU", "50m"),
faas_request_memory: System.get_env("FAAS_REQUEST_MEMORY", "128Mi"),
faas_limit_cpu: System.get_env("FAAS_LIMIT_CPU", "100m"),
faas_limit_memory: System.get_env("FAAS_LIMIT_MEMORY", "256Mi")

config :application_runner, :mongo,
hostname: "localhost",
Expand Down
24 changes: 12 additions & 12 deletions libs/application_runner/lib/services/application_services.ex
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ defmodule ApplicationRunner.ApplicationServices do
"image" => image_name,
"service" => function_name,
"secrets" => Application.fetch_env!(:lenra, :faas_secrets),
"limits" => %{
"memory" => "256Mi",
"cpu" => "100m"
},
"requests" => %{
"memory" => "128Mi",
"cpu" => "50m"
"cpu" => Application.fetch_env!(:application_runner, :faas_request_cpu),
"memory" => Application.fetch_env!(:application_runner, :faas_request_memory)
},
"limits" => %{
"cpu" => Application.fetch_env!(:application_runner, :faas_limit_cpu),
"memory" => Application.fetch_env!(:application_runner, :faas_limit_memory)
},
"labels" => %{
@min_scale_label => @min_scale_default,
Expand Down Expand Up @@ -287,13 +287,13 @@ defmodule ApplicationRunner.ApplicationServices do
Jason.encode!(%{
"image" => app["image"],
"service" => function_name,
"limits" => %{
"memory" => "256Mi",
"cpu" => "100m"
},
"requests" => %{
"memory" => "128Mi",
"cpu" => "50m"
"cpu" => Application.fetch_env!(:application_runner, :faas_request_cpu),
"memory" => Application.fetch_env!(:application_runner, :faas_request_memory)
},
"limits" => %{
"cpu" => Application.fetch_env!(:application_runner, :faas_limit_cpu),
"memory" => Application.fetch_env!(:application_runner, :faas_limit_memory)
},
"labels" => Map.merge(Map.get(app, :labels, %{}), labels)
})
Expand Down
Loading