Remove Quack logging backend

This commit is contained in:
Mark Felder 2022-11-11 11:39:43 -05:00
parent 39a96876ef
commit 6b87b3f2ea
11 changed files with 47 additions and 120 deletions

View File

@ -160,11 +160,6 @@ config :logger, :ex_syslogger,
format: "$metadata[$level] $message", format: "$metadata[$level] $message",
metadata: [:request_id] metadata: [:request_id]
config :quack,
level: :warn,
meta: [:all],
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
config :mime, :types, %{ config :mime, :types, %{
"application/xml" => ["xml"], "application/xml" => ["xml"],
"application/xrd+xml" => ["xrd+xml"], "application/xrd+xml" => ["xrd+xml"],

View File

@ -1190,45 +1190,6 @@ config :pleroma, :config_description, [
} }
] ]
}, },
%{
group: :quack,
type: :group,
label: "Quack Logger",
description: "Quack-related settings",
children: [
%{
key: :level,
type: {:dropdown, :atom},
description: "Log level",
suggestions: [:debug, :info, :warn, :error]
},
%{
key: :meta,
type: {:list, :atom},
description: "Configure which metadata you want to report on",
suggestions: [
:application,
:module,
:file,
:function,
:line,
:pid,
:crash_reason,
:initial_call,
:registered_name,
:all,
:none
]
},
%{
key: :webhook_url,
label: "Webhook URL",
type: :string,
description: "Configure the Slack incoming webhook",
suggestions: ["https://hooks.slack.com/services/YOUR-KEY-HERE"]
}
]
},
%{ %{
group: :pleroma, group: :pleroma,
key: :frontend_configurations, key: :frontend_configurations,

View File

@ -47,7 +47,7 @@ defmodule Pleroma.Config.TransferTask do
{logger, other} = {logger, other} =
(Repo.all(ConfigDB) ++ deleted_settings) (Repo.all(ConfigDB) ++ deleted_settings)
|> Enum.map(&merge_with_default/1) |> Enum.map(&merge_with_default/1)
|> Enum.split_with(fn {group, _, _, _} -> group in [:logger, :quack] end) |> Enum.split_with(fn {group, _, _, _} -> group in [:logger] end)
logger logger
|> Enum.sort() |> Enum.sort()
@ -104,11 +104,6 @@ defmodule Pleroma.Config.TransferTask do
end end
# change logger configuration in runtime, without restart # change logger configuration in runtime, without restart
defp configure({:quack, key, _, merged}) do
Logger.configure_backend(Quack.Logger, [{key, merged}])
:ok = update_env(:quack, key, merged)
end
defp configure({_, :backends, _, merged}) do defp configure({_, :backends, _, merged}) do
# removing current backends # removing current backends
Enum.each(Application.get_env(:logger, :backends), &Logger.remove_backend/1) Enum.each(Application.get_env(:logger, :backends), &Logger.remove_backend/1)

View File

@ -163,7 +163,6 @@ defmodule Pleroma.ConfigDB do
defp only_full_update?(%ConfigDB{group: group, key: key}) do defp only_full_update?(%ConfigDB{group: group, key: key}) do
full_key_update = [ full_key_update = [
{:pleroma, :ecto_repos}, {:pleroma, :ecto_repos},
{:quack, :meta},
{:mime, :types}, {:mime, :types},
{:cors_plug, [:max_age, :methods, :expose, :headers]}, {:cors_plug, [:max_age, :methods, :expose, :headers]},
{:swarm, :node_blacklist}, {:swarm, :node_blacklist},
@ -386,7 +385,7 @@ defmodule Pleroma.ConfigDB do
@spec module_name?(String.t()) :: boolean() @spec module_name?(String.t()) :: boolean()
def module_name?(string) do def module_name?(string) do
Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Quack|Ueberauth|Swoosh)\./, string) or Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Ueberauth|Swoosh)\./, string) or
string in ["Oban", "Ueberauth", "ExSyslogger", "ConcurrentLimiter"] string in ["Oban", "Ueberauth", "ExSyslogger", "ConcurrentLimiter"]
end end
end end

View File

