Skip to content

Commit

Permalink
Merge pull request #162 from umccr/config-refactor
Browse files Browse the repository at this point in the history
feat: additional features to make configuration simpler
  • Loading branch information
mmalenic authored Mar 22, 2023
2 parents acca24a + 5aa2616 commit f9b341d
Show file tree
Hide file tree
Showing 54 changed files with 2,459 additions and 1,695 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ jobs:
with:
command: build
args: --all-targets --features s3-storage
- name: Run cargo test
- name: Run cargo tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
- name: Run cargo tests no default features
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features
3 changes: 3 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ members = [
"htsget-http",
"htsget-lambda",
"htsget-search",
"htsget-test",
]
"htsget-test"
]
2 changes: 1 addition & 1 deletion data/events/event_get.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"httpMethod": "GET",
"path": "/variants/vcf/sample1-bcbio-cancer",
"path": "/variants/1-vcf/sample1-bcbio-cancer",
"body": null,

"resource": "/{proxy+}",
Expand Down
2 changes: 1 addition & 1 deletion data/events/event_parameterized_get.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"httpMethod": "GET",
"path": "/variants/vcf/sample1-bcbio-cancer",
"path": "/variants/1-vcf/sample1-bcbio-cancer",
"body": null,

"resource": "/{proxy+}",
Expand Down
2 changes: 1 addition & 1 deletion data/events/event_parameterized_post.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"httpMethod": "POST",
"path": "/variants/vcf/sample1-bcbio-cancer",
"path": "/variants/1-vcf/sample1-bcbio-cancer",
"body": "{\"format\": \"VCF\", \"regions\": [{\"referenceName\": \"chrM\"}]}",

"resource": "/{proxy+}",
Expand Down
2 changes: 1 addition & 1 deletion data/events/event_parameterized_post_class_header.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"httpMethod": "POST",
"path": "/variants/vcf/sample1-bcbio-cancer",
"path": "/variants/1-vcf/sample1-bcbio-cancer",
"body": "{\"format\": \"VCF\", \"class\": \"header\", \"regions\": [{\"referenceName\": \"chrM\"}]}",

"resource": "/{proxy+}",
Expand Down
2 changes: 1 addition & 1 deletion data/events/event_post.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"httpMethod": "POST",
"path": "/variants/vcf/sample1-bcbio-cancer",
"path": "/variants/1-vcf/sample1-bcbio-cancer",
"body": null,

"resource": "/{proxy+}",
Expand Down
21 changes: 7 additions & 14 deletions deploy/config/config_dev_umccr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,29 @@ documentation_url = "https://github.com/umccr/htsget-rs"
environment = "dev"

[[resolvers]]
regex = '^umccr-10c-data-dev/(?P<key>.*)$'
regex = '^(umccr-10c-data-dev)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-10c-data-dev' }

[[resolvers]]
regex = '^umccr-10f-data-dev/(?P<key>.*)$'
regex = '^(umccr-10f-data-dev)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-10f-data-dev' }

[[resolvers]]
regex = '^umccr-10g-data-dev/(?P<key>.*)$'
regex = '^(umccr-10g-data-dev)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-10g-data-dev' }

[[resolvers]]
regex = '^umccr-agha-test-dev/(?P<key>.*)$'
regex = '^(umccr-agha-test-dev)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-agha-test-dev' }

[[resolvers]]
regex = '^umccr-research-dev/(?P<key>.*)$'
regex = '^(umccr-research-dev)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-research-dev' }

[[resolvers]]
regex = '^umccr-primary-data-dev/(?P<key>.*)$'
regex = '^(umccr-primary-data-dev)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-primary-data-dev' }

[[resolvers]]
regex = '^umccr-validation-prod/(?P<key>.*)$'
regex = '^(umccr-validation-prod)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-validation-prod' }
9 changes: 3 additions & 6 deletions deploy/config/config_prod_umccr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ documentation_url = "https://github.com/umccr/htsget-rs"
environment = "prod"

[[resolvers]]
regex = '^umccr-research-dev/(?P<key>.*)$'
regex = '^(umccr-research-dev)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-research-dev' }

[[resolvers]]
regex = '^umccr-validation-prod/(?P<key>.*)$'
regex = '^(umccr-validation-prod)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-validation-prod' }

[[resolvers]]
regex = '^umccr-primary-data-prod/(?P<key>.*)$'
regex = '^(umccr-primary-data-prod)/(?P<key>.*)$'
substitution_string = '$key'
storage_type = { type = 'S3', bucket = 'umccr-primary-data-prod' }
16 changes: 8 additions & 8 deletions htsget-actix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ This crate uses [htsget-config] for configuration. See [htsget-config] for detai

To run an instance of this crate, execute the following command:
```sh
cargo run -p htsget-actix
cargo run -p htsget-actix --no-default-features
```
Using the default configuration, this will start a ticket server on `127.0.0.1:8080` and a data block server on `127.0.0.1:8081`
with data accessible from the [`data`][data] directory.

If only `LocalStorage` is required, compiling code related `AwsS3Storage` can be avoided by running the following:

