Skip to content

Commit d8c3c00

Browse files
jasonvigilphilipkiely-baseten
authored andcommitted
[ENH] Add attributes for frontend metrics (chroma-core#4168)
## Description of changes Record tenant, database, and collection_id (where appropriate) attributes for the various frontend endpoints. This will allow us to perform usage queries such as gets per tenant (as well as per database / collection). ## Test plan These changes are not tested (yet). The plan is to merge into staging, then manually create some honeycomb dashboards / graphs to verify these attributes are being passed as expected.
1 parent 70b54b4 commit d8c3c00

File tree

1 file changed

+71
-15
lines changed

1 file changed

+71
-15
lines changed

rust/frontend/src/server.rs

+71-15
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,10 @@ async fn create_database(
548548
State(mut server): State<FrontendServer>,
549549
Json(CreateDatabasePayload { name }): Json<CreateDatabasePayload>,
550550
) -> Result<Json<CreateDatabaseResponse>, ServerError> {
551-
server.metrics.create_database.add(1, &[]);
551+
server
552+
.metrics
553+
.create_database
554+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
552555
tracing::info!("Creating database [{}] for tenant [{}]", name, tenant);
553556
server
554557
.authenticate_and_authorize(
@@ -607,7 +610,10 @@ async fn list_databases(
607610
Query(ListDatabasesParams { limit, offset }): Query<ListDatabasesParams>,
608611
State(mut server): State<FrontendServer>,
609612
) -> Result<Json<ListDatabasesResponse>, ServerError> {
610-
server.metrics.list_databases.add(1, &[]);
613+
server
614+
.metrics
615+
.list_databases
616+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
611617
tracing::info!("Listing database for tenant [{}]", tenant);
612618
server
613619
.authenticate_and_authorize(
@@ -647,7 +653,10 @@ async fn get_database(
647653
Path((tenant, database)): Path<(String, String)>,
648654
State(mut server): State<FrontendServer>,
649655
) -> Result<Json<GetDatabaseResponse>, ServerError> {
650-
server.metrics.get_database.add(1, &[]);
656+
server
657+
.metrics
658+
.get_database
659+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
651660
tracing::info!("Getting database [{}] for tenant [{}]", database, tenant);
652661
server
653662
.authenticate_and_authorize(
@@ -687,7 +696,10 @@ async fn delete_database(
687696
Path((tenant, database)): Path<(String, String)>,
688697
State(mut server): State<FrontendServer>,
689698
) -> Result<Json<DeleteDatabaseResponse>, ServerError> {
690-
server.metrics.delete_database.add(1, &[]);
699+
server
700+
.metrics
701+
.delete_database
702+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
691703
tracing::info!("Deleting database [{}] for tenant [{}]", database, tenant);
692704
server
693705
.authenticate_and_authorize(
@@ -735,7 +747,10 @@ async fn list_collections(
735747
Query(ListCollectionsParams { limit, offset }): Query<ListCollectionsParams>,
736748
State(mut server): State<FrontendServer>,
737749
) -> Result<Json<ListCollectionsResponse>, ServerError> {
738-
server.metrics.list_collections.add(1, &[]);
750+
server
751+
.metrics
752+
.list_collections
753+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
739754
tracing::info!(
740755
"Listing collections in database [{}] for tenant [{}] with limit [{:?}] and offset [{:?}]",
741756
database,
@@ -788,7 +803,10 @@ async fn count_collections(
788803
Path((tenant, database)): Path<(String, String)>,
789804
State(mut server): State<FrontendServer>,
790805
) -> Result<Json<CountCollectionsResponse>, ServerError> {
791-
server.metrics.count_collections.add(1, &[]);
806+
server
807+
.metrics
808+
.count_collections
809+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
792810
tracing::info!("Counting number of collections in database [{database}] for tenant [{tenant}]",);
793811
server
794812
.authenticate_and_authorize(
@@ -840,7 +858,10 @@ async fn create_collection(
840858
State(mut server): State<FrontendServer>,
841859
Json(payload): Json<CreateCollectionPayload>,
842860
) -> Result<Json<Collection>, ServerError> {
843-
server.metrics.create_collection.add(1, &[]);
861+
server
862+
.metrics
863+
.create_collection
864+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
844865
tracing::info!("Creating collection in database [{database}] for tenant [{tenant}]");
845866
server
846867
.authenticate_and_authorize(
@@ -908,7 +929,10 @@ async fn get_collection(
908929
Path((tenant, database, collection_name)): Path<(String, String, String)>,
909930
State(mut server): State<FrontendServer>,
910931
) -> Result<Json<Collection>, ServerError> {
911-
server.metrics.get_collection.add(1, &[]);
932+
server
933+
.metrics
934+
.get_collection
935+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
912936
tracing::info!(
913937
"Getting collection [{collection_name}] in database [{database}] for tenant [{tenant}]"
914938
);
@@ -960,7 +984,13 @@ async fn update_collection(
960984
State(mut server): State<FrontendServer>,
961985
Json(payload): Json<UpdateCollectionPayload>,
962986
) -> Result<Json<UpdateCollectionResponse>, ServerError> {
963-
server.metrics.update_collection.add(1, &[]);
987+
server.metrics.update_collection.add(
988+
1,
989+
&[
990+
KeyValue::new("tenant", tenant.clone()),
991+
KeyValue::new("collection_id", collection_id.clone()),
992+
],
993+
);
964994
tracing::info!(
965995
"Updating collection [{collection_id}] in database [{database}] for tenant [{tenant}]"
966996
);
@@ -1029,7 +1059,10 @@ async fn delete_collection(
10291059
Path((tenant, database, collection_name)): Path<(String, String, String)>,
10301060
State(mut server): State<FrontendServer>,
10311061
) -> Result<Json<UpdateCollectionResponse>, ServerError> {
1032-
server.metrics.delete_collection.add(1, &[]);
1062+
server
1063+
.metrics
1064+
.delete_collection
1065+
.add(1, &[KeyValue::new("tenant", tenant.clone())]);
10331066
tracing::info!(
10341067
"Deleting collection [{collection_name}] in database [{database}] for tenant [{tenant}]"
10351068
);
@@ -1080,7 +1113,13 @@ async fn collection_add(
10801113
State(mut server): State<FrontendServer>,
10811114
Json(payload): Json<AddCollectionRecordsPayload>,
10821115
) -> Result<(StatusCode, Json<AddCollectionRecordsResponse>), ServerError> {
1083-
server.metrics.collection_add.add(1, &[]);
1116+
server.metrics.collection_add.add(
1117+
1,
1118+
&[
1119+
KeyValue::new("tenant", tenant.clone()),
1120+
KeyValue::new("collection_id", collection_id.clone()),
1121+
],
1122+
);
10841123
server
10851124
.authenticate_and_authorize(
10861125
&headers,
@@ -1161,7 +1200,13 @@ async fn collection_update(
11611200
State(mut server): State<FrontendServer>,
11621201
Json(payload): Json<UpdateCollectionRecordsPayload>,
11631202
) -> Result<Json<UpdateCollectionRecordsResponse>, ServerError> {
1164-
server.metrics.collection_update.add(1, &[]);
1203+
server.metrics.collection_update.add(
1204+
1,
1205+
&[
1206+
KeyValue::new("tenant", tenant.clone()),
1207+
KeyValue::new("collection_id", collection_id.clone()),
1208+
],
1209+
);
11651210
server
11661211
.authenticate_and_authorize(
11671212
&headers,
@@ -1246,7 +1291,13 @@ async fn collection_upsert(
12461291
State(mut server): State<FrontendServer>,
12471292
Json(payload): Json<UpsertCollectionRecordsPayload>,
12481293
) -> Result<Json<UpsertCollectionRecordsResponse>, ServerError> {
1249-
server.metrics.collection_upsert.add(1, &[]);
1294+
server.metrics.collection_upsert.add(
1295+
1,
1296+
&[
1297+
KeyValue::new("tenant", tenant.clone()),
1298+
KeyValue::new("collection_id", collection_id.clone()),
1299+
],
1300+
);
12501301
server
12511302
.authenticate_and_authorize(
12521303
&headers,
@@ -1330,7 +1381,13 @@ async fn collection_delete(
13301381
State(mut server): State<FrontendServer>,
13311382
Json(payload): Json<DeleteCollectionRecordsPayload>,
13321383
) -> Result<Json<DeleteCollectionRecordsResponse>, ServerError> {
1333-
server.metrics.collection_delete.add(1, &[]);
1384+
server.metrics.collection_delete.add(
1385+
1,
1386+
&[
1387+
KeyValue::new("tenant", tenant.clone()),
1388+
KeyValue::new("collection_id", collection_id.clone()),
1389+
],
1390+
);
13341391
server
13351392
.authenticate_and_authorize(
13361393
&headers,
@@ -1401,7 +1458,6 @@ async fn collection_count(
14011458
1,
14021459
&[
14031460
KeyValue::new("tenant", tenant.clone()),
1404-
KeyValue::new("database", database.clone()),
14051461
KeyValue::new("collection_id", collection_id.clone()),
14061462
],
14071463
);

0 commit comments

Comments
 (0)