-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export trace data to cloud providers
- Loading branch information
Showing
13 changed files
with
772 additions
and
114 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,6 +1,7 @@ | ||
FROM debian:buster-slim | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
ca-certificates \ | ||
dumb-init \ | ||
rust-gdb | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use object_store::path::Path; | ||
use object_store::DynObjectStore; | ||
use reqwest::Url; | ||
|
||
use crate::errors::*; | ||
|
||
/// We use the [object_store](https://docs.rs/object_store/latest/object_store/index.html) crate to | ||
/// enable reading/writing from the three major cloud providers (AWS, Azure, GCP), as well as | ||
/// to/from a local filesystem or an in-memory store. Supposedly HTTP with WebDAV is supported as | ||
/// well but that is completely untested. | ||
/// | ||
/// The reader will load credentials from the environment to communicate with the cloud provider, | ||
/// as follows (other auth mechanisms _may_ work as well but are currently untested): | ||
/// | ||
/// ### AWS | ||
/// | ||
/// Set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables, and pass in a | ||
/// URL like `s3://bucket/path/to/resource`. | ||
/// | ||
/// ### Azure | ||
/// | ||
/// Set the `AZURE_STORAGE_ACCOUNT_NAME` and `AZURE_STORAGE_ACCOUNT_KEY` environment variables, and | ||
/// pass in a URL like `azure://container/path/to/resources` (do not include the storage acocunt | ||
/// name in the URL). | ||
/// | ||
/// ### GCP | ||
/// | ||
/// Set the `GOOGLE_SERVICE_ACCOUNT` environment variable to the path for your service account JSON | ||
/// file (if you're running inside a container, you'll need that file injected as well). Pass in a | ||
/// URL like `gs://bucket/path/to/resource`. | ||
// This code is copy-pasta'ed from the object_store library because it is currently private | ||
// in that library. This code can all be deleted if/once https://github.com/apache/arrow-rs/pull/5912 | ||
// is merged. | ||
|
||
#[derive(Debug, Eq, PartialEq)] | ||
pub enum ObjectStoreScheme { | ||
Local, | ||
Memory, | ||
AmazonS3, | ||
GoogleCloudStorage, | ||
MicrosoftAzure, | ||
Http, | ||
} | ||
|
||
impl ObjectStoreScheme { | ||
pub fn parse(url: &Url) -> anyhow::Result<(Self, Path)> { | ||
let strip_bucket = || Some(url.path().strip_prefix('/')?.split_once('/')?.1); | ||
|
||
let (scheme, path) = match (url.scheme(), url.host_str()) { | ||
("file", None) => (Self::Local, url.path()), | ||
("memory", None) => (Self::Memory, url.path()), | ||
("s3" | "s3a", Some(_)) => (Self::AmazonS3, url.path()), | ||
("gs", Some(_)) => (Self::GoogleCloudStorage, url.path()), | ||
("az" | "adl" | "azure" | "abfs" | "abfss", Some(_)) => (Self::MicrosoftAzure, url.path()), | ||
("http", Some(_)) => (Self::Http, url.path()), | ||
("https", Some(host)) => { | ||
if host.ends_with("dfs.core.windows.net") | ||
|| host.ends_with("blob.core.windows.net") | ||
|| host.ends_with("dfs.fabric.microsoft.com") | ||
|| host.ends_with("blob.fabric.microsoft.com") | ||
{ | ||
(Self::MicrosoftAzure, url.path()) | ||
} else if host.ends_with("amazonaws.com") { | ||
match host.starts_with("s3") { | ||
true => (Self::AmazonS3, strip_bucket().unwrap_or_default()), | ||
false => (Self::AmazonS3, url.path()), | ||
} | ||
} else if host.ends_with("r2.cloudflarestorage.com") { | ||
(Self::AmazonS3, strip_bucket().unwrap_or_default()) | ||
} else { | ||
(Self::Http, url.path()) | ||
} | ||
}, | ||
_ => bail!("unrecognized url: {url}"), | ||
}; | ||
|
||
Ok((scheme, Path::from_url_path(path)?)) | ||
} | ||
} | ||
|
||
// End copy-pasta'ed code | ||
|
||
pub fn object_store_for_scheme(scheme: &ObjectStoreScheme, path: Path) -> anyhow::Result<Box<DynObjectStore>> { | ||
let store: Box<DynObjectStore> = match &scheme { | ||
ObjectStoreScheme::Local => Box::new(object_store::local::LocalFileSystem::new()), | ||
ObjectStoreScheme::Memory => Box::new(object_store::memory::InMemory::new()), | ||
ObjectStoreScheme::AmazonS3 => Box::new(object_store::aws::AmazonS3Builder::from_env().with_url(path).build()?), | ||
ObjectStoreScheme::MicrosoftAzure => { | ||
Box::new(object_store::azure::MicrosoftAzureBuilder::from_env().with_url(path).build()?) | ||
}, | ||
ObjectStoreScheme::GoogleCloudStorage => Box::new( | ||
object_store::gcp::GoogleCloudStorageBuilder::from_env() | ||
.with_url(path) | ||
.build()?, | ||
), | ||
ObjectStoreScheme::Http => Box::new(object_store::http::HttpBuilder::new().with_url(path).build()?), | ||
}; | ||
Ok(store) | ||
} |
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,5 +1,5 @@ | ||
pub mod external_storage; | ||
mod pod_owners_map; | ||
pub mod storage; | ||
mod trace_filter; | ||
mod trace_store; | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::sync::{ | ||
MutexGuard, | ||
PoisonError, | ||
}; | ||
|
||
use rocket::Responder; | ||
use simkube::store::TraceStore; | ||
|
||
#[derive(Responder)] | ||
pub enum ExportResponseError { | ||
#[response(status = 404)] | ||
StorageNotFound(String), | ||
|
||
#[response(status = 500)] | ||
TracerError(String), | ||
|
||
#[response(status = 502)] | ||
StorageError(String), | ||
} | ||
|
||
impl From<anyhow::Error> for ExportResponseError { | ||
fn from(e: anyhow::Error) -> Self { | ||
Self::TracerError(format!("SimKube error: {e}")) | ||
} | ||
} | ||
|
||
impl From<PoisonError<MutexGuard<'_, TraceStore>>> for ExportResponseError { | ||
fn from(e: PoisonError<MutexGuard<'_, TraceStore>>) -> Self { | ||
Self::TracerError(format!("Mutex was poisoned: {e}")) | ||
} | ||
} | ||
|
||
impl From<url::ParseError> for ExportResponseError { | ||
fn from(e: url::ParseError) -> Self { | ||
Self::TracerError(format!("Could not parse URL: {e}")) | ||
} | ||
} | ||
|
||
impl From<object_store::Error> for ExportResponseError { | ||
fn from(e: object_store::Error) -> Self { | ||
match e { | ||
object_store::Error::NotFound { .. } => { | ||
Self::StorageNotFound(format!("Could not find external storage location: {e}")) | ||
}, | ||
_ => Self::StorageError(format!("Could not write to object store: {e}")), | ||
} | ||
} | ||
} |
Oops, something went wrong.