Skip to content
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

Improve diagnostics when an Azure endpoint is not configured. #4845

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
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
28 changes: 19 additions & 9 deletions tiledb/sm/filesystem/azure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ std::string get_config_with_env_fallback(
return result;
}

std::string get_blob_endpoint(
std::optional<std::string> get_blob_endpoint(
const Config& config, const std::string& account_name) {
std::string sas_token = get_config_with_env_fallback(
config, "vfs.azure.storage_sas_token", "AZURE_STORAGE_SAS_TOKEN");
Expand All @@ -90,9 +90,7 @@ std::string get_blob_endpoint(
if (!account_name.empty()) {
result = "https://" + account_name + ".blob.core.windows.net";
} else {
LOG_WARN(
"Neither the 'vfs.azure.storage_account_name' nor the "
"'vfs.azure.blob_endpoint' options are specified.");
return std::nullopt;
}
} else if (!(utils::parse::starts_with(result, "http://") ||
utils::parse::starts_with(result, "https://"))) {
Expand Down Expand Up @@ -124,7 +122,20 @@ static bool has_sas_token(const Config& config) {
return !sas_token.empty();
}

AzureParameters::AzureParameters(const Config& config)
std::optional<AzureParameters> AzureParameters::create(const Config& config) {
auto account_name = get_config_with_env_fallback(
config, "vfs.azure.storage_account_name", "AZURE_STORAGE_ACCOUNT");
auto blob_endpoint = get_blob_endpoint(config, account_name);
if (!blob_endpoint) {
return std::nullopt;
}
return AzureParameters{config, account_name, *blob_endpoint};
}

AzureParameters::AzureParameters(
const Config& config,
const std::string& account_name,
const std::string& blob_endpoint)
: max_parallel_ops_(
config.get<uint64_t>("vfs.azure.max_parallel_ops", Config::must_find))
, block_list_block_size_(config.get<uint64_t>(
Expand All @@ -138,11 +149,10 @@ AzureParameters::AzureParameters(const Config& config)
"vfs.azure.max_retry_delay_ms", Config::must_find)))
, use_block_list_upload_(config.get<bool>(
"vfs.azure.use_block_list_upload", Config::must_find))
, account_name_(get_config_with_env_fallback(
config, "vfs.azure.storage_account_name", "AZURE_STORAGE_ACCOUNT"))
, account_name_(account_name)
, account_key_(get_config_with_env_fallback(
config, "vfs.azure.storage_account_key", "AZURE_STORAGE_KEY"))
, blob_endpoint_(get_blob_endpoint(config, account_name_))
, blob_endpoint_(blob_endpoint)
, ssl_cfg_(config)
, has_sas_token_(has_sas_token(config)) {
}
Expand All @@ -153,7 +163,7 @@ Status Azure::init(const Config& config, ThreadPool* const thread_pool) {
Status_AzureError("Can't initialize with null thread pool."));
}
thread_pool_ = thread_pool;
azure_params_ = config;
azure_params_ = AzureParameters::create(config);
return Status::Ok();
}

Expand Down
30 changes: 28 additions & 2 deletions tiledb/sm/filesystem/azure.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ namespace sm {
struct AzureParameters {
AzureParameters() = delete;

AzureParameters(const Config& config);
/**
* Creates an AzureParameters object.
*
* @return AzureParameters or nullopt if config does not have
* a storage account or blob endpoint set.
*/
static std::optional<AzureParameters> create(const Config& config);

/** The maximum number of parallel requests. */
uint64_t max_parallel_ops_;
Expand Down Expand Up @@ -107,6 +113,12 @@ struct AzureParameters {

/** Whether the config specifies a SAS token. */
bool has_sas_token_;

private:
AzureParameters(
const Config& config,
const std::string& account_name,
const std::string& blob_endpoint);
};

class Azure {
Expand Down Expand Up @@ -362,7 +374,21 @@ class Azure {
* use of the BlobServiceClient.
*/
const ::Azure::Storage::Blobs::BlobServiceClient& client() const {
assert(azure_params_);
// This branch can be entered in two circumstances:
// 1. The init method has not been called yet.
// 2. The init method has been called, but the config (or environment
// variables) do not contain enough information to get the Azure
// endpoint.
// We don't distinguish between the two, because only the latter can
// happen under normal circumstances, and the former is a C.41 issue
// that will go away once the class is C.41 compliant.
if (!azure_params_) {
throw StatusException(Status_AzureError(
"Azure VFS is not configured. Please set the "
"'vfs.azure.storage_account_name' and/or "
"'vfs.azure.blob_endpoint' configuration options."));
}

return client_singleton_.get(*azure_params_);
}

Expand Down
Loading