-
Notifications
You must be signed in to change notification settings - Fork 574
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
refactor: remove private link related connection #18975
Draft
tabVersion
wants to merge
5
commits into
main
Choose a base branch
from
tab/deprecate-private-link-connection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
449f09b
remove private link related connection
tabVersion 03b47bb
fix
tabVersion 589d9ff
Merge branch 'main' into tab/deprecate-private-link-connection
tabVersion 6c1b912
Merge remote-tracking branch 'origin' into tab/deprecate-private-link…
tabVersion de10c92
fix
tabVersion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,197 +0,0 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::collections::BTreeMap; | ||
use std::sync::LazyLock; | ||
|
||
use async_trait::async_trait; | ||
use regex::Regex; | ||
use risingwave_connector::error::ConnectorResult; | ||
use risingwave_connector::source::kafka::private_link::insert_privatelink_broker_rewrite_map; | ||
use risingwave_connector::source::{ | ||
ConnectorProperties, SourceEnumeratorContext, SourceProperties, SplitEnumerator, | ||
}; | ||
use risingwave_connector::{dispatch_source_prop, WithOptionsSecResolved}; | ||
use risingwave_meta::manager::MetadataManager; | ||
use risingwave_meta_model::ConnectionId; | ||
use risingwave_pb::catalog::connection::Info::PrivateLinkService; | ||
use risingwave_pb::cloud_service::cloud_service_server::CloudService; | ||
use risingwave_pb::cloud_service::rw_cloud_validate_source_response::{Error, ErrorType}; | ||
use risingwave_pb::cloud_service::{ | ||
RwCloudValidateSourceRequest, RwCloudValidateSourceResponse, SourceType, | ||
}; | ||
use thiserror_ext::AsReport; | ||
use tonic::{Request, Response, Status}; | ||
|
||
use crate::rpc::cloud_provider::AwsEc2Client; | ||
|
||
pub struct CloudServiceImpl { | ||
metadata_manager: MetadataManager, | ||
aws_client: Option<AwsEc2Client>, | ||
} | ||
|
||
impl CloudServiceImpl { | ||
pub fn new(metadata_manager: MetadataManager, aws_client: Option<AwsEc2Client>) -> Self { | ||
Self { | ||
metadata_manager, | ||
aws_client, | ||
} | ||
} | ||
} | ||
|
||
#[inline(always)] | ||
fn new_rwc_validate_fail_response( | ||
error_type: ErrorType, | ||
error_message: String, | ||
) -> Response<RwCloudValidateSourceResponse> { | ||
Response::new(RwCloudValidateSourceResponse { | ||
ok: false, | ||
error: Some(Error { | ||
error_type: error_type.into(), | ||
error_message, | ||
}), | ||
}) | ||
} | ||
|
||
#[async_trait] | ||
impl CloudService for CloudServiceImpl { | ||
async fn rw_cloud_validate_source( | ||
&self, | ||
request: Request<RwCloudValidateSourceRequest>, | ||
) -> Result<Response<RwCloudValidateSourceResponse>, Status> { | ||
let req = request.into_inner(); | ||
if req.source_type() != SourceType::Kafka { | ||
return Err(Status::invalid_argument( | ||
"unexpected source type, only kafka source is supported", | ||
)); | ||
} | ||
let mut source_cfg: BTreeMap<String, String> = req.source_config.into_iter().collect(); | ||
// if connection_id provided, check whether endpoint service is available and resolve | ||
// broker rewrite map currently only support aws privatelink connection | ||
if let Some(connection_id_str) = source_cfg.get("connection.id") { | ||
let connection_id = connection_id_str.parse::<ConnectionId>().map_err(|e| { | ||
Status::invalid_argument(format!( | ||
"connection.id is not an integer: {}", | ||
e.as_report() | ||
)) | ||
})?; | ||
|
||
let connection = self | ||
.metadata_manager | ||
.catalog_controller | ||
.get_connection_by_id(connection_id) | ||
.await; | ||
|
||
if let Err(e) = connection { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::PrivatelinkConnectionNotFound, | ||
e.to_report_string(), | ||
)); | ||
} | ||
if let Some(PrivateLinkService(service)) = connection.unwrap().info { | ||
if self.aws_client.is_none() { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::AwsClientNotConfigured, | ||
"AWS client is not configured".to_string(), | ||
)); | ||
} | ||
let cli = self.aws_client.as_ref().unwrap(); | ||
let privatelink_status = cli | ||
.is_vpc_endpoint_ready(service.endpoint_id.as_str()) | ||
.await; | ||
match privatelink_status { | ||
Err(e) => { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::PrivatelinkUnavailable, | ||
e.to_report_string(), | ||
)); | ||
} | ||
Ok(false) => { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::PrivatelinkUnavailable, | ||
format!("Private link endpoint {} is not ready", service.endpoint_id,), | ||
)); | ||
} | ||
_ => (), | ||
}; | ||
if let Err(e) = | ||
insert_privatelink_broker_rewrite_map(&mut source_cfg, Some(&service), None) | ||
{ | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::PrivatelinkResolveErr, | ||
e.to_report_string(), | ||
)); | ||
} | ||
} else { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::PrivatelinkResolveErr, | ||
format!("connection {} has no info available", connection_id), | ||
)); | ||
} | ||
} | ||
|
||
// XXX: We can't use secret in cloud validate source. | ||
let source_cfg = WithOptionsSecResolved::without_secrets(source_cfg); | ||
|
||
// try fetch kafka metadata, return error message on failure | ||
let props = ConnectorProperties::extract(source_cfg, false); | ||
if let Err(e) = props { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::KafkaInvalidProperties, | ||
e.to_report_string(), | ||
)); | ||
}; | ||
|
||
async fn new_enumerator<P: SourceProperties>( | ||
props: P, | ||
) -> ConnectorResult<P::SplitEnumerator> { | ||
P::SplitEnumerator::new(props, SourceEnumeratorContext::dummy().into()).await | ||
} | ||
|
||
dispatch_source_prop!(props.unwrap(), props, { | ||
let enumerator = new_enumerator(*props).await; | ||
if let Err(e) = enumerator { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::KafkaInvalidProperties, | ||
e.to_report_string(), | ||
)); | ||
} | ||
if let Err(e) = enumerator.unwrap().list_splits().await { | ||
let error_message = e.to_report_string(); | ||
if error_message.contains("BrokerTransportFailure") { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::KafkaBrokerUnreachable, | ||
e.to_report_string(), | ||
)); | ||
} | ||
static TOPIC_NOT_FOUND: LazyLock<Regex> = | ||
LazyLock::new(|| Regex::new(r"topic .* not found").unwrap()); | ||
if TOPIC_NOT_FOUND.is_match(error_message.as_str()) { | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::KafkaTopicNotFound, | ||
e.to_report_string(), | ||
)); | ||
} | ||
return Ok(new_rwc_validate_fail_response( | ||
ErrorType::KafkaOther, | ||
e.to_report_string(), | ||
)); | ||
} | ||
}); | ||
Ok(Response::new(RwCloudValidateSourceResponse { | ||
ok: true, | ||
error: None, | ||
})) | ||
} | ||
} | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rpc interface is provided to the cloud portal previously, I am not sure whether it is still valid. Please confirm with @cloudcarver @neverchanje
#10139