Skip to content

Commit 67eb7e0

Browse files
committed
test with metric that doesn't have project_id on it
1 parent af315bb commit 67eb7e0

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

nexus/tests/integration_tests/metrics.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use nexus_test_utils::background::activate_background_task;
1515
use nexus_test_utils::http_testing::{AuthnMode, NexusRequest, RequestBuilder};
1616
use nexus_test_utils::resource_helpers::{
1717
create_default_ip_pool, create_disk, create_instance, create_project,
18-
objects_list_page_authz, DiskTest,
18+
object_create_error, objects_list_page_authz, DiskTest,
1919
};
2020
use nexus_test_utils::ControlPlaneTestContext;
2121
use nexus_test_utils_macros::nexus_test;
@@ -578,6 +578,13 @@ async fn test_project_timeseries_query(
578578
assert_eq!(result.len(), 1);
579579
assert!(result[0].timeseries().len() > 0);
580580

581+
// also works with project ID
582+
let result =
583+
project_timeseries_query(&cptestctx, &p1.identity.id.to_string(), q1)
584+
.await;
585+
assert_eq!(result.len(), 1);
586+
assert!(result[0].timeseries().len() > 0);
587+
581588
let result = project_timeseries_query(&cptestctx, "project2", q1).await;
582589
assert_eq!(result.len(), 1);
583590
assert!(result[0].timeseries().len() > 0);
@@ -606,19 +613,32 @@ async fn test_project_timeseries_query(
606613
assert_eq!(result.len(), 1);
607614
assert_eq!(result[0].timeseries().len(), 0);
608615

609-
// Query with nonexistent project
610-
// Also test at least once with project ID in path instead of project name
616+
// expect error when querying a metric that has no project_id on it
617+
let q4 = "get integration_target:integration_metric";
618+
let url = "/v1/timeseries/query/project/project1";
619+
let body = nexus_types::external_api::params::TimeseriesQuery {
620+
query: q4.to_string(),
621+
};
622+
let result =
623+
object_create_error(client, url, &body, StatusCode::BAD_REQUEST).await;
624+
assert_eq!(result.error_code.unwrap(), "InvalidRequest");
625+
// Notable that the error confirms that the metric exists and says what the
626+
// fields are. This is helpful generally, but here it would be better if
627+
// we could say something more like "you can't query this timeseries from
628+
// this endpoint"
629+
assert_eq!(result.message, "The filter expression contains identifiers that are not valid for its input timeseries. Invalid identifiers: [\"project_id\", \"silo_id\"], timeseries fields: {\"datum\", \"metric_name\", \"target_name\", \"timestamp\"}");
630+
631+
// nonexistent project
632+
let url = "/v1/timeseries/query/project/nonexistent";
633+
let body = nexus_types::external_api::params::TimeseriesQuery {
634+
query: q4.to_string(),
635+
};
636+
let result =
637+
object_create_error(client, url, &body, StatusCode::NOT_FOUND).await;
638+
assert_eq!(result.message, "not found: project with name \"nonexistent\"");
611639

612640
// try a project in your silo that you can't read
613641
// try a project in another silo
614-
615-
// now try it adversarially — use a project you can read in the path, but
616-
// try to access a fleet metric... if I can find one that will work
617-
618-
// let q4 = "get hardware_component:temperature";
619-
// let result = dbg!(timeseries_query(&cptestctx, q4).await);
620-
// let result =
621-
// dbg!(project_timeseries_query(&cptestctx, "project2", q4).await);
622642
}
623643

624644
#[nexus_test]

0 commit comments

Comments
 (0)