Skip to content

feat(user): use global redis key prefix for user lineage context #7903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions crates/router/src/utils/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ pub fn get_redis_connection(state: &SessionState) -> UserResult<Arc<RedisConnect
.attach_printable("Failed to get redis connection")
}

pub fn get_redis_connection_for_global_tenant(
state: &SessionState,
) -> UserResult<Arc<RedisConnectionPool>> {
let redis_connection_pool = state
.store
.get_redis_conn()
.change_context(UserErrors::InternalServerError)
.attach_printable("Failed to get redis connection")?;

let global_tenant_prefix = &state.conf.multitenancy.global_tenant.redis_key_prefix;

Ok(Arc::new(RedisConnectionPool {
pool: Arc::clone(&redis_connection_pool.pool),
key_prefix: global_tenant_prefix.to_string(),
config: Arc::clone(&redis_connection_pool.config),
subscriber: Arc::clone(&redis_connection_pool.subscriber),
publisher: Arc::clone(&redis_connection_pool.publisher),
is_redis_available: Arc::clone(&redis_connection_pool.is_redis_available),
}))
}

impl ForeignFrom<&user_api::AuthConfig> for UserAuthType {
fn foreign_from(from: &user_api::AuthConfig) -> Self {
match *from {
Expand Down Expand Up @@ -347,7 +368,7 @@ pub async fn get_lineage_context_from_cache(
state: &SessionState,
user_id: &str,
) -> UserResult<Option<LineageContext>> {
let connection = get_redis_connection(state)?;
let connection = get_redis_connection_for_global_tenant(state)?;
let key = format!("{}{}", LINEAGE_CONTEXT_PREFIX, user_id);
let lineage_context = connection
.get_key::<Option<String>>(&key.into())
Expand All @@ -371,7 +392,7 @@ pub async fn set_lineage_context_in_cache(
user_id: &str,
lineage_context: LineageContext,
) -> UserResult<()> {
let connection = get_redis_connection(state)?;
let connection = get_redis_connection_for_global_tenant(state)?;
let key = format!("{}{}", LINEAGE_CONTEXT_PREFIX, user_id);
let serialized_lineage_context: String = serde_json::to_string(&lineage_context)
.change_context(UserErrors::InternalServerError)
Expand Down
Loading