1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Endpoint.MetricsExporterTest do
6 # Modifies AppEnv, has to stay synchronous
7 use Pleroma.Web.ConnCase
9 alias Pleroma.Web.Endpoint.MetricsExporter
12 Application.get_env(:prometheus, MetricsExporter)
15 describe "with default config" do
16 test "does NOT expose app metrics", %{conn: conn} do
18 |> get(config()[:path])
23 describe "when enabled" do
25 initial_config = config()
26 on_exit(fn -> Application.put_env(:prometheus, MetricsExporter, initial_config) end)
31 Keyword.put(initial_config, :enabled, true)
35 test "serves app metrics", %{conn: conn} do
36 conn = get(conn, config()[:path])
37 assert response = response(conn, 200)
40 "http_requests_total",
41 "http_request_duration_microseconds",
42 "phoenix_controller_call_duration",
43 "telemetry_scrape_duration",
44 "erlang_vm_memory_atom_bytes_total"
46 assert response =~ ~r/#{metric}/
50 test "when IP whitelist configured, " <>
51 "serves app metrics only if client IP is whitelisted",
56 Keyword.put(config(), :ip_whitelist, ["127.127.127.127", {1, 1, 1, 1}, '255.255.255.255'])
60 |> get(config()[:path])
64 |> Map.put(:remote_ip, {127, 127, 127, 127})
65 |> get(config()[:path])