Skip to content

Commit

Permalink
Merge pull request #10 from statsig-io/08-27-_sync_code_stable_versio…
Browse files Browse the repository at this point in the history
…n_bump

[Sync Code] See description for change list
  • Loading branch information
ealui-statsig authored Aug 27, 2024
2 parents 41fdcac + a45a4ac commit db81935
Show file tree
Hide file tree
Showing 26 changed files with 983 additions and 389 deletions.
113 changes: 99 additions & 14 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tokio = { version = "1.35.1", features = ["full"] }
reqwest = { version = "0.12.0", features = ["gzip"] }
futures = "0.3.30"
envy = "0.4.2"
serde = { version = "1.0.130" }
serde = { version = "1.0.130", features = ["derive"] }
redis = { version = "0.25.1", features = ["tokio-rustls-comp", "tokio-comp"] }
bb8 = { version = "0.8.1" }
bb8-redis = { version = "0.15.0" }
Expand All @@ -31,6 +31,10 @@ cloud_profiler_rust = "1.1.1"
statsig = "0.3.0"
uuid = { version="1.8.0", features = ["v4", "fast-rng"] }
chrono = "0.4.38"
serde_with = "3.9.0"
libflate = "2.1.0"
serde_json = "1.0.120"
once_cell = "1.19.0"


[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions Rocket.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[global]
address = "0.0.0.0"
limits = { json = "5 MiB", string = "5 MiB" }
2 changes: 1 addition & 1 deletion api-interface-definitions
42 changes: 29 additions & 13 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ pub mod statsig_forward_proxy {
tonic::include_proto!("statsig_forward_proxy");
}

fn last_500_char(spec: &String) -> String {
// only print last 500 characters
let len = spec.len();
let start = if len > 500 { len - 500 } else { 0 };
spec[start..].to_string()
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = StatsigForwardProxyClient::connect("http://0.0.0.0:50051")
Expand All @@ -14,21 +21,29 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.max_decoding_message_size(16777216);

// Non-Streaming
let request = tonic::Request::new(ConfigSpecRequest {
since_time: Some(1234),
sdk_key: "1234".into(),
});
let response: tonic::Response<statsig_forward_proxy::ConfigSpecResponse> =
client.get_config_spec(request).await?;
println!(
"RESPONSE={:?}, CURRENT TIME={}",
response.into_inner().last_updated,
Local::now()
);
for version in 0..3 {
let request = tonic::Request::new(ConfigSpecRequest {
since_time: Some(1234),
sdk_key: "1234".into(),
version: Some(version),
});
let response: tonic::Response<statsig_forward_proxy::ConfigSpecResponse> =
client.get_config_spec(request).await?;
let config_response = response.into_inner();
println!(
"Version={}, RESPONSE={:?}, CURRENT TIME={}, SPEC={}\n",
version,
&config_response.last_updated,
Local::now(),
last_500_char(&config_response.spec)
);
}

// Streaming
let request = tonic::Request::new(ConfigSpecRequest {
since_time: Some(1234),
sdk_key: "1234".into(),
version: Some(2),
});
let response = client.stream_config_spec(request).await?;
println!("Metadata={:?}", response.metadata());
Expand All @@ -38,9 +53,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
match stream.message().await {
Ok(Some(value)) => {
println!(
"STREAMING={:?}, CURRENT TIME={}",
"STREAMING={:?}, CURRENT TIME={}, SPEC={}",
value.last_updated,
Local::now()
Local::now(),
last_500_char(&value.spec)
);
}
Ok(None) => {
Expand Down
Loading

0 comments on commit db81935

Please sign in to comment.