@@ -122,6 +122,16 @@ impl Default for Address {
122
122
}
123
123
}
124
124
125
+ impl std:: fmt:: Display for Address {
126
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
127
+ write ! (
128
+ f,
129
+ "[address: {}:{}][database: {}][user: {}]" ,
130
+ self . host, self . port, self . database, self . username
131
+ )
132
+ }
133
+ }
134
+
125
135
// We need to implement PartialEq by ourselves so we skip stats in the comparison
126
136
impl PartialEq for Address {
127
137
fn eq ( & self , other : & Self ) -> bool {
@@ -235,6 +245,8 @@ pub struct General {
235
245
pub port : u16 ,
236
246
237
247
pub enable_prometheus_exporter : Option < bool > ,
248
+
249
+ #[ serde( default = "General::default_prometheus_exporter_port" ) ]
238
250
pub prometheus_exporter_port : i16 ,
239
251
240
252
#[ serde( default = "General::default_connect_timeout" ) ]
@@ -374,6 +386,10 @@ impl General {
374
386
pub fn default_validate_config ( ) -> bool {
375
387
true
376
388
}
389
+
390
+ pub fn default_prometheus_exporter_port ( ) -> i16 {
391
+ 9930
392
+ }
377
393
}
378
394
379
395
impl Default for General {
@@ -462,6 +478,7 @@ pub struct Pool {
462
478
#[ serde( default = "Pool::default_load_balancing_mode" ) ]
463
479
pub load_balancing_mode : LoadBalancingMode ,
464
480
481
+ #[ serde( default = "Pool::default_default_role" ) ]
465
482
pub default_role : String ,
466
483
467
484
#[ serde( default ) ] // False
@@ -476,6 +493,7 @@ pub struct Pool {
476
493
477
494
pub server_lifetime : Option < u64 > ,
478
495
496
+ #[ serde( default = "Pool::default_sharding_function" ) ]
479
497
pub sharding_function : ShardingFunction ,
480
498
481
499
#[ serde( default = "Pool::default_automatic_sharding_key" ) ]
@@ -489,6 +507,7 @@ pub struct Pool {
489
507
pub auth_query_user : Option < String > ,
490
508
pub auth_query_password : Option < String > ,
491
509
510
+ pub plugins : Option < Plugins > ,
492
511
pub shards : BTreeMap < String , Shard > ,
493
512
pub users : BTreeMap < String , User > ,
494
513
// Note, don't put simple fields below these configs. There's a compatibility issue with TOML that makes it
@@ -521,6 +540,14 @@ impl Pool {
521
540
None
522
541
}
523
542
543
+ pub fn default_default_role ( ) -> String {
544
+ "any" . into ( )
545
+ }
546
+
547
+ pub fn default_sharding_function ( ) -> ShardingFunction {
548
+ ShardingFunction :: PgBigintHash
549
+ }
550
+
524
551
pub fn validate ( & mut self ) -> Result < ( ) , Error > {
525
552
match self . default_role . as_ref ( ) {
526
553
"any" => ( ) ,
@@ -609,6 +636,7 @@ impl Default for Pool {
609
636
auth_query_user : None ,
610
637
auth_query_password : None ,
611
638
server_lifetime : None ,
639
+ plugins : None ,
612
640
}
613
641
}
614
642
}
@@ -687,30 +715,50 @@ impl Default for Shard {
687
715
}
688
716
}
689
717
690
- #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default ) ]
718
+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default , Hash , Eq ) ]
691
719
pub struct Plugins {
692
720
pub intercept : Option < Intercept > ,
693
721
pub table_access : Option < TableAccess > ,
694
722
pub query_logger : Option < QueryLogger > ,
723
+ pub prewarmer : Option < Prewarmer > ,
695
724
}
696
725
697
- #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default ) ]
726
+ impl std:: fmt:: Display for Plugins {
727
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
728
+ write ! (
729
+ f,
730
+ "interceptor: {}, table_access: {}, query_logger: {}, prewarmer: {}" ,
731
+ self . intercept. is_some( ) ,
732
+ self . table_access. is_some( ) ,
733
+ self . query_logger. is_some( ) ,
734
+ self . prewarmer. is_some( ) ,
735
+ )
736
+ }
737
+ }
738
+
739
+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default , Hash , Eq ) ]
698
740
pub struct Intercept {
699
741
pub enabled : bool ,
700
742
pub queries : BTreeMap < String , Query > ,
701
743
}
702
744
703
- #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default ) ]
745
+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default , Hash , Eq ) ]
704
746
pub struct TableAccess {
705
747
pub enabled : bool ,
706
748
pub tables : Vec < String > ,
707
749
}
708
750
709
- #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default ) ]
751
+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default , Hash , Eq ) ]
710
752
pub struct QueryLogger {
711
753
pub enabled : bool ,
712
754
}
713
755
756
+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default , Hash , Eq ) ]
757
+ pub struct Prewarmer {
758
+ pub enabled : bool ,
759
+ pub queries : Vec < String > ,
760
+ }
761
+
714
762
impl Intercept {
715
763
pub fn substitute ( & mut self , db : & str , user : & str ) {
716
764
for ( _, query) in self . queries . iter_mut ( ) {
@@ -720,7 +768,7 @@ impl Intercept {
720
768
}
721
769
}
722
770
723
- #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default ) ]
771
+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Default , Hash , Eq ) ]
724
772
pub struct Query {
725
773
pub query : String ,
726
774
pub schema : Vec < Vec < String > > ,
@@ -754,8 +802,13 @@ pub struct Config {
754
802
#[ serde( default = "Config::default_path" ) ]
755
803
pub path : String ,
756
804
805
+ // General and global settings.
757
806
pub general : General ,
807
+
808
+ // Plugins that should run in all pools.
758
809
pub plugins : Option < Plugins > ,
810
+
811
+ // Connection pools.
759
812
pub pools : HashMap < String , Pool > ,
760
813
}
761
814
@@ -940,6 +993,13 @@ impl Config {
940
993
"Server TLS certificate verification: {}" ,
941
994
self . general. verify_server_certificate
942
995
) ;
996
+ info ! (
997
+ "Plugins: {}" ,
998
+ match self . plugins {
999
+ Some ( ref plugins) => plugins. to_string( ) ,
1000
+ None => "not configured" . into( ) ,
1001
+ }
1002
+ ) ;
943
1003
944
1004
for ( pool_name, pool_config) in & self . pools {
945
1005
// TODO: Make this output prettier (maybe a table?)
@@ -1006,6 +1066,14 @@ impl Config {
1006
1066
None => "default" . to_string( ) ,
1007
1067
}
1008
1068
) ;
1069
+ info ! (
1070
+ "[pool: {}] Plugins: {}" ,
1071
+ pool_name,
1072
+ match pool_config. plugins {
1073
+ Some ( ref plugins) => plugins. to_string( ) ,
1074
+ None => "not configured" . into( ) ,
1075
+ }
1076
+ ) ;
1009
1077
1010
1078
for user in & pool_config. users {
1011
1079
info ! (
0 commit comments