@@ -11,6 +11,7 @@ use chrono::Utc;
11
11
use dropshot:: test_util:: ClientTestContext ;
12
12
use dropshot:: ResultsPage ;
13
13
use http:: { Method , StatusCode } ;
14
+ use nexus_test_utils:: background:: activate_background_task;
14
15
use nexus_test_utils:: http_testing:: { AuthnMode , NexusRequest , RequestBuilder } ;
15
16
use nexus_test_utils:: resource_helpers:: {
16
17
create_default_ip_pool, create_disk, create_instance, create_project,
@@ -298,7 +299,7 @@ pub async fn project_timeseries_query(
298
299
) -> Vec < oxql_types:: Table > {
299
300
execute_timeseries_query (
300
301
cptestctx,
301
- & format ! ( "/v1/timeseries/query/projects /{}" , project) ,
302
+ & format ! ( "/v1/timeseries/query/project /{}" , project) ,
302
303
query,
303
304
)
304
305
. await
@@ -554,33 +555,70 @@ async fn test_project_timeseries_query(
554
555
) {
555
556
let client = & cptestctx. external_client ;
556
557
558
+ create_default_ip_pool ( & client) . await ; // needed for instance create to work
559
+
557
560
// Create two projects
558
- let project1 = create_project ( & client, "project1" ) . await ;
559
- let project2 = create_project ( & client, "project2" ) . await ;
561
+ let p1 = create_project ( & client, "project1" ) . await ;
562
+ let _p2 = create_project ( & client, "project2" ) . await ;
560
563
561
564
// Create resources in each project
562
- create_instance ( & client, "project1" , "instance1" ) . await ;
563
- create_instance ( & client, "project2" , "instance2" ) . await ;
565
+ let i1 = create_instance ( & client, "project1" , "instance1" ) . await ;
566
+ let _i2 = create_instance ( & client, "project2" , "instance2" ) . await ;
564
567
565
- // Force a metrics collection
566
- cptestctx. oximeter . force_collect ( ) . await ;
568
+ let internal_client = & cptestctx. internal_client ;
567
569
568
- // Query for project1
569
- let query1 = "get virtual_machine:check" ; // TODO: add project to query
570
- let result1 =
571
- project_timeseries_query ( & cptestctx, "project1" , query1) . await ;
570
+ // get the instance metrics to show up
571
+ let _ =
572
+ activate_background_task ( & internal_client, "instance_watcher" ) . await ;
572
573
573
- // shouldn't work
574
- let result1 =
575
- project_timeseries_query ( & cptestctx, "project2" , query1) . await ;
574
+ // Query with no project specified
575
+ let q1 = "get virtual_machine:check" ;
576
576
577
- // Query for project2
578
- let query2 = "get virtual_machine:check" ;
579
- let result2 =
580
- project_timeseries_query ( & cptestctx, "project2" , query2) . await ;
577
+ let result = project_timeseries_query ( & cptestctx, "project1" , q1) . await ;
578
+ assert_eq ! ( result. len( ) , 1 ) ;
579
+ assert ! ( result[ 0 ] . timeseries( ) . len( ) > 0 ) ;
580
+
581
+ let result = project_timeseries_query ( & cptestctx, "project2" , q1) . await ;
582
+ assert_eq ! ( result. len( ) , 1 ) ;
583
+ assert ! ( result[ 0 ] . timeseries( ) . len( ) > 0 ) ;
584
+
585
+ // with project specified
586
+ let q2 = & format ! ( "{} | filter project_id == \" {}\" " , q1, p1. identity. id) ;
587
+
588
+ let result = project_timeseries_query ( & cptestctx, "project1" , q2) . await ;
589
+ assert_eq ! ( result. len( ) , 1 ) ;
590
+ assert ! ( result[ 0 ] . timeseries( ) . len( ) > 0 ) ;
591
+
592
+ let result = project_timeseries_query ( & cptestctx, "project2" , q2) . await ;
593
+ assert_eq ! ( result. len( ) , 1 ) ;
594
+ assert_eq ! ( result[ 0 ] . timeseries( ) . len( ) , 0 ) ;
595
+
596
+ // with instance specified
597
+ let q3 = & format ! ( "{} | filter instance_id == \" {}\" " , q1, i1. identity. id) ;
598
+
599
+ // project containing instance gives me something
600
+ let result = project_timeseries_query ( & cptestctx, "project1" , q3) . await ;
601
+ assert_eq ! ( result. len( ) , 1 ) ;
602
+ assert_eq ! ( result[ 0 ] . timeseries( ) . len( ) , 1 ) ;
603
+
604
+ // should be empty or error
605
+ let result = project_timeseries_query ( & cptestctx, "project2" , q3) . await ;
606
+ assert_eq ! ( result. len( ) , 1 ) ;
607
+ assert_eq ! ( result[ 0 ] . timeseries( ) . len( ) , 0 ) ;
581
608
582
- // Query with no project specified
583
609
// Query with nonexistent project
610
+ // Also test at least once with project ID in path instead of project name
611
+
612
+ // try a project in your silo that you can't read
613
+ // 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);
584
622
}
585
623
586
624
#[ nexus_test]
0 commit comments