To use `AwsS3Storage`, avoid compiling with no default features:
```sh
cargo run -p htsget-actix --no-default-features
cargo run -p htsget-actix
```
This will start a ticket server with `AwsS3Storage` using a bucket called `"data"`.

See [htsget-search] for details on how to structure files.

Expand Down Expand Up @@ -70,25 +70,25 @@ Some example requests using `curl` are shown below:
* GET

```sh
curl '127.0.0.1:8080/variants/vcf/sample1-bcbio-cancer'
curl '127.0.0.1:8080/variants/data/vcf/sample1-bcbio-cancer'
```

* POST

```sh
curl --header "Content-Type: application/json" -d '{}' '127.0.0.1:8080/variants/vcf/sample1-bcbio-cancer'
curl --header "Content-Type: application/json" -d '{}' '127.0.0.1:8080/variants/data/vcf/sample1-bcbio-cancer'
```

* Parametrised GET

```sh
curl '127.0.0.1:8080/variants/vcf/sample1-bcbio-cancer?format=VCF&class=header'
curl '127.0.0.1:8080/variants/data/vcf/sample1-bcbio-cancer?format=VCF&class=header'
```

* Parametrised POST

```sh
curl --header "Content-Type: application/json" -d '{"format": "VCF", "regions": [{"referenceName": "chrM"}]}' '127.0.0.1:8080/variants/vcf/sample1-bcbio-cancer'
curl --header "Content-Type: application/json" -d '{"format": "VCF", "regions": [{"referenceName": "chrM"}]}' '127.0.0.1:8080/variants/data/vcf/sample1-bcbio-cancer'
```

* Service info
Expand Down
17 changes: 11 additions & 6 deletions htsget-actix/benches/request_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use reqwest::blocking::ClientBuilder;
use reqwest::Result;
use serde::{Deserialize, Serialize};

use htsget_config::types::{Headers, JsonResponse};
use htsget_http::{PostRequest, Region};
use htsget_search::htsget::{Headers, JsonResponse};
use htsget_test::http_tests::{default_config_fixed_port, default_dir, default_dir_data};

const REFSERVER_DOCKER_IMAGE: &str = "ga4gh/htsget-refserver:1.5.0";
Expand Down Expand Up @@ -54,6 +54,7 @@ fn request(url: reqwest::Url, json_content: &impl Serialize, client: &Client) ->
.unwrap()
.json()
.unwrap();

