| 
 | 1 | +use chroma_memberlist::config::CustomResourceMemberlistProviderConfig;  | 
 | 2 | +use serde::{Deserialize, Serialize};  | 
 | 3 | + | 
 | 4 | +/// Configuration for the gRPC heap service client.  | 
 | 5 | +///  | 
 | 6 | +/// This configures how to connect to the heap tender service instances via memberlist.  | 
 | 7 | +#[derive(Deserialize, Clone, Serialize, Debug)]  | 
 | 8 | +pub struct GrpcHeapServiceConfig {  | 
 | 9 | +    /// Whether the heap service client is enabled. Defaults to false.  | 
 | 10 | +    #[serde(default = "GrpcHeapServiceConfig::default_enabled")]  | 
 | 11 | +    pub enabled: bool,  | 
 | 12 | +    /// Connection timeout in milliseconds. Defaults to 5000ms.  | 
 | 13 | +    #[serde(default = "GrpcHeapServiceConfig::default_connect_timeout_ms")]  | 
 | 14 | +    pub connect_timeout_ms: u64,  | 
 | 15 | +    /// Request timeout in milliseconds. Defaults to 5000ms.  | 
 | 16 | +    #[serde(default = "GrpcHeapServiceConfig::default_request_timeout_ms")]  | 
 | 17 | +    pub request_timeout_ms: u64,  | 
 | 18 | +    /// Maximum message size for encoding. Defaults to 32MB.  | 
 | 19 | +    #[serde(default = "GrpcHeapServiceConfig::default_max_encoding_message_size")]  | 
 | 20 | +    pub max_encoding_message_size: usize,  | 
 | 21 | +    /// Maximum message size for decoding. Defaults to 32MB.  | 
 | 22 | +    #[serde(default = "GrpcHeapServiceConfig::default_max_decoding_message_size")]  | 
 | 23 | +    pub max_decoding_message_size: usize,  | 
 | 24 | +    /// Memberlist provider configuration. Defaults to rust-log-service-memberlist (colocated).  | 
 | 25 | +    #[serde(default = "GrpcHeapServiceConfig::default_memberlist_provider")]  | 
 | 26 | +    pub memberlist_provider: chroma_memberlist::config::MemberlistProviderConfig,  | 
 | 27 | +    /// Assignment policy. Must match log service (RendezvousHashing + Murmur3) for data locality.  | 
 | 28 | +    #[serde(default = "GrpcHeapServiceConfig::default_assignment")]  | 
 | 29 | +    pub assignment: chroma_config::assignment::config::AssignmentPolicyConfig,  | 
 | 30 | +    /// Port the heap service listens on. Defaults to 50052.  | 
 | 31 | +    #[serde(default = "GrpcHeapServiceConfig::default_port")]  | 
 | 32 | +    pub port: u16,  | 
 | 33 | +}  | 
 | 34 | + | 
 | 35 | +impl GrpcHeapServiceConfig {  | 
 | 36 | +    fn default_enabled() -> bool {  | 
 | 37 | +        false  | 
 | 38 | +    }  | 
 | 39 | + | 
 | 40 | +    fn default_connect_timeout_ms() -> u64 {  | 
 | 41 | +        5000  | 
 | 42 | +    }  | 
 | 43 | + | 
 | 44 | +    fn default_request_timeout_ms() -> u64 {  | 
 | 45 | +        5000  | 
 | 46 | +    }  | 
 | 47 | + | 
 | 48 | +    fn default_max_encoding_message_size() -> usize {  | 
 | 49 | +        32_000_000  | 
 | 50 | +    }  | 
 | 51 | + | 
 | 52 | +    fn default_max_decoding_message_size() -> usize {  | 
 | 53 | +        32_000_000  | 
 | 54 | +    }  | 
 | 55 | + | 
 | 56 | +    fn default_memberlist_provider() -> chroma_memberlist::config::MemberlistProviderConfig {  | 
 | 57 | +        chroma_memberlist::config::MemberlistProviderConfig::CustomResource(  | 
 | 58 | +            CustomResourceMemberlistProviderConfig {  | 
 | 59 | +                kube_namespace: "chroma".to_string(),  | 
 | 60 | +                memberlist_name: "rust-log-service-memberlist".to_string(), // Colocated with log service  | 
 | 61 | +                queue_size: 100,  | 
 | 62 | +            },  | 
 | 63 | +        )  | 
 | 64 | +    }  | 
 | 65 | + | 
 | 66 | +    fn default_assignment() -> chroma_config::assignment::config::AssignmentPolicyConfig {  | 
 | 67 | +        // IMPORTANT: Must match log service assignment policy (RendezvousHashing + Murmur3)  | 
 | 68 | +        // since heap and log services are colocated. This ensures that a collection's  | 
 | 69 | +        // heap operations go to the same node as its log operations.  | 
 | 70 | +        chroma_config::assignment::config::AssignmentPolicyConfig::RendezvousHashing(  | 
 | 71 | +            chroma_config::assignment::config::RendezvousHashingAssignmentPolicyConfig {  | 
 | 72 | +                hasher: chroma_config::assignment::config::HasherType::Murmur3,  | 
 | 73 | +            },  | 
 | 74 | +        )  | 
 | 75 | +    }  | 
 | 76 | + | 
 | 77 | +    fn default_port() -> u16 {  | 
 | 78 | +        50052  | 
 | 79 | +    }  | 
 | 80 | +}  | 
 | 81 | + | 
 | 82 | +impl Default for GrpcHeapServiceConfig {  | 
 | 83 | +    fn default() -> Self {  | 
 | 84 | +        GrpcHeapServiceConfig {  | 
 | 85 | +            enabled: GrpcHeapServiceConfig::default_enabled(),  | 
 | 86 | +            connect_timeout_ms: GrpcHeapServiceConfig::default_connect_timeout_ms(),  | 
 | 87 | +            request_timeout_ms: GrpcHeapServiceConfig::default_request_timeout_ms(),  | 
 | 88 | +            max_encoding_message_size: GrpcHeapServiceConfig::default_max_encoding_message_size(),  | 
 | 89 | +            max_decoding_message_size: GrpcHeapServiceConfig::default_max_decoding_message_size(),  | 
 | 90 | +            memberlist_provider: GrpcHeapServiceConfig::default_memberlist_provider(),  | 
 | 91 | +            assignment: GrpcHeapServiceConfig::default_assignment(),  | 
 | 92 | +            port: GrpcHeapServiceConfig::default_port(),  | 
 | 93 | +        }  | 
 | 94 | +    }  | 
 | 95 | +}  | 
 | 96 | + | 
 | 97 | +/// Configuration for heap service client.  | 
 | 98 | +#[derive(Deserialize, Clone, Serialize, Debug)]  | 
 | 99 | +pub enum HeapServiceConfig {  | 
 | 100 | +    /// gRPC-based heap service configuration.  | 
 | 101 | +    #[serde(alias = "grpc")]  | 
 | 102 | +    Grpc(GrpcHeapServiceConfig),  | 
 | 103 | +}  | 
 | 104 | + | 
 | 105 | +impl Default for HeapServiceConfig {  | 
 | 106 | +    fn default() -> Self {  | 
 | 107 | +        HeapServiceConfig::Grpc(GrpcHeapServiceConfig::default())  | 
 | 108 | +    }  | 
 | 109 | +}  | 
0 commit comments