@ -76,7 +76,6 @@ defmodule Pleroma.Mixfile do
:logger, :logger,
:runtime_tools, :runtime_tools,
:comeonin, :comeonin,
:quack,
:fast_sanitize, :fast_sanitize,
:os_mon, :os_mon,
:ssl, :ssl,
@ -177,7 +176,6 @@ defmodule Pleroma.Mixfile do
branch: "no-logging"}, branch: "no-logging"},
{:prometheus_ecto, "~> 1.4"}, {:prometheus_ecto, "~> 1.4"},
{:recon, "~> 2.5"}, {:recon, "~> 2.5"},
{:quack, "~> 0.1.1"},
{:joken, "~> 2.0"}, {:joken, "~> 2.0"},
{:benchee, "~> 1.0"}, {:benchee, "~> 1.0"},
{:pot, "~> 1.0"}, {:pot, "~> 1.0"},

View File

@ -8,8 +8,6 @@ config :pleroma, :first_setting, key: "value", key2: [Pleroma.Repo]
config :pleroma, :second_setting, key: "value2", key2: ["Activity"] config :pleroma, :second_setting, key: "value2", key2: ["Activity"]
config :quack, level: :info
config :pleroma, Pleroma.Repo, pool: Ecto.Adapters.SQL.Sandbox config :pleroma, Pleroma.Repo, pool: Ecto.Adapters.SQL.Sandbox
config :postgrex, :json_library, Poison config :postgrex, :json_library, Poison

View File

@ -49,7 +49,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
describe "migrate_to_db/1" do describe "migrate_to_db/1" do
setup do setup do
clear_config(:configurable_from_database, true) clear_config(:configurable_from_database, true)
clear_config([:quack, :level])
end end
@tag capture_log: true @tag capture_log: true
@ -72,14 +71,12 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"}) config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"}) config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"}) refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
refute ConfigDB.get_by_params(%{group: ":postgrex", key: ":json_library"}) refute ConfigDB.get_by_params(%{group: ":postgrex", key: ":json_library"})
refute ConfigDB.get_by_params(%{group: ":pleroma", key: ":database"}) refute ConfigDB.get_by_params(%{group: ":pleroma", key: ":database"})
assert config1.value == [key: "value", key2: [Repo]] assert config1.value == [key: "value", key2: [Repo]]
assert config2.value == [key: "value2", key2: ["Activity"]] assert config2.value == [key: "value2", key2: ["Activity"]]
assert config3.value == :info
end end
test "config table is truncated before migration" do test "config table is truncated before migration" do
@ -108,7 +105,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"]) insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"])
insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo]) insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo])
insert_config_record(:quack, :level, :info)
MixTask.run(["migrate_from_db", "--env", "temp", "-d"]) MixTask.run(["migrate_from_db", "--env", "temp", "-d"])
@ -117,7 +113,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(temp_file) file = File.read!(temp_file)
assert file =~ "config :pleroma, :setting_first," assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second," assert file =~ "config :pleroma, :setting_second,"
assert file =~ "config :quack, :level, :info"
end end
test "load a settings with large values and pass to file", %{temp_file: temp_file} do test "load a settings with large values and pass to file", %{temp_file: temp_file} do
@ -199,7 +194,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
setup do setup do
insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"]) insert_config_record(:pleroma, :setting_first, key: "value", key2: ["Activity"])
insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo]) insert_config_record(:pleroma, :setting_second, key: "value2", key2: [Repo])
insert_config_record(:quack, :level, :info)
path = "test/instance_static" path = "test/instance_static"
file_path = Path.join(path, "temp.exported_from_db.secret.exs") file_path = Path.join(path, "temp.exported_from_db.secret.exs")
@ -215,7 +209,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(file_path) file = File.read!(file_path)
assert file =~ "config :pleroma, :setting_first," assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second," assert file =~ "config :pleroma, :setting_second,"
assert file =~ "config :quack, :level, :info"
end end
test "release", %{file_path: file_path} do test "release", %{file_path: file_path} do
@ -227,7 +220,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
file = File.read!(file_path) file = File.read!(file_path)
assert file =~ "config :pleroma, :setting_first," assert file =~ "config :pleroma, :setting_first,"
assert file =~ "config :pleroma, :setting_second," assert file =~ "config :pleroma, :setting_second,"
assert file =~ "config :quack, :level, :info"
end end
end end

View File

@ -11,7 +11,6 @@ defmodule Pleroma.Config.LoaderTest do
config = Loader.read("test/fixtures/config/temp.secret.exs") config = Loader.read("test/fixtures/config/temp.secret.exs")
assert config[:pleroma][:first_setting][:key] == "value" assert config[:pleroma][:first_setting][:key] == "value"
assert config[:pleroma][:first_setting][:key2] == [Pleroma.Repo] assert config[:pleroma][:first_setting][:key2] == [Pleroma.Repo]
assert config[:quack][:level] == :info
end end
test "filter_group/2" do test "filter_group/2" do

