From 8d96365d185625375af432bfe66d96dd126196c0 Mon Sep 17 00:00:00 2001 From: Thomas DA ROCHA Date: Wed, 28 Aug 2024 17:34:31 +0200 Subject: [PATCH 1/3] fix: Save listener duration en milliseconds --- apps/lenra/lib/lenra/apps.ex | 2 +- config/config.exs | 2 +- config/dev.exs | 2 +- docs/test.md | 29 +++++++++++++++++++ .../lib/channels/route_channel.ex | 5 ++++ libs/application_runner/lib/event_handler.ex | 6 ++++ libs/application_runner/lib/telemetry.ex | 2 +- mix.lock | 16 +++++----- scripts/create_test_user.sh | 27 +++++++++++++++++ 9 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 docs/test.md create mode 100755 scripts/create_test_user.sh diff --git a/apps/lenra/lib/lenra/apps.ex b/apps/lenra/lib/lenra/apps.ex index c0c8ce65..3af016a6 100644 --- a/apps/lenra/lib/lenra/apps.ex +++ b/apps/lenra/lib/lenra/apps.ex @@ -283,7 +283,7 @@ defmodule Lenra.Apps do res end - defp create_build(creator_id, app_id, params) do + def create_build(creator_id, app_id, params) do Logger.debug( "#{__MODULE__} create_build with params #{inspect(%{creator_id: creator_id, app_id: app_id, params: params})}" ) diff --git a/config/config.exs b/config/config.exs index 55e4ff69..7b534d31 100644 --- a/config/config.exs +++ b/config/config.exs @@ -78,7 +78,7 @@ config :lenra_web, LenraWeb.Endpoint, # Configures Elixir's Logger config :logger, :console, - format: "$time $metadata[$level] $message\n", + format: "$date $time $metadata[$level] $message\n", metadata: [:request_id] # Use Jason for JSON parsing in Phoenix diff --git a/config/dev.exs b/config/dev.exs index ba44506b..9d1f446c 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -67,7 +67,7 @@ config :lenra_web, public_api_url: "http://localhost:#{String.to_integer(System.get_env("PORT", "4000"))}" # Do not include metadata nor timestamps in development logs -config :logger, :console, format: "[$level] $message\n" +config :logger, :console, format: "$time [$level] $message\n" # Set a higher stacktrace during development. Avoid configuring such # in production as building large stacktraces may be expensive. diff --git a/docs/test.md b/docs/test.md new file mode 100644 index 00000000..fdc29e48 --- /dev/null +++ b/docs/test.md @@ -0,0 +1,29 @@ +# Local testing + +To test the Lenra server locally... + +## Start the dependency tools + +```bash +docker compose up -d +``` + +## Initiate the database + +```bash +mix setup +``` + +## Add an app in database + +First, you need to add an app in the database. You can do this by running the following command: + +```bash +./scripts/create_test_user.sh +``` + +## Run the server + +```bash +FAAS_URL="http://localhost:3000" mix phx.server +``` diff --git a/libs/application_runner/lib/channels/route_channel.ex b/libs/application_runner/lib/channels/route_channel.ex index 92d19eb2..06b35d6f 100644 --- a/libs/application_runner/lib/channels/route_channel.ex +++ b/libs/application_runner/lib/channels/route_channel.ex @@ -71,13 +71,18 @@ defmodule ApplicationRunner.RouteChannel do session_id = Map.fetch!(socket.assigns, :session_id) Logger.debug("Handle run #{code}") + start_time = Time.utc_now() case Session.send_client_event(session_id, code, event) do {:error, err} -> + duration = Time.diff(Time.utc_now(), start_time, :millisecond) + Logger.debug("/Handle run #{code} failed (#{duration} ms)") Phoenix.Channel.push(socket, "error", ErrorHelpers.translate_error(err)) {:reply, {:error, %{"error" => err}}, socket} _ -> + duration = Time.diff(Time.utc_now(), start_time, :millisecond) + Logger.debug("/Handle run #{code} succeed (#{duration} ms)") {:reply, {:ok, %{}}, socket} end end diff --git a/libs/application_runner/lib/event_handler.ex b/libs/application_runner/lib/event_handler.ex index b2f203fc..cb248e14 100644 --- a/libs/application_runner/lib/event_handler.ex +++ b/libs/application_runner/lib/event_handler.ex @@ -99,11 +99,17 @@ defmodule ApplicationRunner.EventHandler do Logger.debug( "#{__MODULE__} handle_call for listener: #{inspect(listener)} with props #{inspect(props)} and event #{inspect(event)}" ) + start = Time.utc_now() %{function_name: function_name, token: token} = get_metadata(mode, id) |> create_token(uuid) res = ApplicationServices.run_listener(function_name, listener, props, event, token) + duration = Time.diff(Time.utc_now(), start, :millisecond) + Logger.debug( + "End #{__MODULE__} handle_call for listener: #{inspect(listener)} with props #{inspect(props)} and event #{inspect(event)} (#{duration} ms)" + ) + {:reply, res, state} after %{env_id: env_id} = get_metadata(mode, id) diff --git a/libs/application_runner/lib/telemetry.ex b/libs/application_runner/lib/telemetry.ex index 39d9840a..2746a0ea 100644 --- a/libs/application_runner/lib/telemetry.ex +++ b/libs/application_runner/lib/telemetry.ex @@ -30,7 +30,7 @@ defmodule ApplicationRunner.Telemetry do :telemetry.execute( [:application_runner, event, :stop], Map.merge(extra_measurements, %{ - duration: DateTime.diff(end_time, start_time), + duration: DateTime.diff(end_time, start_time, :millisecond), end_time: end_time }), meta diff --git a/mix.lock b/mix.lock index 9030efff..9ba89412 100644 --- a/mix.lock +++ b/mix.lock @@ -7,14 +7,14 @@ "bouncer": {:git, "https://github.com/lenra-io/bouncer.git", "50f11ed26dd7730ba405afedeec65a00499c8cee", [tag: "v1.0.0"]}, "bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, "bypass": {:hex, :bypass, "2.1.0", "909782781bf8e20ee86a9cabde36b259d44af8b9f38756173e8f5e2e1fabb9b1", [:mix], [{:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "d9b5df8fa5b7a6efa08384e9bbecfe4ce61c77d28a4282f79e02f1ef78d96b80"}, - "castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"}, + "castore": {:hex, :castore, "1.0.8", "dedcf20ea746694647f883590b82d9e96014057aff1d44d03ec90f36a5c0dc6e", [:mix], [], "hexpm", "0b2b66d2ee742cb1d9cb8c8be3b43c3a70ee8651f37b75a8b982e036752983f1"}, "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"}, "comeonin": {:hex, :comeonin, "5.4.0", "246a56ca3f41d404380fc6465650ddaa532c7f98be4bda1b4656b3a37cc13abe", [:mix], [], "hexpm", "796393a9e50d01999d56b7b8420ab0481a7538d0caf80919da493b4a6e51faf1"}, "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, "cors_plug": {:hex, :cors_plug, "3.0.3", "7c3ac52b39624bc616db2e937c282f3f623f25f8d550068b6710e58d04a0e330", [:mix], [{:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "3f2d759e8c272ed3835fab2ef11b46bddab8c1ab9528167bd463b6452edf830d"}, - "cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"}, + "cowboy": {:hex, :cowboy, "2.12.0", "f276d521a1ff88b2b9b4c54d0e753da6c66dd7be6c9fca3d9418b561828a3731", [:make, :rebar3], [{:cowlib, "2.13.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "8a7abe6d183372ceb21caa2709bec928ab2b72e18a3911aa1771639bef82651e"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, - "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"}, + "cowlib": {:hex, :cowlib, "2.13.0", "db8f7505d8332d98ef50a3ef34b34c1afddec7506e4ee4dd4a3a266285d282ca", [:make, :rebar3], [], "hexpm", "e1e1284dc3fc030a64b1ad0d8382ae7e99da46c3246b815318a4b848873800a4"}, "credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"}, "crontab": {:hex, :crontab, "1.1.13", "3bad04f050b9f7f1c237809e42223999c150656a6b2afbbfef597d56df2144c5", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "d67441bec989640e3afb94e123f45a2bc42d76e02988c9613885dc3d01cf7085"}, "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, @@ -46,7 +46,7 @@ "honeydew": {:hex, :honeydew, "1.5.0", "53088c1d87399efa5c0939adc8d32a9713b8fe6ce00a77c6769d2d363abac6bc", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "f71669e25f6a972e970ecbd79c34c4ad4b28369be78e4f8164fe8d0c5a674907"}, "hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, - "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "jose": {:hex, :jose, "1.11.6", "613fda82552128aa6fb804682e3a616f4bc15565a048dabd05b1ebd5827ed965", [:mix, :rebar3], [], "hexpm", "6275cb75504f9c1e60eeacb771adfeee4905a9e182103aa59b53fed651ff9738"}, "json_diff": {:hex, :json_diff, "0.1.3", "c80d5ca5416e785867e765e906e9a91b7efc35bfd505af276654d108f4995736", [:mix], [], "hexpm", "a5332e8293e7e9f384d34ea44645d7961334db73739165178fd4a7728d06f7d1"}, "lenra_common": {:hex, :lenra_common, "2.9.0", "78c941b4878d10fed9ec3bbf44437221c662d5556a441a9a832175069414796d", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6.15", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "ce907706adc0fbb72b373c1f1f868205d1ed8ffa7e9d7b4c0db9c25320b3dcc0"}, @@ -68,15 +68,15 @@ "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, "phoenix": {:hex, :phoenix, "1.6.16", "e5bdd18c7a06da5852a25c7befb72246de4ddc289182285f8685a40b7b5f5451", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e15989ff34f670a96b95ef6d1d25bad0d9c50df5df40b671d8f4a669e050ac39"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.2", "b21bd01fdeffcfe2fab49e4942aa938b6d3e89e93a480d4aee58085560a0bc0d", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "70242edd4601d50b69273b057ecf7b684644c19ee750989fd555625ae4ce8f5d"}, - "phoenix_html": {:hex, :phoenix_html, "3.3.3", "380b8fb45912b5638d2f1d925a3771b4516b9a78587249cabe394e0a5d579dc9", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "923ebe6fec6e2e3b3e569dfbdc6560de932cd54b000ada0208b5f45024bdd76c"}, + "phoenix_html": {:hex, :phoenix_html, "3.3.4", "42a09fc443bbc1da37e372a5c8e6755d046f22b9b11343bf885067357da21cb3", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "0249d3abec3714aff3415e7ee3d9786cb325be3151e6c4b3021502c585bf53fb"}, "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.5", "1495bb014be12c9a9252eca04b9af54246f6b5c1e4cd1f30210cd00ec540cf8e", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.7", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "ef4fa50dd78364409039c99cf6f98ab5209b4c5f8796c17f4db118324f0db852"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.4.1", "2aff698f5e47369decde4357ba91fc9c37c6487a512b41732818f2204a8ef1d3", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "9bffb834e7ddf08467fe54ae58b5785507aaba6255568ae22b4d46e2bb3615ab"}, "phoenix_live_view": {:hex, :phoenix_live_view, "0.17.14", "5ec615d4d61bf9d4755f158bd6c80372b715533fe6d6219e12d74fb5eedbeac1", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.0 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "afeb6ba43ce329a6f7fc1c9acdfc6d3039995345f025febb7f409a92f6faebd3"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, - "phoenix_view": {:hex, :phoenix_view, "2.0.3", "4d32c4817fce933693741deeb99ef1392619f942633dde834a5163124813aad3", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "cd34049af41be2c627df99cd4eaa71fc52a328c0c3d8e7d4aa28f880c30e7f64"}, - "plug": {:hex, :plug, "1.15.3", "712976f504418f6dff0a3e554c40d705a9bcf89a7ccef92fc6a5ef8f16a30a97", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4365a3c010a56af402e0809208873d113e9c38c401cabd88027ef4f5c01fd2"}, - "plug_cowboy": {:hex, :plug_cowboy, "2.7.0", "3ae9369c60641084363b08fe90267cbdd316df57e3557ea522114b30b63256ea", [:mix], [{:cowboy, "~> 2.7.0 or ~> 2.8.0 or ~> 2.9.0 or ~> 2.10.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "d85444fb8aa1f2fc62eabe83bbe387d81510d773886774ebdcb429b3da3c1a4a"}, + "phoenix_view": {:hex, :phoenix_view, "2.0.4", "b45c9d9cf15b3a1af5fb555c674b525391b6a1fe975f040fb4d913397b31abf4", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "4e992022ce14f31fe57335db27a28154afcc94e9983266835bb3040243eb620b"}, + "plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.7.1", "87677ffe3b765bc96a89be7960f81703223fe2e21efa42c125fcd0127dd9d6b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "02dbd5f9ab571b864ae39418db7811618506256f6d13b4a45037e5fe78dc5de3"}, "plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"}, "poison": {:hex, :poison, "5.0.0", "d2b54589ab4157bbb82ec2050757779bfed724463a544b6e20d79855a9e43b24", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "11dc6117c501b80c62a7594f941d043982a1bd05a1184280c0d9166eb4d8d3fc"}, "postgrex": {:hex, :postgrex, "0.16.5", "fcc4035cc90e23933c5d69a9cd686e329469446ef7abba2cf70f08e2c4b69810", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "edead639dc6e882618c01d8fc891214c481ab9a3788dfe38dd5e37fd1d5fb2e8"}, diff --git a/scripts/create_test_user.sh b/scripts/create_test_user.sh new file mode 100755 index 00000000..ce868715 --- /dev/null +++ b/scripts/create_test_user.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Add your code here +echo "Creating a test user" +user_id="$(mix run -e ' + {:ok, %{inserted_user: user}} = Lenra.Accounts.register_user(%{"email" => "john.doe@lenra.fr","password" => "Johndoe@thefirst","password_confirmation" => "Johndoe@thefirst"}, :dev); + IO.inspect "user_id=" <> to_string(user.id)' | grep -E '^"user_id=' | sed -E 's/^"user_id=(.+)"$/\1/')" +echo "User created with id: $user_id" + +echo "Creating a test app" +app_name="$(mix run -e " + {:ok, %{inserted_application: app, inserted_env: env}} = Lenra.Apps.create_app(${user_id}, %{ name: \"test\", color: \"FFFFFF\", icon: \"60189\" }); + {:ok, %{inserted_build: build}} = Lenra.Repo.transaction(Lenra.Apps.create_build(${user_id}, app.id, %{})); + {:ok, %{inserted_deployment: deployment}} = Lenra.Apps.create_deployment( + env.id, + build.id, + ${user_id}, + %{} + ); + Lenra.Apps.update_build(build, %{status: :success}); + Lenra.Apps.update_deployment(deployment, %{status: :success}); + env + |> Ecto.Changeset.change(is_public: true, deployment_id: deployment.id) + |> Lenra.Repo.update(); + IO.inspect \"app_name=\" <> to_string(app.service_name)" | grep -E '^\"app_name=' | sed -E 's/^\"app_name=(.+)\"$/\1/')" + +echo "App created with name: $app_name" \ No newline at end of file From 4d9aad2d704e82791edc57b9cc9b9eb7fc189c3d Mon Sep 17 00:00:00 2001 From: Thomas DA ROCHA Date: Wed, 4 Sep 2024 15:18:24 +0200 Subject: [PATCH 2/3] docs: Reset test app --- docs/test.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/test.md b/docs/test.md index fdc29e48..c9308b1d 100644 --- a/docs/test.md +++ b/docs/test.md @@ -14,6 +14,12 @@ docker compose up -d mix setup ``` +If you want to reset the database, you can run the following command: + +```bash +mix ecto.reset +``` + ## Add an app in database First, you need to add an app in the database. You can do this by running the following command: From 9222ddebf337beadd3696c5bbba618bd41f28883 Mon Sep 17 00:00:00 2001 From: Thomas DA ROCHA Date: Tue, 17 Sep 2024 17:57:50 +0200 Subject: [PATCH 3/3] style: Format --- libs/application_runner/lib/event_handler.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/application_runner/lib/event_handler.ex b/libs/application_runner/lib/event_handler.ex index cb248e14..e2713bea 100644 --- a/libs/application_runner/lib/event_handler.ex +++ b/libs/application_runner/lib/event_handler.ex @@ -99,6 +99,7 @@ defmodule ApplicationRunner.EventHandler do Logger.debug( "#{__MODULE__} handle_call for listener: #{inspect(listener)} with props #{inspect(props)} and event #{inspect(event)}" ) + start = Time.utc_now() %{function_name: function_name, token: token} = get_metadata(mode, id) |> create_token(uuid) @@ -106,6 +107,7 @@ defmodule ApplicationRunner.EventHandler do res = ApplicationServices.run_listener(function_name, listener, props, event, token) duration = Time.diff(Time.utc_now(), start, :millisecond) + Logger.debug( "End #{__MODULE__} handle_call for listener: #{inspect(listener)} with props #{inspect(props)} and event #{inspect(event)} (#{duration} ms)" )