response
.htsget
.urls
Expand Down Expand Up @@ -144,6 +145,7 @@ fn start_htsget_rs() -> (DropGuard, String) {
.arg("run")
.arg("-p")
.arg("htsget-actix")
.arg("--no-default-features")
.env("HTSGET_PATH", default_dir_data())
.env("RUST_LOG", "warn")
.spawn()
Expand Down Expand Up @@ -234,7 +236,7 @@ fn criterion_benchmark(c: &mut Criterion) {
bench_pair(
&mut group,
"[LIGHT] simple request",
format_url(&htsget_rs_url, "reads/bam/htsnexus_test_NA12878"),
format_url(&htsget_rs_url, "reads/data/bam/htsnexus_test_NA12878"),
format_url(&htsget_refserver_url, "reads/htsnexus_test_NA12878"),
&json_content,
);
Expand All @@ -254,7 +256,7 @@ fn criterion_benchmark(c: &mut Criterion) {
bench_pair(
&mut group,
"[LIGHT] with region",
format_url(&htsget_rs_url, "reads/bam/htsnexus_test_NA12878"),
format_url(&htsget_rs_url, "reads/data/bam/htsnexus_test_NA12878"),
format_url(&htsget_refserver_url, "reads/htsnexus_test_NA12878"),
&json_content,
);
Expand All @@ -281,7 +283,7 @@ fn criterion_benchmark(c: &mut Criterion) {
bench_pair(
&mut group,
"[LIGHT] with two regions",
format_url(&htsget_rs_url, "reads/bam/htsnexus_test_NA12878"),
format_url(&htsget_rs_url, "reads/data/bam/htsnexus_test_NA12878"),
format_url(&htsget_refserver_url, "reads/htsnexus_test_NA12878"),
&json_content,
);
Expand All @@ -301,7 +303,7 @@ fn criterion_benchmark(c: &mut Criterion) {
bench_pair(
&mut group,
"[LIGHT] with VCF",
format_url(&htsget_rs_url, "variants/vcf/sample1-bcbio-cancer"),
format_url(&htsget_rs_url, "variants/data/vcf/sample1-bcbio-cancer"),
format_url(&htsget_refserver_url, "variants/sample1-bcbio-cancer"),
&json_content,
);
Expand All @@ -321,7 +323,10 @@ fn criterion_benchmark(c: &mut Criterion) {
bench_pair(
&mut group,
"[HEAVY] with big VCF",
format_url(&htsget_rs_url, "variants/vcf/internationalgenomesample"),
format_url(
&htsget_rs_url,
"variants/data/vcf/internationalgenomesample",
),
format_url(&htsget_refserver_url, "variants/internationalgenomesample"),
&json_content,
);
Expand Down
2 changes: 1 addition & 1 deletion htsget-actix/src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use actix_web::{http::StatusCode, Either, Responder};

use htsget_config::types::JsonResponse;
use htsget_http::Result;
use htsget_search::htsget::JsonResponse;
use pretty_json::PrettyJson;

pub use crate::handlers::service_info::{
Expand Down
38 changes: 21 additions & 17 deletions htsget-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use tracing_actix_web::TracingLogger;

use htsget_config::config::cors::CorsConfig;
pub use htsget_config::config::{Config, DataServerConfig, ServiceInfo, TicketServerConfig, USAGE};
#[cfg(feature = "s3-storage")]
pub use htsget_config::regex_resolver::aws::S3Resolver;
pub use htsget_config::regex_resolver::StorageType;
pub use htsget_config::storage::Storage;
use htsget_search::htsget::from_storage::HtsGetFromStorage;
use htsget_search::htsget::HtsGet;
use htsget_search::storage::local::LocalStorage;
Expand Down Expand Up @@ -144,10 +142,10 @@ mod tests {
use actix_web::dev::ServiceResponse;
use actix_web::{test, web, App};
use async_trait::async_trait;
use htsget_search::htsget::JsonResponse;
use tempfile::TempDir;

use htsget_search::storage::data_server::HttpTicketFormatter;
use htsget_config::types::JsonResponse;
use htsget_search::storage::data_server::BindDataServer;
use htsget_test::http_tests::{config_with_tls, default_test_config};
use htsget_test::http_tests::{
Header as TestHeader, Response as TestResponse, TestRequest, TestServer,
Expand Down Expand Up @@ -197,6 +195,18 @@ mod tests {

#[async_trait(?Send)]
impl TestServer<ActixTestRequest<test::TestRequest>> for ActixTestServer {
async fn get_expected_path(&self) -> String {
let mut bind_data_server =
BindDataServer::try_from(self.get_config().data_server().clone()).unwrap();
let server = bind_data_server.bind_data_server().await.unwrap();
let addr = server.local_addr();

let path = self.get_config().data_server().local_path().to_path_buf();
tokio::spawn(async move { server.serve(path).await.unwrap() });

expected_url_path(self.get_config(), addr)
}

fn get_config(&self) -> &Config {
&self.config
}
Expand All @@ -205,18 +215,13 @@ mod tests {
ActixTestRequest(test::TestRequest::default())
}

async fn test_server(&self, request: ActixTestRequest<test::TestRequest>) -> TestResponse {
let mut formatter =
HttpTicketFormatter::try_from(self.get_config().data_server().clone()).unwrap();
let server = formatter.bind_data_server().await.unwrap();
let addr = server.local_addr();

let path = self.get_config().data_server().local_path().to_path_buf();
tokio::spawn(async move { server.serve(path).await.unwrap() });

let expected_path = expected_url_path(self.get_config(), addr);
async fn test_server(
&self,
request: ActixTestRequest<test::TestRequest>,
expected_path: String,
) -> TestResponse {
let response = self.get_response(request.0).await;

let response = self.get_response(request.0, formatter).await;
let status: u16 = response.status().into();
let mut headers = response.headers().clone();
let bytes = test::read_body(response).await.to_vec();
Expand All @@ -243,7 +248,6 @@ mod tests {
async fn get_response(
&self,
request: test::TestRequest,
_formatter: HttpTicketFormatter,
) -> ServiceResponse<EitherBody<BoxBody>> {
println!("{:#?}", self.config);
let app = test::init_service(
Expand Down
6 changes: 3 additions & 3 deletions htsget-actix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use tokio::select;

use htsget_actix::run_server;
use htsget_actix::Config;
use htsget_search::storage::data_server::HttpTicketFormatter;
use htsget_search::storage::data_server::BindDataServer;

#[actix_web::main]
async fn main() -> std::io::Result<()> {
Expand All @@ -13,9 +13,9 @@ async fn main() -> std::io::Result<()> {

if config.data_server().enabled() {
let server = config.data_server().clone();
let mut formatter = HttpTicketFormatter::from(server.clone());
let mut bind_data_server = BindDataServer::from(server.clone());

let local_server = formatter.bind_data_server().await?;
let local_server = bind_data_server.bind_data_server().await?;
let local_server =
tokio::spawn(async move { local_server.serve(&server.local_path()).await });

Expand Down
3 changes: 3 additions & 0 deletions htsget-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ s3-storage = []
default = ["s3-storage"]

[dependencies]
thiserror = "1.0"
async-trait = "0.1"
noodles = { version = "0.32", features = ["core"] }
serde = { version = "1.0", features = ["derive"] }
serde_with = "2.2"
Expand All @@ -30,3 +32,4 @@ http-serde = "1.1"

[dev-dependencies]
figment = { version = "0.10", features = ["test"] }
tokio = { version = "1.25", features = ["macros", "rt-multi-thread"] }
Loading

0 comments on commit f9b341d

Please sign in to comment.