View File

@ -15,13 +15,11 @@ defmodule Pleroma.Config.TransferTaskTest do
test "transfer config values from db to env" do test "transfer config values from db to env" do
refute Application.get_env(:pleroma, :test_key) refute Application.get_env(:pleroma, :test_key)
refute Application.get_env(:idna, :test_key) refute Application.get_env(:idna, :test_key)
refute Application.get_env(:quack, :test_key)
refute Application.get_env(:postgrex, :test_key) refute Application.get_env(:postgrex, :test_key)
initial = Application.get_env(:logger, :level) initial = Application.get_env(:logger, :level)
insert(:config, key: :test_key, value: [live: 2, com: 3]) insert(:config, key: :test_key, value: [live: 2, com: 3])
insert(:config, group: :idna, key: :test_key, value: [live: 15, com: 35]) insert(:config, group: :idna, key: :test_key, value: [live: 15, com: 35])
insert(:config, group: :quack, key: :test_key, value: [:test_value1, :test_value2])
insert(:config, group: :postgrex, key: :test_key, value: :value) insert(:config, group: :postgrex, key: :test_key, value: :value)
insert(:config, group: :logger, key: :level, value: :debug) insert(:config, group: :logger, key: :level, value: :debug)
@ -29,36 +27,32 @@ defmodule Pleroma.Config.TransferTaskTest do
assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3] assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
assert Application.get_env(:idna, :test_key) == [live: 15, com: 35] assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
assert Application.get_env(:logger, :level) == :debug assert Application.get_env(:logger, :level) == :debug
assert Application.get_env(:postgrex, :test_key) == :value assert Application.get_env(:postgrex, :test_key) == :value
on_exit(fn -> on_exit(fn ->
Application.delete_env(:pleroma, :test_key) Application.delete_env(:pleroma, :test_key)
Application.delete_env(:idna, :test_key) Application.delete_env(:idna, :test_key)
Application.delete_env(:quack, :test_key)
Application.delete_env(:postgrex, :test_key) Application.delete_env(:postgrex, :test_key)
Application.put_env(:logger, :level, initial) Application.put_env(:logger, :level, initial)
end) end)
end end
test "transfer config values for 1 group and some keys" do test "transfer config values for 1 group and some keys" do
level = Application.get_env(:quack, :level) level = Application.get_env(:somegroup, :level)
meta = Application.get_env(:quack, :meta) meta = Application.get_env(:somegroup, :meta)
insert(:config, group: :quack, key: :level, value: :info) insert(:config, group: :somegroup, key: :level, value: :info)
insert(:config, group: :quack, key: :meta, value: [:none]) insert(:config, group: :somegroup, key: :meta, value: [:none])
TransferTask.start_link([]) TransferTask.start_link([])
assert Application.get_env(:quack, :level) == :info assert Application.get_env(:somegroup, :level) == :info
assert Application.get_env(:quack, :meta) == [:none] assert Application.get_env(:somegroup, :meta) == [:none]
default = Pleroma.Config.Holder.default_config(:quack, :webhook_url)
assert Application.get_env(:quack, :webhook_url) == default
on_exit(fn -> on_exit(fn ->
Application.put_env(:quack, :level, level) Application.put_env(:somegroup, :level, level)
Application.put_env(:quack, :meta, meta) Application.put_env(:somegroup, :meta, meta)
end) end)
end end

View File

