Skip to content

Commit

Permalink
feat(err): get resolver trait working (#25420)
Browse files Browse the repository at this point in the history
Co-authored-by: David Newell <[email protected]>
  • Loading branch information
oliverb123 and daibhin authored Oct 8, 2024
1 parent c598564 commit 76c7271
Show file tree
Hide file tree
Showing 26 changed files with 1,481 additions and 154 deletions.
146 changes: 145 additions & 1 deletion rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions rust/cymbal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ common-metrics = { path = "../common/metrics" }
common-alloc = { path = "../common/alloc" }
common-kafka = { path = "../common/kafka" }
common-types = { path = "../common/types" }
common-dns = { path = "../common/dns" }
thiserror = { workspace = true }
sqlx = { workspace = true }
serde_json = { workspace = true }
serde = { workspace = true }
sourcemap = "9.0.0"
reqwest = { workspace = true }

[dev-dependencies]
httpmock = { workspace = true }

[lints]
workspace = true
19 changes: 18 additions & 1 deletion rust/cymbal/src/app_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ use health::{HealthHandle, HealthRegistry};
use sqlx::{postgres::PgPoolOptions, PgPool};
use tracing::info;

use crate::{config::Config, error::Error};
use crate::{
config::Config,
error::Error,
resolver::{Resolver, ResolverImpl},
symbol_store::{basic::BasicStore, caching::CachingStore},
};

pub struct AppContext {
pub health_registry: HealthRegistry,
pub worker_liveness: HealthHandle,
pub consumer: SingleTopicConsumer,
pub pool: PgPool,
pub resolver: Box<dyn Resolver>,
}

impl AppContext {
Expand All @@ -31,11 +37,22 @@ impl AppContext {
config.consumer.kafka_consumer_topic
);

// We're going to make heavy use of this "layering" pattern with stores, e.g. a we'll add an s3
// store that wraps an underlying basic one and stores the returned values in s3, and looks in s3
// before making fetches, etc.
let symbol_store = BasicStore::new(config)?;
let symbol_store =
CachingStore::new(Box::new(symbol_store), config.symbol_store_cache_max_bytes);

// Box box, box box
let resolver = Box::new(ResolverImpl::new(Box::new(symbol_store)));

Ok(Self {
health_registry,
worker_liveness,
consumer,
pool,
resolver,
})
}
}
10 changes: 10 additions & 0 deletions rust/cymbal/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ pub struct Config {

#[envconfig(default = "true")]
pub skip_reads: bool,

// cymbal makes HTTP get requests to auto-resolve sourcemaps - and follows redirects. To protect against SSRF, we only allow requests to public URLs by default
#[envconfig(default = "false")]
pub allow_internal_ips: bool,

#[envconfig(default = "30")]
pub sourcemap_timeout_seconds: u64,

#[envconfig(default = "100000000")] // 100MB - in prod, we should use closer to 1-10GB
pub symbol_store_cache_max_bytes: usize,
}

impl Config {
Expand Down
10 changes: 10 additions & 0 deletions rust/cymbal/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ pub enum Error {
KafkaError(#[from] KafkaError),
#[error("Sqlx error: {0}")]
SqlxError(#[from] sqlx::Error),
#[error("Reqwest error: {0}")]
ReqwestError(#[from] reqwest::Error),
#[error("Not implemented error: {0}")]
NotImplementedError(String),
#[error("Lookup failed: {0}")]
LookupFailed(String),
#[error("Could not get source ref from: {0}")]
InvalidSourceRef(String),
#[error("sourcemap error: {0}")]
SourceMapError(#[from] sourcemap::Error),
}
Loading

0 comments on commit 76c7271

Please sign in to comment.