1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Endpoint.MetricsExporterTest do
6 use Pleroma.Web.ConnCase
8 alias Pleroma.Web.Endpoint.MetricsExporter
11 Application.get_env(:prometheus, MetricsExporter)
14 describe "with default config" do
15 test "does NOT expose app metrics", %{conn: conn} do
17 |> get(config()[:path])
22 describe "when enabled" do
24 initial_config = config()
25 on_exit(fn -> Application.put_env(:prometheus, MetricsExporter, initial_config) end)
30 Keyword.put(initial_config, :enabled, true)
34 test "serves app metrics", %{conn: conn} do
35 conn = get(conn, config()[:path])
36 assert response = response(conn, 200)
39 "http_requests_total",
40 "http_request_duration_microseconds",
41 "phoenix_controller_call_duration",
42 "telemetry_scrape_duration",
43 "erlang_vm_memory_atom_bytes_total"
45 assert response =~ ~r/#{metric}/
49 test "when IP whitelist configured, " <>
50 "serves app metrics only if client IP is whitelisted",
55 Keyword.put(config(), :ip_whitelist, ["127.127.127.127", {1, 1, 1, 1}, '255.255.255.255'])
59 |> get(config()[:path])
63 |> Map.put(:remote_ip, {127, 127, 127, 127})
64 |> get(config()[:path])