logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

logger.ex (2871B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Telemetry.Logger do
  5. @moduledoc "Transforms Pleroma telemetry events to logs"
  6. require Logger
  7. @events [
  8. [:pleroma, :connection_pool, :reclaim, :start],
  9. [:pleroma, :connection_pool, :reclaim, :stop],
  10. [:pleroma, :connection_pool, :provision_failure],
  11. [:pleroma, :connection_pool, :client, :dead],
  12. [:pleroma, :connection_pool, :client, :add]
  13. ]
  14. def attach do
  15. :telemetry.attach_many("pleroma-logger", @events, &handle_event/4, [])
  16. end
  17. # Passing anonymous functions instead of strings to logger is intentional,
  18. # that way strings won't be concatenated if the message is going to be thrown
  19. # out anyway due to higher log level configured
  20. def handle_event(
  21. [:pleroma, :connection_pool, :reclaim, :start],
  22. _,
  23. %{max_connections: max_connections, reclaim_max: reclaim_max},
  24. _
  25. ) do
  26. Logger.debug(fn ->
  27. "Connection pool is exhausted (reached #{max_connections} connections). Starting idle connection cleanup to reclaim as much as #{reclaim_max} connections"
  28. end)
  29. end
  30. def handle_event(
  31. [:pleroma, :connection_pool, :reclaim, :stop],
  32. %{reclaimed_count: 0},
  33. _,
  34. _
  35. ) do
  36. Logger.error(fn ->
  37. "Connection pool failed to reclaim any connections due to all of them being in use. It will have to drop requests for opening connections to new hosts"
  38. end)
  39. end
  40. def handle_event(
  41. [:pleroma, :connection_pool, :reclaim, :stop],
  42. %{reclaimed_count: reclaimed_count},
  43. _,
  44. _
  45. ) do
  46. Logger.debug(fn -> "Connection pool cleaned up #{reclaimed_count} idle connections" end)
  47. end
  48. def handle_event(
  49. [:pleroma, :connection_pool, :provision_failure],
  50. %{opts: [key | _]},
  51. _,
  52. _
  53. ) do
  54. Logger.debug(fn ->
  55. "Connection pool had to refuse opening a connection to #{key} due to connection limit exhaustion"
  56. end)
  57. end
  58. def handle_event(
  59. [:pleroma, :connection_pool, :client, :dead],
  60. %{client_pid: client_pid, reason: reason},
  61. %{key: key},
  62. _
  63. ) do
  64. Logger.warning(fn ->
  65. "Pool worker for #{key}: Client #{inspect(client_pid)} died before releasing the connection with #{inspect(reason)}"
  66. end)
  67. end
  68. def handle_event(
  69. [:pleroma, :connection_pool, :client, :add],
  70. %{clients: [_, _ | _] = clients},
  71. %{key: key, protocol: :http},
  72. _
  73. ) do
  74. Logger.debug(fn ->
  75. "Pool worker for #{key}: #{length(clients)} clients are using an HTTP1 connection at the same time, head-of-line blocking might occur."
  76. end)
  77. end
  78. def handle_event([:pleroma, :connection_pool, :client, :add], _, _, _), do: :ok
  79. end