2022-12-16 10:56:17 +00:00
|
|
|
defmodule Pleroma.Web.AkkomaAPI.MetricsControllerTest do
|
2023-08-01 10:43:50 +00:00
|
|
|
use Pleroma.Web.ConnCase, async: false
|
2022-12-16 10:56:17 +00:00
|
|
|
|
|
|
|
describe "GET /api/v1/akkoma/metrics" do
|
|
|
|
test "should return metrics when the user has admin:metrics" do
|
|
|
|
%{conn: conn} = oauth_access(["admin:metrics"])
|
2022-12-16 11:18:14 +00:00
|
|
|
|
2023-01-01 18:32:14 +00:00
|
|
|
Pleroma.PrometheusExporter.gather()
|
|
|
|
|
2022-12-16 11:18:14 +00:00
|
|
|
resp =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/akkoma/metrics")
|
|
|
|
|> text_response(200)
|
2022-12-16 10:56:17 +00:00
|
|
|
|
|
|
|
assert resp =~ "# HELP"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should not allow users that do not have the admin:metrics scope" do
|
|
|
|
%{conn: conn} = oauth_access(["read:metrics"])
|
2022-12-16 11:18:14 +00:00
|
|
|
|
2022-12-16 11:17:04 +00:00
|
|
|
conn
|
2022-12-16 10:56:17 +00:00
|
|
|
|> get("/api/v1/akkoma/metrics")
|
|
|
|
|> json_response(403)
|
|
|
|
end
|
2022-12-16 11:17:04 +00:00
|
|
|
|
|
|
|
test "should be disabled by export_prometheus_metrics" do
|
|
|
|
clear_config([:instance, :export_prometheus_metrics], false)
|
|
|
|
%{conn: conn} = oauth_access(["admin:metrics"])
|
2022-12-16 11:18:14 +00:00
|
|
|
|
2022-12-16 11:17:04 +00:00
|
|
|
conn
|
|
|
|
|> get("/api/v1/akkoma/metrics")
|
|
|
|
|> response(404)
|
|
|
|
end
|
2022-12-16 10:56:17 +00:00
|
|
|
end
|
|
|
|
end
|