@ -16,13 +16,13 @@ defmodule Pleroma.ConfigDBTest do
test "get_all_as_keyword/0" do test "get_all_as_keyword/0" do
saved = insert(:config) saved = insert(:config)
insert(:config, group: ":quack", key: ":level", value: :info) insert(:config, group: ":goose", key: ":level", value: :info)
insert(:config, group: ":quack", key: ":meta", value: [:none]) insert(:config, group: ":goose", key: ":meta", value: [:none])
insert(:config, insert(:config,
group: ":quack", group: ":goose",
key: ":webhook_url", key: ":webhook_url",
value: "https://hooks.slack.com/services/KEY/some_val" value: "https://gander.com/"
) )
config = ConfigDB.get_all_as_keyword() config = ConfigDB.get_all_as_keyword()
@ -31,9 +31,9 @@ defmodule Pleroma.ConfigDBTest do
{saved.key, saved.value} {saved.key, saved.value}
] ]
assert config[:quack][:level] == :info assert config[:goose][:level] == :info
assert config[:quack][:meta] == [:none] assert config[:goose][:meta] == [:none]
assert config[:quack][:webhook_url] == "https://hooks.slack.com/services/KEY/some_val" assert config[:goose][:webhook_url] == "https://gander.com/"
end end
describe "update_or_create/1" do describe "update_or_create/1" do
@ -267,10 +267,6 @@ defmodule Pleroma.ConfigDBTest do
assert ConfigDB.to_elixir_types("ExSyslogger") == ExSyslogger assert ConfigDB.to_elixir_types("ExSyslogger") == ExSyslogger
end end
test "Quack.Logger module" do
assert ConfigDB.to_elixir_types("Quack.Logger") == Quack.Logger
end
test "Swoosh.Adapters modules" do test "Swoosh.Adapters modules" do
assert ConfigDB.to_elixir_types("Swoosh.Adapters.SMTP") == Swoosh.Adapters.SMTP assert ConfigDB.to_elixir_types("Swoosh.Adapters.SMTP") == Swoosh.Adapters.SMTP
assert ConfigDB.to_elixir_types("Swoosh.Adapters.AmazonSES") == Swoosh.Adapters.AmazonSES assert ConfigDB.to_elixir_types("Swoosh.Adapters.AmazonSES") == Swoosh.Adapters.AmazonSES

View File

@ -317,14 +317,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end end
test "save configs setting without explicit key", %{conn: conn} do test "save configs setting without explicit key", %{conn: conn} do
level = Application.get_env(:quack, :level) adapter = Application.get_env(:http, :adapter)
meta = Application.get_env(:quack, :meta) send_user_agent = Application.get_env(:http, :send_user_agent)
webhook_url = Application.get_env(:quack, :webhook_url) user_agent = Application.get_env(:http, :user_agent)
on_exit(fn -> on_exit(fn ->
Application.put_env(:quack, :level, level) Application.put_env(:http, :adapter, adapter)
Application.put_env(:quack, :meta, meta) Application.put_env(:http, :send_user_agent, send_user_agent)
Application.put_env(:quack, :webhook_url, webhook_url) Application.put_env(:http, :user_agent, user_agent)
end) end)
conn = conn =
@ -333,19 +333,19 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|> post("/api/pleroma/admin/config", %{ |> post("/api/pleroma/admin/config", %{
configs: [ configs: [
%{ %{
group: ":quack", group: ":http",
key: ":level", key: ":adapter",
value: ":info" value: [":someval"]
}, },
%{ %{
group: ":quack", group: ":http",
key: ":meta", key: ":send_user_agent",
value: [":none"] value: true
}, },
%{ %{
group: ":quack", group: ":http",
key: ":webhook_url", key: ":user_agent",
value: "https://hooks.slack.com/services/KEY" value: [":default"]
} }
] ]
}) })
@ -353,30 +353,30 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
assert json_response_and_validate_schema(conn, 200) == %{ assert json_response_and_validate_schema(conn, 200) == %{
"configs" => [ "configs" => [
%{ %{
"group" => ":quack", "group" => ":http",
"key" => ":level", "key" => ":adapter",
"value" => ":info", "value" => [":someval"],
"db" => [":level"] "db" => [":adapter"]
}, },
%{ %{
"group" => ":quack", "group" => ":http",
"key" => ":meta", "key" => ":send_user_agent",
"value" => [":none"], "value" => true,
"db" => [":meta"] "db" => [":send_user_agent"]
}, },
%{ %{
"group" => ":quack", "group" => ":http",
"key" => ":webhook_url", "key" => ":user_agent",
"value" => "https://hooks.slack.com/services/KEY", "value" => [":default"],
"db" => [":webhook_url"] "db" => [":user_agent"]
} }
], ],
"need_reboot" => false "need_reboot" => false
} }
assert Application.get_env(:quack, :level) == :info assert Application.get_env(:http, :adapter) == [:someval]
assert Application.get_env(:quack, :meta) == [:none] assert Application.get_env(:http, :send_user_agent) == true
assert Application.get_env(:quack, :webhook_url) == "https://hooks.slack.com/services/KEY" assert Application.get_env(:http, :user_agent) == [:default]
end end
test "saving config with partial update", %{conn: conn} do test "saving config with partial update", %{conn: conn} do