@@ -12,10 +12,13 @@ use std::fmt::Display;
12
12
13
13
use chrono:: { DateTime , Utc } ;
14
14
use futures_util:: { Stream , TryStreamExt } ;
15
+ use opentelemetry:: KeyValue ;
15
16
use sqlx:: { Acquire , FromRow , PgConnection , Postgres , Transaction , Type , query} ;
16
17
use thiserror:: Error ;
17
18
use thiserror_ext:: ContextInto ;
18
19
20
+ use crate :: telemetry:: READER_ENTITY_COUNT ;
21
+
19
22
pub mod checks;
20
23
pub mod config;
21
24
@@ -432,6 +435,7 @@ impl<'conn> SynapseReader<'conn> {
432
435
/// Reads Synapse users, excluding application service users (which do not
433
436
/// need to be migrated), from the database.
434
437
pub fn read_users ( & mut self ) -> impl Stream < Item = Result < SynapseUser , Error > > + ' _ {
438
+ let kv = [ KeyValue :: new ( "entity" , "users" ) ] ;
435
439
sqlx:: query_as (
436
440
"
437
441
SELECT
@@ -440,12 +444,14 @@ impl<'conn> SynapseReader<'conn> {
440
444
" ,
441
445
)
442
446
. fetch ( & mut * self . txn )
447
+ . inspect_ok ( move |_| READER_ENTITY_COUNT . add ( 1 , & kv) )
443
448
. map_err ( |err| err. into_database ( "reading Synapse users" ) )
444
449
}
445
450
446
451
/// Reads threepids (such as e-mail and phone number associations) from
447
452
/// Synapse.
448
453
pub fn read_threepids ( & mut self ) -> impl Stream < Item = Result < SynapseThreepid , Error > > + ' _ {
454
+ let kv = [ KeyValue :: new ( "entity" , "threepids" ) ] ;
449
455
sqlx:: query_as (
450
456
"
451
457
SELECT
@@ -454,13 +460,15 @@ impl<'conn> SynapseReader<'conn> {
454
460
" ,
455
461
)
456
462
. fetch ( & mut * self . txn )
463
+ . inspect_ok ( move |_| READER_ENTITY_COUNT . add ( 1 , & kv) )
457
464
. map_err ( |err| err. into_database ( "reading Synapse threepids" ) )
458
465
}
459
466
460
467
/// Read associations between Synapse users and external identity providers
461
468
pub fn read_user_external_ids (
462
469
& mut self ,
463
470
) -> impl Stream < Item = Result < SynapseExternalId , Error > > + ' _ {
471
+ let kv = [ KeyValue :: new ( "entity" , "external_ids" ) ] ;
464
472
sqlx:: query_as (
465
473
"
466
474
SELECT
@@ -469,13 +477,15 @@ impl<'conn> SynapseReader<'conn> {
469
477
" ,
470
478
)
471
479
. fetch ( & mut * self . txn )
480
+ . inspect_ok ( move |_| READER_ENTITY_COUNT . add ( 1 , & kv) )
472
481
. map_err ( |err| err. into_database ( "reading Synapse user external IDs" ) )
473
482
}
474
483
475
484
/// Reads devices from the Synapse database.
476
485
/// Does not include so-called 'hidden' devices, which are just a mechanism
477
486
/// for storing various signing keys shared between the real devices.
478
487
pub fn read_devices ( & mut self ) -> impl Stream < Item = Result < SynapseDevice , Error > > + ' _ {
488
+ let kv = [ KeyValue :: new ( "entity" , "devices" ) ] ;
479
489
sqlx:: query_as (
480
490
"
481
491
SELECT
@@ -485,6 +495,7 @@ impl<'conn> SynapseReader<'conn> {
485
495
" ,
486
496
)
487
497
. fetch ( & mut * self . txn )
498
+ . inspect_ok ( move |_| READER_ENTITY_COUNT . add ( 1 , & kv) )
488
499
. map_err ( |err| err. into_database ( "reading Synapse devices" ) )
489
500
}
490
501
@@ -500,6 +511,7 @@ impl<'conn> SynapseReader<'conn> {
500
511
pub fn read_unrefreshable_access_tokens (
501
512
& mut self ,
502
513
) -> impl Stream < Item = Result < SynapseAccessToken , Error > > + ' _ {
514
+ let kv = [ KeyValue :: new ( "entity" , "nonrefreshable_access_tokens" ) ] ;
503
515
sqlx:: query_as (
504
516
"
505
517
SELECT
@@ -517,6 +529,7 @@ impl<'conn> SynapseReader<'conn> {
517
529
" ,
518
530
)
519
531
. fetch ( & mut * self . txn )
532
+ . inspect_ok ( move |_| READER_ENTITY_COUNT . add ( 1 , & kv) )
520
533
. map_err ( |err| err. into_database ( "reading Synapse access tokens" ) )
521
534
}
522
535
@@ -532,6 +545,7 @@ impl<'conn> SynapseReader<'conn> {
532
545
pub fn read_refreshable_token_pairs (
533
546
& mut self ,
534
547
) -> impl Stream < Item = Result < SynapseRefreshableTokenPair , Error > > + ' _ {
548
+ let kv = [ KeyValue :: new ( "entity" , "refreshable_token_pairs" ) ] ;
535
549
sqlx:: query_as (
536
550
"
537
551
SELECT
@@ -544,6 +558,7 @@ impl<'conn> SynapseReader<'conn> {
544
558
" ,
545
559
)
546
560
. fetch ( & mut * self . txn )
561
+ . inspect_ok ( move |_| READER_ENTITY_COUNT . add ( 1 , & kv) )
547
562
. map_err ( |err| err. into_database ( "reading Synapse refresh tokens" ) )
548
563
}
549
564
}
0 commit comments