From 36020aae87eedf1a41cff29cc354ef94d49f3a9e Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Mon, 25 Jan 2021 14:31:40 -0800 Subject: [PATCH 01/11] Add phoenix_live_dashboard --- config/config.exs | 4 +++- lib/ret_web/endpoint.ex | 2 ++ lib/ret_web/router.ex | 6 ++++++ mix.exs | 1 + mix.lock | 3 +++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index 284361ab7..d2e6ff7e5 100644 --- a/config/config.exs +++ b/config/config.exs @@ -30,7 +30,9 @@ config :ret, RetWeb.Endpoint, url: [host: "localhost"], secret_key_base: "txlMOtlaY5x3crvOCko4uV5PM29ul3zGo1oBGNO3cDXx+7GHLKqt0gR9qzgThxb5", render_errors: [view: RetWeb.ErrorView, accepts: ~w(html json)], - pubsub_server: Ret.PubSub + pubsub_server: Ret.PubSub, + # TODO: Load salt securely for production environment + live_view: [signing_salt: "p1pqfyVx4YPcjkZYz5PiQJDm0XlMWYk7"] # Configures Elixir's Logger config :logger, :console, diff --git a/lib/ret_web/endpoint.ex b/lib/ret_web/endpoint.ex index dff9480b0..e5b128e57 100644 --- a/lib/ret_web/endpoint.ex +++ b/lib/ret_web/endpoint.ex @@ -3,6 +3,8 @@ defmodule RetWeb.Endpoint do use Sentry.Phoenix.Endpoint use Absinthe.Phoenix.Endpoint + socket "/live", Phoenix.LiveView.Socket + socket("/socket", RetWeb.SessionSocket, websocket: [check_origin: {RetWeb.Endpoint, :allowed_origin?, []}]) def get_cors_origins, do: Application.get_env(:ret, RetWeb.Endpoint)[:allowed_origins] |> String.split(",") diff --git a/lib/ret_web/router.ex b/lib/ret_web/router.ex index 3342fc143..a1708c863 100644 --- a/lib/ret_web/router.ex +++ b/lib/ret_web/router.ex @@ -2,6 +2,7 @@ defmodule RetWeb.Router do use RetWeb, :router use Plug.ErrorHandler use Sentry.Plug + import Phoenix.LiveDashboard.Router pipeline :secure_headers do plug(:put_secure_browser_headers) @@ -179,6 +180,11 @@ defmodule RetWeb.Router do end end + scope "/" do + pipe_through [:parsed_body, :browser] + live_dashboard "/telemetry" + end + scope "/", RetWeb do pipe_through([:secure_headers, :parsed_body, :browser] ++ if(Mix.env() == :prod, do: [:ssl_only], else: [])) diff --git a/mix.exs b/mix.exs index 219d86a40..66d9e8d30 100644 --- a/mix.exs +++ b/mix.exs @@ -48,6 +48,7 @@ defmodule Ret.Mixfile do {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 2.13"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, + {:phoenix_live_dashboard, "~> 0.1"}, {:gettext, "~> 0.17"}, {:plug_cowboy, "~> 2.1"}, {:distillery, "~> 2.0"}, diff --git a/mix.lock b/mix.lock index a4bd59723..367cdc823 100644 --- a/mix.lock +++ b/mix.lock @@ -60,7 +60,9 @@ "phoenix": {:hex, :phoenix, "1.5.7", "2923bb3af924f184459fe4fa4b100bd25fa6468e69b2803dfae82698269aa5e0", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "774cd64417c5a3788414fdbb2be2eb9bcd0c048d9e6ad11a0c1fd67b7c0d0978"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.1.0", "a044d0756d0464c5a541b4a0bf4bcaf89bffcaf92468862408290682c73ae50d", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "c5e666a341ff104d0399d8f0e4ff094559b2fde13a5985d4cb5023b2c2ac558b"}, "phoenix_html": {:hex, :phoenix_html, "2.14.3", "51f720d0d543e4e157ff06b65de38e13303d5778a7919bcc696599e5934271b8", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "efd697a7fff35a13eeeb6b43db884705cba353a1a41d127d118fda5f90c8e80f"}, + "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.4.0", "87990e68b60213d7487e65814046f9a2bed4a67886c943270125913499b3e5c3", [:mix], [{:ecto_psql_extras, "~> 0.4.1 or ~> 0.5", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.14.1 or ~> 2.15", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.15.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.4.0 or ~> 0.5.0 or ~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "8d52149e58188e9e4497cc0d8900ab94d9b66f96998ec38c47c7a4f8f4f50e57"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.1", "274a4b07c4adbdd7785d45a8b0bb57634d0b4f45b18d2c508b26c0344bd59b8f", [: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", "41b4103a2fa282cfd747d377233baf213c648fdcc7928f432937676532490eee"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "0.15.3", "70c7917e5c421e32d1a1c8ddf8123378bb741748cd8091eb9d557fb4be92a94f", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.7", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 0.5", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cabcfb6738419a08600009219a5f0d861de97507fc1232121e1d5221aba849bd"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"}, "plug": {:hex, :plug, "1.11.0", "f17217525597628298998bc3baed9f8ea1fa3f1160aa9871aee6df47a6e4d38e", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2d9c633f0499f9dc5c2fd069161af4e2e7756890b81adcbb2ceaa074e8308876"}, "plug_attack": {:hex, :plug_attack, "0.4.2", "0413707429210b890e21758902ac720a4e06c0350453df9954da3d4ca4bac5d8", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "e9a2b1786e1d180d295b5974d337f0952de007eaf081f11d075aa1be65347288"}, @@ -82,6 +84,7 @@ "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "statix": {:hex, :statix, "1.4.0", "c822abd1e60e62828e8460e932515d0717aa3c089b44cc3f795d43b94570b3a8", [:mix], [], "hexpm", "507373cc80925a9b6856cb14ba17f6125552434314f6613c907d295a09d1a375"}, "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, + "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.0", "da9d49ee7e6bb1c259d36ce6539cd45ae14d81247a2b0c90edf55e2b50507f7b", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5cfe67ad464b243835512aa44321cee91faed6ea868d7fb761d7016e02915c3d"}, "temp": {:hex, :temp, "0.4.7", "2c78482cc2294020a4bc0c95950b907ff386523367d4e63308a252feffbea9f2", [:mix], [], "hexpm", "6af19e7d6a85a427478be1021574d1ae2a1e1b90882586f06bde76c63cd03e0d"}, "the_end": {:git, "https://github.com/mozillareality/the_end.git", "978ce97bec3ec754182fa72e24a82eab935a5853", [branch: "bug/phoenix-14"]}, "timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "f354efb2400dd7a80fd9eb6c8419068c4f632da4ac47f3d8822d6e33f08bc852"}, From 37cc4ee8522bdebb9c56f594e248eae07e6b9b80 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 10:25:57 -0800 Subject: [PATCH 02/11] Add cookie-based authentication --- lib/ret_web/auth_pipeline.ex | 1 + .../controllers/api/v1/account_controller.ex | 29 +++++++++++++++++++ lib/ret_web/router.ex | 21 ++++++++++---- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/ret_web/auth_pipeline.ex b/lib/ret_web/auth_pipeline.ex index 63d13c3b1..41194b9e9 100644 --- a/lib/ret_web/auth_pipeline.ex +++ b/lib/ret_web/auth_pipeline.ex @@ -5,6 +5,7 @@ defmodule RetWeb.Guardian.AuthPipeline do error_handler: RetWeb.Guardian.AuthErrorHandler plug(Guardian.Plug.VerifyHeader, realm: "Bearer") + plug(Guardian.Plug.VerifyCookie, exchange_from: "access") plug(Guardian.Plug.EnsureAuthenticated) plug(Guardian.Plug.LoadResource) end diff --git a/lib/ret_web/controllers/api/v1/account_controller.ex b/lib/ret_web/controllers/api/v1/account_controller.ex index 4a01a2e7c..63c7452d7 100644 --- a/lib/ret_web/controllers/api/v1/account_controller.ex +++ b/lib/ret_web/controllers/api/v1/account_controller.ex @@ -63,4 +63,33 @@ defmodule RetWeb.Api.V1.AccountController do {:ok, {200, Phoenix.View.render(AccountView, "create.json", account: account, email: email)}} end end + + def set_cookie(conn, _params) do + conn + |> set_account_cookie(%{ + value: Ret.Guardian.Plug.current_token(conn), + max_age: 60 * 60 * 24 + }) + |> Plug.Conn.send_resp(200, "") + end + + def expire_cookie(conn, _params) do + conn + |> set_account_cookie(%{value: "", max_age: 60}) + |> Plug.Conn.send_resp(200, "") + end + + defp set_account_cookie(conn, %{value: value, max_age: max_age}) do + key = Guardian.Plug.Keys.token_key("default") |> Atom.to_string() + + opts = [ + encrypt: false, + max_age: max_age, + http_only: true, + secure: true + ] + + conn + |> Plug.Conn.put_resp_cookie(key, value, opts) + end end diff --git a/lib/ret_web/router.ex b/lib/ret_web/router.ex index a1708c863..5dd5537c5 100644 --- a/lib/ret_web/router.ex +++ b/lib/ret_web/router.ex @@ -89,6 +89,22 @@ defmodule RetWeb.Router do forward("/", RetWeb.Plugs.ItaProxy) end + scope "/", RetWeb do + pipe_through( + [:secure_headers, :parsed_body, :browser] ++ + if(Mix.env() == :prod, do: [:ssl_only, :canonicalize_domain], else: []) + ) + + get("/api/v1/accounts/expire_cookie", Api.V1.AccountController, :expire_cookie) + + scope "/" do + pipe_through([:admin_required]) + + live_dashboard "/telemetry" + get("/api/v1/accounts/set_cookie", Api.V1.AccountController, :set_cookie) + end + end + scope "/api", RetWeb do pipe_through( [:secure_headers, :parsed_body, :api] ++ if(Mix.env() == :prod, do: [:ssl_only, :canonicalize_domain], else: []) @@ -180,11 +196,6 @@ defmodule RetWeb.Router do end end - scope "/" do - pipe_through [:parsed_body, :browser] - live_dashboard "/telemetry" - end - scope "/", RetWeb do pipe_through([:secure_headers, :parsed_body, :browser] ++ if(Mix.env() == :prod, do: [:ssl_only], else: [])) From 2d8a3e2bf4e53bb570fe54d5ba848ff2ff8cbf92 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 11:11:51 -0800 Subject: [PATCH 03/11] Use encrypted cookies --- lib/ret_web/auth_pipeline.ex | 13 ++++++++++++- .../controllers/api/v1/account_controller.ex | 2 +- .../plugs/decrypt_auth_cookie_into_session.ex | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 lib/ret_web/plugs/decrypt_auth_cookie_into_session.ex diff --git a/lib/ret_web/auth_pipeline.ex b/lib/ret_web/auth_pipeline.ex index 41194b9e9..6a5049a7a 100644 --- a/lib/ret_web/auth_pipeline.ex +++ b/lib/ret_web/auth_pipeline.ex @@ -5,7 +5,18 @@ defmodule RetWeb.Guardian.AuthPipeline do error_handler: RetWeb.Guardian.AuthErrorHandler plug(Guardian.Plug.VerifyHeader, realm: "Bearer") - plug(Guardian.Plug.VerifyCookie, exchange_from: "access") + # TODO: Move configuration elsewhere + plug Plug.Session, + store: :cookie, + key: "_ret_session", + # TODO: Provide real salts (safely) + encryption_salt: "8XD1Tqa223TZ/1pErZGaKDWLbnEFfdo/", + signing_salt: "ZXAeUzIQJdzKT5WmxUQpROOL7eqK1FsX", + key_length: 64, + log: :debug + + plug(RetWeb.Plugs.DecryptAuthCookieIntoSession) + plug(Guardian.Plug.VerifySession) plug(Guardian.Plug.EnsureAuthenticated) plug(Guardian.Plug.LoadResource) end diff --git a/lib/ret_web/controllers/api/v1/account_controller.ex b/lib/ret_web/controllers/api/v1/account_controller.ex index 63c7452d7..1baf08e08 100644 --- a/lib/ret_web/controllers/api/v1/account_controller.ex +++ b/lib/ret_web/controllers/api/v1/account_controller.ex @@ -83,7 +83,7 @@ defmodule RetWeb.Api.V1.AccountController do key = Guardian.Plug.Keys.token_key("default") |> Atom.to_string() opts = [ - encrypt: false, + encrypt: true, max_age: max_age, http_only: true, secure: true diff --git a/lib/ret_web/plugs/decrypt_auth_cookie_into_session.ex b/lib/ret_web/plugs/decrypt_auth_cookie_into_session.ex new file mode 100644 index 000000000..7f5fd23e9 --- /dev/null +++ b/lib/ret_web/plugs/decrypt_auth_cookie_into_session.ex @@ -0,0 +1,14 @@ +defmodule RetWeb.Plugs.DecryptAuthCookieIntoSession do + def init([]), do: [] + + def call(conn, []) do + conn = Plug.Conn.fetch_cookies(conn, encrypted: "guardian_default_token") + # Plug.Conn.fetch_cookies decrypts into conn.cookies + # But Guardian.Plug.VerifyCookie reads from conn.req_cookies + # so instead we put token into a session and use + # Guardian.Plug.VerifySession + conn = Plug.Conn.fetch_session(conn) + conn = Plug.Conn.put_session(conn, "guardian_default_token", conn.cookies["guardian_default_token"] || nil) + conn + end +end From a351493f2716ed408d32e0d2eb8009bad672ac7f Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 11:14:09 -0800 Subject: [PATCH 04/11] Enable os_mon --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 66d9e8d30..47d3028b5 100644 --- a/mix.exs +++ b/mix.exs @@ -20,7 +20,7 @@ defmodule Ret.Mixfile do def application do [ mod: {Ret.Application, []}, - extra_applications: [:runtime_tools, :canada] + extra_applications: [:runtime_tools, :canada, :os_mon] ] end From 769fcef76c6ef7ac5d32db24e83c10510675a674 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 11:32:16 -0800 Subject: [PATCH 05/11] Add metrics to LiveDashboard --- lib/ret/application.ex | 1 + lib/ret_web/plugs/add_csp.ex | 2 +- lib/ret_web/router.ex | 2 +- lib/ret_web/telemetry.ex | 53 ++++++++++++++++++++++++++++++++++++ mix.exs | 4 ++- mix.lock | 1 + 6 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 lib/ret_web/telemetry.ex diff --git a/lib/ret/application.ex b/lib/ret/application.ex index 28fae1874..66a9e33f9 100644 --- a/lib/ret/application.ex +++ b/lib/ret/application.ex @@ -69,6 +69,7 @@ defmodule Ret.Application do # Start the Ecto repository supervisor(Ret.Repo, []), + RetWeb.Telemetry, supervisor(RetWeb.Endpoint, []), supervisor(RetWeb.Presence, []), diff --git a/lib/ret_web/plugs/add_csp.ex b/lib/ret_web/plugs/add_csp.ex index 5b2289ff5..2576287a5 100644 --- a/lib/ret_web/plugs/add_csp.ex +++ b/lib/ret_web/plugs/add_csp.ex @@ -70,7 +70,7 @@ defmodule RetWeb.Plugs.AddCSP do }:#{janus_port} #{default_janus_csp_rule}" end - "default-src 'none'; manifest-src #{custom_rules[:manifest_src]} 'self'; script-src #{custom_rules[:script_src]} #{ + "default-src 'none'; manifest-src #{custom_rules[:manifest_src]} 'self'; script-src 'self' 'unsafe-inline'; script-src #{custom_rules[:script_src]} #{ storage_url } #{assets_url} 'self' 'unsafe-eval' 'sha256-ViVvpb0oYlPAp7R8ZLxlNI6rsf7E7oz8l1SgCIXgMvM=' 'sha256-hsbRcgUBASABDq7qVGVTpbnWq/ns7B+ToTctZFJXYi8=' 'sha256-MIpWPgYj31kCgSUFc0UwHGQrV87W6N5ozotqfxxQG0w=' 'sha256-buF6N8Z4p2PuaaeRUjm7mxBpPNf4XlCT9Fep83YabbM=' 'sha256-/S6PM16MxkmUT7zJN2lkEKFgvXR7yL4Z8PCrRrFu4Q8=' https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js 'sha256-foB3G7vO68Ot8wctsG3OKBQ84ADKVinlnTg9/s93Ycs=' 'sha256-g0j42v3Wo/ohUAMR/t0EuObDSEkx1rZ3lv45fUaNmYs=' https://www.google-analytics.com https://ssl.google-analytics.com #{ storage_url diff --git a/lib/ret_web/router.ex b/lib/ret_web/router.ex index 5dd5537c5..5e53b327e 100644 --- a/lib/ret_web/router.ex +++ b/lib/ret_web/router.ex @@ -100,7 +100,7 @@ defmodule RetWeb.Router do scope "/" do pipe_through([:admin_required]) - live_dashboard "/telemetry" + live_dashboard "/telemetry", metrics: RetWeb.Telemetry get("/api/v1/accounts/set_cookie", Api.V1.AccountController, :set_cookie) end end diff --git a/lib/ret_web/telemetry.ex b/lib/ret_web/telemetry.ex new file mode 100644 index 000000000..dd60dac9c --- /dev/null +++ b/lib/ret_web/telemetry.ex @@ -0,0 +1,53 @@ +# TODO: Add metrics from various telemetry-enabled libraries (e.g. absinthe) +# TODO: Add storage and enable history https://hexdocs.pm/phoenix_live_dashboard/metrics_history.html +defmodule RetWeb.Telemetry do + use Supervisor + import Telemetry.Metrics + + def start_link(arg) do + Supervisor.start_link(__MODULE__, arg, name: __MODULE__) + end + + @impl true + def init(_arg) do + children = [ + # Telemetry poller will execute the given period measurements + # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics + {:telemetry_poller, measurements: periodic_measurements(), period: 10_000} + # Add reporters as children of your supervision tree. + # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} + ] + + Supervisor.init(children, strategy: :one_for_one) + end + + def metrics do + [ + # Phoenix Metrics + summary("phoenix.endpoint.stop.duration", + unit: {:native, :millisecond} + ), + summary("phoenix.router_dispatch.stop.duration", + tags: [:route], + unit: {:native, :millisecond} + ), + + # Database Time Metrics + summary("ret.repo.query.total_time", unit: {:native, :millisecond}), + summary("ret.repo.query.decode_time", unit: {:native, :millisecond}), + summary("ret.repo.query.query_time", unit: {:native, :millisecond}), + summary("ret.repo.query.queue_time", unit: {:native, :millisecond}), + summary("ret.repo.query.idle_time", unit: {:native, :millisecond}), + + # VM Metrics + summary("vm.memory.total", unit: {:byte, :kilobyte}), + summary("vm.total_run_queue_lengths.total"), + summary("vm.total_run_queue_lengths.cpu"), + summary("vm.total_run_queue_lengths.io") + ] + end + + defp periodic_measurements do + [] + end +end diff --git a/mix.exs b/mix.exs index 47d3028b5..706c03e0b 100644 --- a/mix.exs +++ b/mix.exs @@ -88,7 +88,9 @@ defmodule Ret.Mixfile do {:ex_rated, "~> 1.3.3"}, {:mix_test_watch, "~> 1.0", only: :dev, runtime: false}, {:ex_json_schema, "~> 0.7.3"}, - {:observer_cli, "~> 1.5"} + {:observer_cli, "~> 1.5"}, + {:telemetry_poller, "~> 0.4"}, + {:telemetry_metrics, "~> 0.4"} ] end diff --git a/mix.lock b/mix.lock index 367cdc823..40618e858 100644 --- a/mix.lock +++ b/mix.lock @@ -85,6 +85,7 @@ "statix": {:hex, :statix, "1.4.0", "c822abd1e60e62828e8460e932515d0717aa3c089b44cc3f795d43b94570b3a8", [:mix], [], "hexpm", "507373cc80925a9b6856cb14ba17f6125552434314f6613c907d295a09d1a375"}, "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.0", "da9d49ee7e6bb1c259d36ce6539cd45ae14d81247a2b0c90edf55e2b50507f7b", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5cfe67ad464b243835512aa44321cee91faed6ea868d7fb761d7016e02915c3d"}, + "telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"}, "temp": {:hex, :temp, "0.4.7", "2c78482cc2294020a4bc0c95950b907ff386523367d4e63308a252feffbea9f2", [:mix], [], "hexpm", "6af19e7d6a85a427478be1021574d1ae2a1e1b90882586f06bde76c63cd03e0d"}, "the_end": {:git, "https://github.com/mozillareality/the_end.git", "978ce97bec3ec754182fa72e24a82eab935a5853", [branch: "bug/phoenix-14"]}, "timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "f354efb2400dd7a80fd9eb6c8419068c4f632da4ac47f3d8822d6e33f08bc852"}, From 59a3230cb4f692b02951bd5552ad9080988640e1 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 11:46:32 -0800 Subject: [PATCH 06/11] lint --- lib/ret_web/plugs/add_csp.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ret_web/plugs/add_csp.ex b/lib/ret_web/plugs/add_csp.ex index 2576287a5..f67cb69a2 100644 --- a/lib/ret_web/plugs/add_csp.ex +++ b/lib/ret_web/plugs/add_csp.ex @@ -70,9 +70,9 @@ defmodule RetWeb.Plugs.AddCSP do }:#{janus_port} #{default_janus_csp_rule}" end - "default-src 'none'; manifest-src #{custom_rules[:manifest_src]} 'self'; script-src 'self' 'unsafe-inline'; script-src #{custom_rules[:script_src]} #{ - storage_url - } #{assets_url} 'self' 'unsafe-eval' 'sha256-ViVvpb0oYlPAp7R8ZLxlNI6rsf7E7oz8l1SgCIXgMvM=' 'sha256-hsbRcgUBASABDq7qVGVTpbnWq/ns7B+ToTctZFJXYi8=' 'sha256-MIpWPgYj31kCgSUFc0UwHGQrV87W6N5ozotqfxxQG0w=' 'sha256-buF6N8Z4p2PuaaeRUjm7mxBpPNf4XlCT9Fep83YabbM=' 'sha256-/S6PM16MxkmUT7zJN2lkEKFgvXR7yL4Z8PCrRrFu4Q8=' https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js 'sha256-foB3G7vO68Ot8wctsG3OKBQ84ADKVinlnTg9/s93Ycs=' 'sha256-g0j42v3Wo/ohUAMR/t0EuObDSEkx1rZ3lv45fUaNmYs=' https://www.google-analytics.com https://ssl.google-analytics.com #{ + "default-src 'none'; manifest-src #{custom_rules[:manifest_src]} 'self'; script-src 'self' 'unsafe-inline'; script-src #{ + custom_rules[:script_src] + } #{storage_url} #{assets_url} 'self' 'unsafe-eval' 'sha256-ViVvpb0oYlPAp7R8ZLxlNI6rsf7E7oz8l1SgCIXgMvM=' 'sha256-hsbRcgUBASABDq7qVGVTpbnWq/ns7B+ToTctZFJXYi8=' 'sha256-MIpWPgYj31kCgSUFc0UwHGQrV87W6N5ozotqfxxQG0w=' 'sha256-buF6N8Z4p2PuaaeRUjm7mxBpPNf4XlCT9Fep83YabbM=' 'sha256-/S6PM16MxkmUT7zJN2lkEKFgvXR7yL4Z8PCrRrFu4Q8=' https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js 'sha256-foB3G7vO68Ot8wctsG3OKBQ84ADKVinlnTg9/s93Ycs=' 'sha256-g0j42v3Wo/ohUAMR/t0EuObDSEkx1rZ3lv45fUaNmYs=' https://www.google-analytics.com https://ssl.google-analytics.com #{ storage_url } #{assets_url} https://aframe.io https://www.youtube.com https://s.ytimg.com; child-src #{custom_rules[:child_src]} 'self' blob:; worker-src #{ custom_rules[:worker_src] From ce509fc2fd1cf2d9e7aef78590123eac40e4bd37 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 12:00:32 -0800 Subject: [PATCH 07/11] Add repo stats (and mess up the csp) --- lib/ret_web/plugs/add_csp.ex | 6 +----- lib/ret_web/router.ex | 5 ++++- mix.exs | 8 ++++---- mix.lock | 12 +++++++----- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/ret_web/plugs/add_csp.ex b/lib/ret_web/plugs/add_csp.ex index f67cb69a2..dc6697d1e 100644 --- a/lib/ret_web/plugs/add_csp.ex +++ b/lib/ret_web/plugs/add_csp.ex @@ -70,11 +70,7 @@ defmodule RetWeb.Plugs.AddCSP do }:#{janus_port} #{default_janus_csp_rule}" end - "default-src 'none'; manifest-src #{custom_rules[:manifest_src]} 'self'; script-src 'self' 'unsafe-inline'; script-src #{ - custom_rules[:script_src] - } #{storage_url} #{assets_url} 'self' 'unsafe-eval' 'sha256-ViVvpb0oYlPAp7R8ZLxlNI6rsf7E7oz8l1SgCIXgMvM=' 'sha256-hsbRcgUBASABDq7qVGVTpbnWq/ns7B+ToTctZFJXYi8=' 'sha256-MIpWPgYj31kCgSUFc0UwHGQrV87W6N5ozotqfxxQG0w=' 'sha256-buF6N8Z4p2PuaaeRUjm7mxBpPNf4XlCT9Fep83YabbM=' 'sha256-/S6PM16MxkmUT7zJN2lkEKFgvXR7yL4Z8PCrRrFu4Q8=' https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js 'sha256-foB3G7vO68Ot8wctsG3OKBQ84ADKVinlnTg9/s93Ycs=' 'sha256-g0j42v3Wo/ohUAMR/t0EuObDSEkx1rZ3lv45fUaNmYs=' https://www.google-analytics.com https://ssl.google-analytics.com #{ - storage_url - } #{assets_url} https://aframe.io https://www.youtube.com https://s.ytimg.com; child-src #{custom_rules[:child_src]} 'self' blob:; worker-src #{ + "default-src 'none'; manifest-src #{custom_rules[:manifest_src]} 'self'; script-src * 'unsafe-inline' 'unsafe-eval'; child-src #{custom_rules[:child_src]} 'self' blob:; worker-src #{ custom_rules[:worker_src] } #{storage_url} #{assets_url} 'self' blob:; font-src #{custom_rules[:font_src]} 'self' https://fonts.googleapis.com https://cdn.jsdelivr.net https://fonts.gstatic.com https://cdn.aframe.io #{ storage_url diff --git a/lib/ret_web/router.ex b/lib/ret_web/router.ex index 5e53b327e..6e7b8739f 100644 --- a/lib/ret_web/router.ex +++ b/lib/ret_web/router.ex @@ -100,7 +100,10 @@ defmodule RetWeb.Router do scope "/" do pipe_through([:admin_required]) - live_dashboard "/telemetry", metrics: RetWeb.Telemetry + # TODO: investigate whether we have pg_stat_statements installed for postgres + # https://www.postgresql.org/docs/current/pgstatstatements.html + # https://hexdocs.pm/phoenix_live_dashboard/ecto_stats.html#install-custom-extensions + live_dashboard "/telemetry", metrics: RetWeb.Telemetry, ecto_repos: [Ret.Repo] get("/api/v1/accounts/set_cookie", Api.V1.AccountController, :set_cookie) end end diff --git a/mix.exs b/mix.exs index 706c03e0b..78714a118 100644 --- a/mix.exs +++ b/mix.exs @@ -38,9 +38,8 @@ defmodule Ret.Mixfile do {:phoenix_pubsub, "~> 2.0"}, {:phoenix_ecto, "~> 4.0"}, {:plug, "~> 1.7"}, - # Avoid 3.4.0 for now bc https://github.com/elixir-ecto/ecto/issues/3246 - {:ecto, "~> 3.3.0"}, - {:ecto_sql, "~> 3.3.0"}, + {:ecto, "~> 3.5.0"}, + {:ecto_sql, "~> 3.5.0"}, {:absinthe, "~> 1.5.0"}, {:dataloader, "~> 1.0.0"}, {:absinthe_plug, "~> 1.5.0"}, @@ -90,7 +89,8 @@ defmodule Ret.Mixfile do {:ex_json_schema, "~> 0.7.3"}, {:observer_cli, "~> 1.5"}, {:telemetry_poller, "~> 0.4"}, - {:telemetry_metrics, "~> 0.4"} + {:telemetry_metrics, "~> 0.4"}, + {:ecto_psql_extras, "~> 0.2"} ] end diff --git a/mix.lock b/mix.lock index 40618e858..3a7bca7fb 100644 --- a/mix.lock +++ b/mix.lock @@ -12,7 +12,7 @@ "canary": {:hex, :canary, "1.1.1", "4138d5e05db8497c477e4af73902eb9ae06e49dceaa13c2dd9f0b55525ded48b", [:mix], [{:canada, "~> 1.0.1", [hex: :canada, repo: "hexpm", optional: false]}, {:ecto, ">= 1.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "f348d9848693c830a65b707bba9e4dfdd6434e8c356a8d4477e4535afb0d653b"}, "certifi": {:hex, :certifi, "2.5.3", "70bdd7e7188c804f3a30ee0e7c99655bc35d8ac41c23e12325f36ab449b70651", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "ed516acb3929b101208a9d700062d520f3953da3b6b918d866106ffa980e1c10"}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, - "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, + "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, "cors_plug": {:hex, :cors_plug, "2.0.2", "2b46083af45e4bc79632bd951550509395935d3e7973275b2b743bd63cc942ce", [:mix], [{:plug, "~> 1.8", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "f0d0e13f71c51fd4ef8b2c7e051388e4dfb267522a83a22392c856de7e46465f"}, "cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"}, @@ -20,16 +20,17 @@ "credo": {:hex, :credo, "1.3.2", "08d456dcf3c24da162d02953fb07267e444469d8dad3a2ae47794938ea467b3a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "b11d28cce1f1f399dddffd42d8e21dcad783309e230f84b70267b1a5546468b6"}, "crontab": {:hex, :crontab, "1.1.10", "dc9bb1f4299138d47bce38341f5dcbee0aa6c205e864fba7bc847f3b5cb48241", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "1347d889d1a0eda997990876b4894359e34bfbbd688acbb0ba28a2795ca40685"}, "dataloader": {:hex, :dataloader, "1.0.7", "58351b335673cf40601429bfed6c11fece6ce7ad169b2ac0f0fe83e716587391", [:mix], [{:ecto, ">= 0.0.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "12bf66478e4a5085d09dc96932d058c206ee8c219cc7691d12a40dc35c8cefaa"}, - "db_connection": {:hex, :db_connection, "2.2.1", "caee17725495f5129cb7faebde001dc4406796f12a62b8949f4ac69315080566", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "2b02ece62d9f983fcd40954e443b7d9e6589664380e5546b2b9b523cd0fb59e1"}, + "db_connection": {:hex, :db_connection, "2.3.1", "4c9f3ed1ef37471cbdd2762d6655be11e38193904d9c5c1c9389f1b891a3088e", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "abaab61780dde30301d840417890bd9f74131041afd02174cf4e10635b3a63f5"}, "decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"}, "deferred_config": {:hex, :deferred_config, "0.1.1", "ec912e9ee3c99b90a8d4bdec8fbd15309f4bd6729f30789e0ff6f595d06bbce5", [:mix], [], "hexpm", "2eb5311037feb4a6a5dbe3ecc5c98af7ea849730e5dbd9aee0f45c5dbccc3922"}, "distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"}, "download": {:git, "https://github.com/gfodor/download.git", "3c341da4a9c3c8fface65d968b4068bd3078b405", [branch: "reticulum/master"]}, - "ecto": {:hex, :ecto, "3.3.4", "95b05c82ae91361475e5491c9f3ac47632f940b3f92ae3988ac1aad04989c5bb", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "9b96cbb83a94713731461ea48521b178b0e3863d310a39a3948c807266eebd69"}, + "ecto": {:hex, :ecto, "3.5.6", "29c77e999e471921c7ce7347732bab7bfa3e24c587640a36f17e0744d1474b8e", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3ae1f3eaecc3e72eeb65ed43239b292bb1eaf335c7e6cea3a7fc27aadb6e93e7"}, "ecto_autoslug_field": {:hex, :ecto_autoslug_field, "2.0.1", "2177c1c253f6dd3efd4b56d1cb76104d0a6ef044c6b9a7a0ad6d32665c4111e5", [:mix], [{:ecto, ">= 2.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:slugger, ">= 0.2.0", [hex: :slugger, repo: "hexpm", optional: false]}], "hexpm", "a3cc73211f2e75b89a03332183812ebe1ac08be2e25a1df5aa3d1422f92c45c3"}, "ecto_boot_migration": {:hex, :ecto_boot_migration, "0.2.0", "fb5b08a01f2668ff3fab1a89a04484eeb8610c84e82b98fd90334f1e2dadc5e1", [:mix], [{:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "10f2e014f97d40620e23a48947ac60f230668ac2a24df2152b8a6b81a28b5dda"}, "ecto_enum": {:hex, :ecto_enum, "1.4.0", "d14b00e04b974afc69c251632d1e49594d899067ee2b376277efd8233027aec8", [:mix], [{:ecto, ">= 3.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "> 3.0.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "8fb55c087181c2b15eee406519dc22578fa60dd82c088be376d0010172764ee4"}, - "ecto_sql": {:hex, :ecto_sql, "3.3.4", "aa18af12eb875fbcda2f75e608b3bd534ebf020fc4f6448e4672fcdcbb081244", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4 or ~> 3.3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5eccbdbf92e3c6f213007a82d5dbba4cd9bb659d1a21331f89f408e4c0efd7a8"}, + "ecto_psql_extras": {:hex, :ecto_psql_extras, "0.6.2", "ff964dcfd80ee285797025734484742faa04b56c2674380014e7233851c5f8b2", [:mix], [{:ecto_sql, "~> 3.4", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.15.7", [hex: :postgrex, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "7e7f88140f14a8aed4b82269aece28498086edd032cd94fac7d05059f9b09c7e"}, + "ecto_sql": {:hex, :ecto_sql, "3.5.4", "a9e292c40bd79fff88885f95f1ecd7b2516e09aa99c7dd0201aa84c54d2358e4", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.5.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1fff1a28a898d7bbef263f1f3ea425b04ba9f33816d843238c84eff883347343"}, "eternal": {:hex, :eternal, "1.2.1", "d5b6b2499ba876c57be2581b5b999ee9bdf861c647401066d3eeed111d096bc4", [:mix], [], "hexpm", "b14f1dc204321429479c569cfbe8fb287541184ed040956c8862cb7a677b8406"}, "ex2ms": {:hex, :ex2ms, "1.6.0", "f39bbd9ff1b0f27b3f707bab2d167066dd8965e7df1149b962d94c74615d0e09", [:mix], [], "hexpm", "0d1ab5e08421af5cd69146efb408dbb1ff77f38a2f4df5f086f2512dc8cf65bf"}, "ex_json_schema": {:hex, :ex_json_schema, "0.7.4", "09eb5b0c8184e5702bc89625a9d0c05c7a0a845d382e9f6f406a0fc1c9a8cc3f", [:mix], [], "hexpm", "45c67fa840f0d719a2b5578126dc29bcdc1f92499c0f61bcb8a3bcb5935f9684"}, @@ -69,7 +70,7 @@ "plug_cowboy": {:hex, :plug_cowboy, "2.4.1", "779ba386c0915027f22e14a48919a9545714f849505fa15af2631a0d298abf0f", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d72113b6dff7b37a7d9b2a5b68892808e3a9a752f2bf7e503240945385b70507"}, "plug_crypto": {:hex, :plug_crypto, "1.2.0", "1cb20793aa63a6c619dd18bb33d7a3aa94818e5fd39ad357051a67f26dfa2df6", [:mix], [], "hexpm", "a48b538ae8bf381ffac344520755f3007cc10bd8e90b240af98ea29b69683fc2"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"}, - "postgrex": {:hex, :postgrex, "0.15.3", "5806baa8a19a68c4d07c7a624ccdb9b57e89cbc573f1b98099e3741214746ae4", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "4737ce62a31747b4c63c12b20c62307e51bb4fcd730ca0c32c280991e0606c90"}, + "postgrex": {:hex, :postgrex, "0.15.8", "f5e782bbe5e8fa178d5e3cd1999c857dc48eda95f0a4d7f7bd92a50e84a0d491", [:mix], [{:connection, "~> 1.0", [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]}], "hexpm", "698fbfacea34c4cf22c8281abeb5cf68d99628d541874f085520ab3b53d356fe"}, "quantum": {:hex, :quantum, "2.2.7", "134277fdd2b9173d0bb53cb33b61f8f6cc5de75bd61c2e789850a202f72f9b0f", [:mix], [{:calendar, "~> 0.17", [hex: :calendar, repo: "hexpm", optional: true]}, {:crontab, "~> 1.1", [hex: :crontab, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.12", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:timex, "~> 3.1", [hex: :timex, repo: "hexpm", optional: true]}], "hexpm", "455e0c4f81c8dc3c3c32a7cad202d19452d128b9ee60972f7259ebd218daf191"}, "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"}, "recon": {:hex, :recon, "2.5.0", "2f7fcbec2c35034bade2f9717f77059dc54eb4e929a3049ca7ba6775c0bd66cd", [:mix, :rebar3], [], "hexpm", "72f3840fedd94f06315c523f6cecf5b4827233bed7ae3fe135b2a0ebeab5e196"}, @@ -83,6 +84,7 @@ "slugger": {:hex, :slugger, "0.3.0", "efc667ab99eee19a48913ccf3d038b1fb9f165fa4fbf093be898b8099e61b6ed", [:mix], [], "hexpm", "20d0ded0e712605d1eae6c5b4889581c3460d92623a930ddda91e0e609b5afba"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "statix": {:hex, :statix, "1.4.0", "c822abd1e60e62828e8460e932515d0717aa3c089b44cc3f795d43b94570b3a8", [:mix], [], "hexpm", "507373cc80925a9b6856cb14ba17f6125552434314f6613c907d295a09d1a375"}, + "table_rex": {:hex, :table_rex, "3.0.0", "5189b71b3b92ed461358f40f7b7b630dc37716bf6c8ab3e934b2bc63a99028bd", [:mix], [], "hexpm", "582776d24cbe6a4d30a39a7f02035b1bc979b6cd64923d7234dd2f0ad21a18c7"}, "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.0", "da9d49ee7e6bb1c259d36ce6539cd45ae14d81247a2b0c90edf55e2b50507f7b", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5cfe67ad464b243835512aa44321cee91faed6ea868d7fb761d7016e02915c3d"}, "telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"}, From ec1c3a8160092bb15469e6f25735bf7b761af004 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 12:06:12 -0800 Subject: [PATCH 08/11] lint --- lib/ret_web/plugs/add_csp.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ret_web/plugs/add_csp.ex b/lib/ret_web/plugs/add_csp.ex index dc6697d1e..06f4ce1a0 100644 --- a/lib/ret_web/plugs/add_csp.ex +++ b/lib/ret_web/plugs/add_csp.ex @@ -70,9 +70,11 @@ defmodule RetWeb.Plugs.AddCSP do }:#{janus_port} #{default_janus_csp_rule}" end - "default-src 'none'; manifest-src #{custom_rules[:manifest_src]} 'self'; script-src * 'unsafe-inline' 'unsafe-eval'; child-src #{custom_rules[:child_src]} 'self' blob:; worker-src #{ - custom_rules[:worker_src] - } #{storage_url} #{assets_url} 'self' blob:; font-src #{custom_rules[:font_src]} 'self' https://fonts.googleapis.com https://cdn.jsdelivr.net https://fonts.gstatic.com https://cdn.aframe.io #{ + "default-src 'none'; manifest-src #{custom_rules[:manifest_src]} 'self'; script-src * 'unsafe-inline' 'unsafe-eval'; child-src #{ + custom_rules[:child_src] + } 'self' blob:; worker-src #{custom_rules[:worker_src]} #{storage_url} #{assets_url} 'self' blob:; font-src #{ + custom_rules[:font_src] + } 'self' https://fonts.googleapis.com https://cdn.jsdelivr.net https://fonts.gstatic.com https://cdn.aframe.io #{ storage_url } #{assets_url} #{cors_proxy_url}; style-src #{custom_rules[:style_src]} 'self' https://fonts.googleapis.com https://cdn.jsdelivr.net #{ cors_proxy_url From ad29798c1de401ee58d75d56999dc59d7e30a448 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 12:06:17 -0800 Subject: [PATCH 09/11] Add request logger --- lib/ret_web/endpoint.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ret_web/endpoint.ex b/lib/ret_web/endpoint.ex index e5b128e57..9899cc4c3 100644 --- a/lib/ret_web/endpoint.ex +++ b/lib/ret_web/endpoint.ex @@ -26,6 +26,10 @@ defmodule RetWeb.Endpoint do plug(Phoenix.CodeReloader) end + plug Phoenix.LiveDashboard.RequestLogger, + param_key: "request_logger", + cookie_key: "request_logger" + plug(Plug.RequestId) plug(Plug.Logger) From 52e7b5ed7b9d92e4efdf7d1e0a80d7098e7336a4 Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Tue, 26 Jan 2021 12:16:40 -0800 Subject: [PATCH 10/11] Add absinthe metrics --- lib/ret_web/telemetry.ex | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/ret_web/telemetry.ex b/lib/ret_web/telemetry.ex index dd60dac9c..139d742a5 100644 --- a/lib/ret_web/telemetry.ex +++ b/lib/ret_web/telemetry.ex @@ -43,7 +43,22 @@ defmodule RetWeb.Telemetry do summary("vm.memory.total", unit: {:byte, :kilobyte}), summary("vm.total_run_queue_lengths.total"), summary("vm.total_run_queue_lengths.cpu"), - summary("vm.total_run_queue_lengths.io") + summary("vm.total_run_queue_lengths.io"), + + # Absinthe + # summary("absinthe.execute.operation.start"), + # summary("absinthe.execute.operation.stop"), + # summary("absinthe.subscription.publish.start"), + # summary("absinthe.subscription.publish.stop"), + # summary("absinthe.resolve.field.start"), + # summary("absinthe.resolve.field.stop"), + # summary("absinthe.middleware.batch.start"), + # summary("absinthe.middleware.batch.stop"), + # TODO: Learn how these metrics work + summary("absinthe.execute.operation.stop.duration"), + summary("absinthe.subscription.publish.stop.duration"), + summary("absinthe.resolve.field.stop.duration"), + summary("absinthe.middleware.batch.stop.duration") ] end From 998c5802f03b0886c83ac5d14ab6a5515bb9ad8d Mon Sep 17 00:00:00 2001 From: John Shaughnessy Date: Wed, 24 Feb 2021 09:45:39 -0800 Subject: [PATCH 11/11] Change GET to POST --- lib/ret_web/router.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ret_web/router.ex b/lib/ret_web/router.ex index 6e7b8739f..cb4a82470 100644 --- a/lib/ret_web/router.ex +++ b/lib/ret_web/router.ex @@ -95,7 +95,7 @@ defmodule RetWeb.Router do if(Mix.env() == :prod, do: [:ssl_only, :canonicalize_domain], else: []) ) - get("/api/v1/accounts/expire_cookie", Api.V1.AccountController, :expire_cookie) + post("/api/v1/accounts/expire_cookie", Api.V1.AccountController, :expire_cookie) scope "/" do pipe_through([:admin_required]) @@ -104,7 +104,7 @@ defmodule RetWeb.Router do # https://www.postgresql.org/docs/current/pgstatstatements.html # https://hexdocs.pm/phoenix_live_dashboard/ecto_stats.html#install-custom-extensions live_dashboard "/telemetry", metrics: RetWeb.Telemetry, ecto_repos: [Ret.Repo] - get("/api/v1/accounts/set_cookie", Api.V1.AccountController, :set_cookie) + post("/api/v1/accounts/set_cookie", Api.V1.AccountController, :set_cookie) end end