From 8a986ea4fd2cd90b159585b8a2c7e6ee7f23ebcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Coss=C3=ADo?= Date: Fri, 26 Apr 2024 08:08:18 -0400 Subject: [PATCH] Issues API: Enable `GET /issues` endpoint (#4118) * enable `GET /issues` endpoint * add access test --- docs/redoc/master/openapi.json | 25 +++++++++++++++++++ openapi/openapi-service.ytt.yaml | 16 ++++++++++++ src/actix/api/issues_api.rs | 19 ++++++++++---- src/actix/mod.rs | 2 ++ .../auth_tests/test_jwt_access.py | 5 ++++ tests/openapi_consistency_check.sh | 2 +- 6 files changed, 63 insertions(+), 6 deletions(-) diff --git a/docs/redoc/master/openapi.json b/docs/redoc/master/openapi.json index 79f7978b4f..6263412124 100644 --- a/docs/redoc/master/openapi.json +++ b/docs/redoc/master/openapi.json @@ -522,6 +522,31 @@ } } }, + "/issues": { + "get": { + "summary": "Get issues", + "description": "Get a report of performance issues and configuration suggestions", + "operationId": "get_issues", + "tags": [ + "beta" + ], + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "4XX": { + "description": "error" + } + } + } + }, "/cluster": { "get": { "tags": [ diff --git a/openapi/openapi-service.ytt.yaml b/openapi/openapi-service.ytt.yaml index 242559e17f..587995c8d0 100644 --- a/openapi/openapi-service.ytt.yaml +++ b/openapi/openapi-service.ytt.yaml @@ -137,3 +137,19 @@ paths: "4XX": description: error + /issues: + get: + summary: Get issues + description: Get a report of performance issues and configuration suggestions + operationId: get_issues + tags: + - beta + responses: + "200": + description: Successful response + content: + application/json: + schema: + type: object + "4XX": + description: error diff --git a/src/actix/api/issues_api.rs b/src/actix/api/issues_api.rs index 11a2ab989d..89c0c6cfae 100644 --- a/src/actix/api/issues_api.rs +++ b/src/actix/api/issues_api.rs @@ -1,14 +1,23 @@ use actix_web::rt::time::Instant; -use actix_web::{get, Responder}; +use actix_web::{get, web, Responder}; use collection::operations::types::IssuesReport; +use storage::rbac::AccessRequirements; +use crate::actix::auth::ActixAccess; use crate::actix::helpers::process_response; #[get("/issues")] -async fn get_collections() -> impl Responder { +async fn get_issues(ActixAccess(access): ActixAccess) -> impl Responder { let timing = Instant::now(); - let response = Ok(IssuesReport { - issues: issues::all_issues(), - }); + let response = access + .check_global_access(AccessRequirements::new().manage()) + .map(|_| IssuesReport { + issues: issues::all_issues(), + }); process_response(response, timing) } + +// Configure services +pub fn config_issues_api(cfg: &mut web::ServiceConfig) { + cfg.service(get_issues); +} diff --git a/src/actix/mod.rs b/src/actix/mod.rs index 22cd3caadd..d45523fd8e 100644 --- a/src/actix/mod.rs +++ b/src/actix/mod.rs @@ -25,6 +25,7 @@ use crate::actix::api::cluster_api::config_cluster_api; use crate::actix::api::collections_api::config_collections_api; use crate::actix::api::count_api::count_points; use crate::actix::api::discovery_api::config_discovery_api; +use crate::actix::api::issues_api::config_issues_api; use crate::actix::api::recommend_api::config_recommend_api; use crate::actix::api::retrieve_api::{get_point, get_points, scroll_points}; use crate::actix::api::search_api::config_search_api; @@ -161,6 +162,7 @@ pub fn init( .configure(config_recommend_api) .configure(config_discovery_api) .configure(config_shards_api) + .configure(config_issues_api) // Ordering of services is important for correct path pattern matching // See: .service(scroll_points) diff --git a/tests/consensus_tests/auth_tests/test_jwt_access.py b/tests/consensus_tests/auth_tests/test_jwt_access.py index 5a0c428c21..0145d26c0b 100644 --- a/tests/consensus_tests/auth_tests/test_jwt_access.py +++ b/tests/consensus_tests/auth_tests/test_jwt_access.py @@ -533,6 +533,7 @@ ACTION_ACCESS = { "metrics": EndpointAccess(True, False, True, "GET /metrics", coll_r=False), "post_locks": EndpointAccess(False, False, True, "POST /locks"), "get_locks": EndpointAccess(True, False, True, "GET /locks", coll_r=False), + "get_issues": EndpointAccess(False, False, True, "GET /issues"), } @@ -1734,3 +1735,7 @@ def test_post_locks(): def test_get_locks(): check_access("get_locks") + + +def test_get_issues(): + check_access("get_issues") diff --git a/tests/openapi_consistency_check.sh b/tests/openapi_consistency_check.sh index ee3cb0f12f..f3a8ae8d2c 100755 --- a/tests/openapi_consistency_check.sh +++ b/tests/openapi_consistency_check.sh @@ -36,7 +36,7 @@ fi rm -f ./docs/redoc/master/.diff.openapi.json NUMBER_OF_APIS=$(cat ./docs/redoc/master/openapi.json | jq '.paths | length') -EXPECTED_NUMBER_OF_APIS=50 +EXPECTED_NUMBER_OF_APIS=51 if [ "$NUMBER_OF_APIS" -ne "$EXPECTED_NUMBER_OF_APIS" ]; then echo "ERROR: It looks like the total number of APIs has changed."