fix the tests and add tests on the experimental features

This commit is contained in:
Tamo 2024-02-05 14:05:24 +01:00 committed by Louis Dureuil
parent 7793ba67a4
commit e23ec4886d
No known key found for this signature in database
8 changed files with 50 additions and 6 deletions

View File

@ -48,8 +48,8 @@ impl RoFeatures {
Ok(()) Ok(())
} else { } else {
Err(FeatureNotEnabledError { Err(FeatureNotEnabledError {
disabled_action: "Getting logs", disabled_action: "getting logs through the `/logs` route",
feature: "logsRoute", feature: "logs route",
/// Update the discussion link /// Update the discussion link
issue_link: "https://github.com/meilisearch/product/discussions/625", issue_link: "https://github.com/meilisearch/product/discussions/625",
} }
@ -95,6 +95,7 @@ impl FeatureData {
runtime_features_db.get(&txn, EXPERIMENTAL_FEATURES)?.unwrap_or_default(); runtime_features_db.get(&txn, EXPERIMENTAL_FEATURES)?.unwrap_or_default();
let runtime = Arc::new(RwLock::new(RuntimeTogglableFeatures { let runtime = Arc::new(RwLock::new(RuntimeTogglableFeatures {
metrics: instance_features.metrics || persisted_features.metrics, metrics: instance_features.metrics || persisted_features.metrics,
logs_route: instance_features.logs_route || persisted_features.logs_route,
..persisted_features ..persisted_features
})); }));

View File

@ -12,4 +12,5 @@ pub struct RuntimeTogglableFeatures {
#[derive(Default, Debug, Clone, Copy)] #[derive(Default, Debug, Clone, Copy)]
pub struct InstanceTogglableFeatures { pub struct InstanceTogglableFeatures {
pub metrics: bool, pub metrics: bool,
pub logs_route: bool,
} }

View File

@ -538,7 +538,10 @@ impl Opt {
} }
pub(crate) fn to_instance_features(&self) -> InstanceTogglableFeatures { pub(crate) fn to_instance_features(&self) -> InstanceTogglableFeatures {
InstanceTogglableFeatures { metrics: self.experimental_enable_metrics } InstanceTogglableFeatures {
metrics: self.experimental_enable_metrics,
logs_route: self.experimental_enable_logs_route,
}
} }
} }

View File

@ -1847,6 +1847,7 @@ async fn import_dump_v6_containing_experimental_features() {
{ {
"vectorStore": false, "vectorStore": false,
"metrics": false, "metrics": false,
"logsRoute": false,
"exportPuffinReports": false "exportPuffinReports": false
} }
"###); "###);

View File

@ -20,6 +20,7 @@ async fn experimental_features() {
{ {
"vectorStore": false, "vectorStore": false,
"metrics": false, "metrics": false,
"logsRoute": false,
"exportPuffinReports": false "exportPuffinReports": false
} }
"###); "###);
@ -31,6 +32,7 @@ async fn experimental_features() {
{ {
"vectorStore": true, "vectorStore": true,
"metrics": false, "metrics": false,
"logsRoute": false,
"exportPuffinReports": false "exportPuffinReports": false
} }
"###); "###);
@ -42,6 +44,7 @@ async fn experimental_features() {
{ {
"vectorStore": true, "vectorStore": true,
"metrics": false, "metrics": false,
"logsRoute": false,
"exportPuffinReports": false "exportPuffinReports": false
} }
"###); "###);
@ -54,6 +57,7 @@ async fn experimental_features() {
{ {
"vectorStore": true, "vectorStore": true,
"metrics": false, "metrics": false,
"logsRoute": false,
"exportPuffinReports": false "exportPuffinReports": false
} }
"###); "###);
@ -66,6 +70,7 @@ async fn experimental_features() {
{ {
"vectorStore": true, "vectorStore": true,
"metrics": false, "metrics": false,
"logsRoute": false,
"exportPuffinReports": false "exportPuffinReports": false
} }
"###); "###);
@ -85,6 +90,7 @@ async fn experimental_feature_metrics() {
{ {
"vectorStore": false, "vectorStore": false,
"metrics": true, "metrics": true,
"logsRoute": false,
"exportPuffinReports": false "exportPuffinReports": false
} }
"###); "###);
@ -140,7 +146,7 @@ async fn errors() {
meili_snap::snapshot!(code, @"400 Bad Request"); meili_snap::snapshot!(code, @"400 Bad Request");
meili_snap::snapshot!(meili_snap::json_string!(response), @r###" meili_snap::snapshot!(meili_snap::json_string!(response), @r###"
{ {
"message": "Unknown field `NotAFeature`: expected one of `vectorStore`, `metrics`, `exportPuffinReports`", "message": "Unknown field `NotAFeature`: expected one of `vectorStore`, `metrics`, `logsRoute`, `exportPuffinReports`",
"code": "bad_request", "code": "bad_request",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#bad_request" "link": "https://docs.meilisearch.com/errors#bad_request"

View File

@ -96,3 +96,30 @@ async fn logs_bad_mode() {
} }
"###); "###);
} }
#[actix_rt::test]
async fn logs_without_enabling_the_route() {
let server = Server::new().await;
let (response, code) = server.service.post("/logs", json!({})).await;
snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###"
{
"message": "getting logs through the `/logs` route requires enabling the `logs route` experimental feature. See https://github.com/meilisearch/product/discussions/625",
"code": "feature_not_enabled",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#feature_not_enabled"
}
"###);
let (response, code) = server.service.delete("/logs").await;
snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###"
{
"message": "getting logs through the `/logs` route requires enabling the `logs route` experimental feature. See https://github.com/meilisearch/product/discussions/625",
"code": "feature_not_enabled",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#feature_not_enabled"
}
"###);
}

View File

@ -16,8 +16,12 @@ use crate::json;
#[actix_web::test] #[actix_web::test]
async fn basic_test_log_route() { async fn basic_test_log_route() {
let db_path = tempfile::tempdir().unwrap(); let db_path = tempfile::tempdir().unwrap();
let server = let server = Server::new_with_options(Opt {
Server::new_with_options(Opt { ..default_settings(db_path.path()) }).await.unwrap(); experimental_enable_logs_route: true,
..default_settings(db_path.path())
})
.await
.unwrap();
let (route_layer, route_layer_handle) = let (route_layer, route_layer_handle) =
tracing_subscriber::reload::Layer::new(None.with_filter( tracing_subscriber::reload::Layer::new(None.with_filter(

View File

@ -15,6 +15,7 @@ async fn index_with_documents<'a>(server: &'a Server, documents: &Value) -> Inde
{ {
"vectorStore": true, "vectorStore": true,
"metrics": false, "metrics": false,
"logsRoute": false,
"exportPuffinReports": false "exportPuffinReports": false
} }
"###); "###);