Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
integration_test:
name: Integration Tests (stable/ubuntu-latest)
runs-on: ubuntu-latest
strategy:
matrix:
http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client]
services:
influxdb:
image: influxdb:1.8
Expand All @@ -67,7 +70,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --package influxdb --package influxdb_derive --all-features --no-fail-fast
- run: cargo test --manifest-path=./influxdb/Cargo.toml --no-default-features --features 'use-serde derive ${{ matrix.http-backend }}' --no-fail-fast

coverage:
name: Code Coverage (stable/ubuntu-20.04)
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Pull requests are always welcome. See [Contributing](https://github.com/Empty2k1
- `#[derive(InfluxDbWriteable)]` Derive Macro for Writing / Reading into Structs
- `GROUP BY` support
- Tokio and async-std support (see example below) or [available backends](https://github.com/Empty2k12/influxdb-rust/blob/master/influxdb/Cargo.toml)
- Swappable HTTP backends ([see below](#Choice-of-HTTP-backend))

## Quickstart

Expand Down Expand Up @@ -98,6 +99,31 @@ async fn main() {
For further examples, check out the Integration Tests in `tests/integration_tests.rs`
in the repository.

## Choice of HTTP backend

To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature:

- **[hyper](https://github.com/hyperium/hyper)** (used by default)
```toml
influxdb = { version = "0.3.0", features = ["derive"] }
```
- **[curl](https://github.com/alexcrichton/curl-rust)**, using [libcurl](https://curl.se/libcurl/)
```toml
influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "curl-client"] }
```
- **[async-h1](https://github.com/http-rs/async-h1)** with native TLS (OpenSSL)
```toml
influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client"] }
```
- **[async-h1](https://github.com/http-rs/async-h1)** with [rutstls](https://github.com/ctz/rustls)
```toml
influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client-rustls"] }
```
- WebAssembly's `window.fetch`, via `web-sys` and **[wasm-bindgen](https://github.com/rustwasm/wasm-bindgen)**
```toml
influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "wasm-client"] }
```

## License

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand Down
3 changes: 2 additions & 1 deletion influxdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ futures = "0.3.4"
lazy_static = "1.4.0"
influxdb_derive = { version = "0.3.0", optional = true }
regex = "1.3.5"
surf = { version = "2.1.0", default-features = false }
surf = { version = "2.2.0", default-features = false }
serde = { version = "1.0.104", features = ["derive"], optional = true }
serde_json = { version = "1.0.48", optional = true }
thiserror = "1.0"
Expand All @@ -30,6 +30,7 @@ thiserror = "1.0"
use-serde = ["serde", "serde_json"]
curl-client = ["surf/curl-client"]
h1-client = ["surf/h1-client"]
h1-client-rustls = ["surf/h1-client-rustls"]
hyper-client = ["surf/hyper-client"]
wasm-client = ["surf/wasm-client"]
default = ["use-serde", "hyper-client"]
Expand Down
26 changes: 26 additions & 0 deletions influxdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//! - `#[derive(InfluxDbWriteable)]` Derive Macro for Writing / Reading into Structs
//! - `GROUP BY` support
//! - Tokio and async-std support (see example below) or [available backends](https://github.com/Empty2k12/influxdb-rust/blob/master/influxdb/Cargo.toml)
//! - Swappable HTTP backends ([see below](#Choice-of-HTTP-backend))
//!
//! # Quickstart
//!
Expand Down Expand Up @@ -66,6 +67,31 @@
//! For further examples, check out the Integration Tests in `tests/integration_tests.rs`
//! in the repository.
//!
//! # Choice of HTTP backend
//!
//! To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature:
//!
//! - **[hyper](https://github.com/hyperium/hyper)** (used by default)
//! ```toml
//! influxdb = { version = "0.3.0", features = ["derive"] }
//! ```
//! - **[curl](https://github.com/alexcrichton/curl-rust)**, using [libcurl](https://curl.se/libcurl/)
//! ```toml
//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "curl-client"] }
//! ```
//! - **[async-h1](https://github.com/http-rs/async-h1)** with native TLS (OpenSSL)
//! ```toml
//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client"] }
//! ```
//! - **[async-h1](https://github.com/http-rs/async-h1)** with [rutstls](https://github.com/ctz/rustls)
//! ```toml
//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client-rustls"] }
//! ```
//! - WebAssembly's `window.fetch`, via `web-sys` and **[wasm-bindgen](https://github.com/rustwasm/wasm-bindgen)**
//! ```toml
//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "wasm-client"] }
//! ```
//!
//! # License
//!
//! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand Down
22 changes: 11 additions & 11 deletions influxdb/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn test_ping_influx_db_tokio() {
async fn test_connection_error() {
let test_name = "test_connection_error";
let client =
Client::new("http://localhost:10086", test_name).with_auth("nopriv_user", "password");
Client::new("http://127.0.0.1:10086", test_name).with_auth("nopriv_user", "password");
let read_query = Query::raw_read_query("SELECT * FROM weather");
let read_result = client.query(&read_query).await;
assert_result_err(&read_result);
Expand All @@ -75,15 +75,15 @@ async fn test_authed_write_and_read() {
run_test(
|| async move {
let client =
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
let query = format!("CREATE DATABASE {}", TEST_NAME);
client
.query(&Query::raw_read_query(query))
.await
.expect("could not setup db");

let client =
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
let write_query = Timestamp::Hours(11)
.into_query("weather")
.add_field("temperature", 82);
Expand All @@ -100,7 +100,7 @@ async fn test_authed_write_and_read() {
},
|| async move {
let client =
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
let query = format!("DROP DATABASE {}", TEST_NAME);

client
Expand All @@ -123,15 +123,15 @@ async fn test_wrong_authed_write_and_read() {
run_test(
|| async move {
let client =
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
let query = format!("CREATE DATABASE {}", TEST_NAME);
client
.query(&Query::raw_read_query(query))
.await
.expect("could not setup db");

let client =
Client::new("http://localhost:9086", TEST_NAME).with_auth("wrong_user", "password");
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("wrong_user", "password");
let write_query = Timestamp::Hours(11)
.into_query("weather")
.add_field("temperature", 82);
Expand All @@ -156,7 +156,7 @@ async fn test_wrong_authed_write_and_read() {
),
}

let client = Client::new("http://localhost:9086", TEST_NAME)
let client = Client::new("http://127.0.0.1:9086", TEST_NAME)
.with_auth("nopriv_user", "password");
let read_query = Query::raw_read_query("SELECT * FROM weather");
let read_result = client.query(&read_query).await;
Expand All @@ -171,7 +171,7 @@ async fn test_wrong_authed_write_and_read() {
},
|| async move {
let client =
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
let query = format!("DROP DATABASE {}", TEST_NAME);
client
.query(&Query::raw_read_query(query))
Expand All @@ -193,13 +193,13 @@ async fn test_non_authed_write_and_read() {
run_test(
|| async move {
let client =
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
let query = format!("CREATE DATABASE {}", TEST_NAME);
client
.query(&Query::raw_read_query(query))
.await
.expect("could not setup db");
let non_authed_client = Client::new("http://localhost:9086", TEST_NAME);
let non_authed_client = Client::new("http://127.0.0.1:9086", TEST_NAME);
let write_query = Timestamp::Hours(11)
.into_query("weather")
.add_field("temperature", 82);
Expand All @@ -226,7 +226,7 @@ async fn test_non_authed_write_and_read() {
},
|| async move {
let client =
Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password");
Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password");
let query = format!("DROP DATABASE {}", TEST_NAME);
client
.query(&Query::raw_read_query(query))
Expand Down
2 changes: 1 addition & 1 deletion influxdb/tests/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn create_client<T>(db_name: T) -> Client
where
T: Into<String>,
{
Client::new("http://localhost:8086", db_name)
Client::new("http://127.0.0.1:8086", db_name)
}

#[cfg(not(tarpaulin_include))]
Expand Down