Skip to content

Commit

Permalink
Keep alive timeouts to detect broken connections
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Jul 18, 2022
1 parent 413e0a1 commit 855d947
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# gcloud-sdk for Rust

[![Rust Documentation](https://docs.rs/gcloud-sdk/badge.svg)](https://docs.rs/gcloud-sdk)
[![Latest Version](https://img.shields.io/crates/v/gcloud-sdk.svg)](https://crates.io/crates/gcloud-sdk)

This library generated from [Google API](https://github.com/googleapis/googleapis) using [tonic-build](https://github.com/hyperium/tonic/tree/master/tonic-build).

This is not official gcloud sdk from Google (and it doesn't exist for Rust at the moment of this page was updated).
This is NOT OFFICAL gcloud sdk from Google (and it doesn't exist for Rust at the moment of this page was updated).

## Overview
This library contains all the code generated from the Google API.
Expand Down Expand Up @@ -48,7 +47,7 @@ fn test() {
Cargo.toml:
```toml
[dependencies]
gcloud-sdk = { version = "0.12", features = ["google-spanner-admin-database-v1"] }
gcloud-sdk = { version = "0.14", features = ["google-spanner-admin-database-v1"] }
tonic = { version = "0.7", features = ["tls"] }
prost = "0.10"
prost-types = "0.10"
Expand Down Expand Up @@ -77,12 +76,16 @@ the updates and API proto descriptions from Google more frequently and simplify
* This fork focuses on simplicity and provided authentication capabilities natively.
* Has direct dependencies to tokio runtime and chrono.
Uses synchronisation primitives (such as Mutex) from tokio everywhere.
* Provides facade API for the caching async client implementation
* Provides facade API for the caching async client implementation based on Tower middleware
that hides complexity working with tokens and TLS.
* Improved observability with tracing and measuring execution time of endpoints.
- Different development cycles - the original development was updated less frequently than it was needed for me.

I'd be glad to contribute all of the changes back if author sees the same goals.

## High-level APIs
Sometimes using proto generated API is tedious and cumbersome, and there is a real

## License
Licensed under either of [Apache License, Version 2.0](./LICENSE-APACHE)
or [MIT license](./LICENSE-MIT) at your option.
Expand Down
8 changes: 7 additions & 1 deletion gcloud-sdk/src/api_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::marker::PhantomData;
use std::time::Duration;

use crate::auth_token_generator::GoogleAuthTokenGenerator;
use crate::token_source::auth_token_generator::GoogleAuthTokenGenerator;
use async_trait::async_trait;
use tonic::transport::Channel;
use tower::ServiceBuilder;
Expand Down Expand Up @@ -132,6 +133,11 @@ async fn init_google_services_channel(

Ok(Channel::from_static(api_url)
.tls_config(tls_config)?
.connect_timeout(Duration::from_secs(30))
.tcp_keepalive(Some(Duration::from_secs(5)))
.keep_alive_timeout(Duration::from_secs(60))
.http2_keep_alive_interval(Duration::from_secs(10))
.keep_alive_while_idle(true)
.connect()
.await?)
}
Expand Down
1 change: 0 additions & 1 deletion gcloud-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ mod token_source;
mod api_client;
pub use api_client::*;

mod auth_token_generator;
mod middleware;
2 changes: 1 addition & 1 deletion gcloud-sdk/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::auth_token_generator::GoogleAuthTokenGenerator;
use crate::token_source::auth_token_generator::GoogleAuthTokenGenerator;
use chrono::Utc;
use futures::{Future, TryFutureExt};
use std::pin::Pin;
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions gcloud-sdk/src/token_source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use std::path::PathBuf;
use async_trait::async_trait;
use chrono::prelude::*;

pub mod auth_token_generator;
mod credentials;
mod metadata;

use serde::{Deserialize, Serialize};

use credentials::{from_env_var, from_well_known_file};
Expand Down

0 comments on commit 855d947

Please sign in to comment.