Skip to content

Commit 046a750

Browse files
authored
Merge pull request #34 from axiomhq/arne/dx-369-add-manual-client-setup-to-axiom-rs-in
Add manual client setup to README, lift query & ingest to top-level and more
2 parents 0b007f7 + 5e742b8 commit 046a750

File tree

19 files changed

+391
-351
lines changed

19 files changed

+391
-351
lines changed

.github/workflows/ci.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on:
3+
on:
44
pull_request:
55
branches:
66
- main
@@ -81,6 +81,25 @@ jobs:
8181
with:
8282
command: test
8383
args: ${{ matrix.flags }} -- --test-threads 1
84+
build_examples:
85+
name: Build examples
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v3
89+
- uses: actions/cache@v3
90+
with:
91+
path: |
92+
~/.cargo/registry
93+
~/.cargo/git
94+
target
95+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
96+
- name: Install rust
97+
uses: actions-rs/toolchain@v1
98+
- name: Run cargo build --examples
99+
uses: actions-rs/cargo@v1
100+
with:
101+
command: build
102+
args: --examples
84103
publish_on_crates_io:
85104
name: Publish on crates.io
86105
runs-on: ubuntu-latest
@@ -89,6 +108,7 @@ jobs:
89108
- rust_fmt_check
90109
- clippy_check
91110
- test
111+
- build_examples
92112
steps:
93113
- uses: actions/checkout@v3
94114
- uses: actions-rs/toolchain@v1

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ tracing = { version = "0.1" }
3434
tokio-stream = "0.1"
3535

3636
[dev-dependencies]
37-
tokio = { version = "1", features = ["rt", "macros"] }
37+
tokio = { version = "1", features = ["full"] }
3838
async-std = { version = "1", features = ["attributes"] }
3939
serde_test = "1"
4040
test-context = "0.1"
4141
async-trait = "0.1"
4242
futures-util = "0.3"
4343
httpmock = "0.6"
44+
structopt = "0.3"
45+
tracing-subscriber = { version = "0.3", features = ["ansi", "env-filter"] }
4446

4547
[features]
4648
default = ["tokio", "default-tls"]

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
For more information check out the [official documentation](https://axiom.co/docs).
2020

21-
## Usage
21+
## Quickstart
2222

2323
Add the following to your Cargo.toml:
2424

@@ -27,9 +27,13 @@ Add the following to your Cargo.toml:
2727
axiom-rs = "0.6"
2828
```
2929

30-
If you use the [Axiom CLI](https://github.com/axiomhq/cli), run `eval $(axiom config export -f)` to configure your environment variables.
30+
If you use the [Axiom CLI](https://github.com/axiomhq/cli), run
31+
`eval $(axiom config export -f)` to configure your environment variables.
3132

32-
Otherwise create a personal token in [the Axiom settings](https://cloud.axiom.co/settings/profile) and export it as `AXIOM_TOKEN`. Set `AXIOM_ORG_ID` to the organization ID from the settings page of the organization you want to access.
33+
Otherwise create a personal token in
34+
[the Axiom settings](https://cloud.axiom.co/settings/profile) and make note of
35+
the organization ID from the settings page of the organization you want to
36+
access.
3337

3438
Create and use a client like this:
3539

@@ -39,16 +43,29 @@ use serde_json::json;
3943

4044
#[tokio::main]
4145
async fn main() -> Result<(), Box<dyn std::error::Error>> {
46+
// Build your client by providing a personal token and an org id:
47+
let client = Client::builder()
48+
.with_token("my-token")
49+
.with_org_id("my-org")
50+
.build()?;
51+
52+
// Alternatively you autoconfigure the client from the environment variables
53+
// AXIOM_TOKEN and AXIOM_ORG_ID:
4254
let client = Client::new()?;
4355

4456
client.datasets.create("my-dataset", "").await?;
4557

46-
client.datasets.ingest("my-dataset", vec![json!({
47-
"foo": "bar",
48-
})]).await?;
58+
client
59+
.ingest(
60+
"my-dataset",
61+
vec![json!({
62+
"foo": "bar",
63+
})],
64+
)
65+
.await?;
4966

50-
let res = client.datasets
51-
.apl_query(r#"['my-dataset'] | where foo == "bar" | limit 100"#, None)
67+
let res = client
68+
.query(r#"['my-dataset'] | where foo == "bar" | limit 100"#, None)
5269
.await?;
5370
println!("{:?}", res);
5471

examples/Cargo.toml

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
# cli
1+
# Examples
22

3-
This example implements a very basic CLI for [Axiom](https://axiom.co).
4-
5-
> **Warning**: This is meant to show some examples on how to call the various methods.
6-
> Please don't actually use this, we have an
7-
> [official CLI](https://github.com/axiomhq/cli).
3+
There's two examples: cli and ingest-hn.
84

95
## Prerequisites
106

11-
You'll need an account at [Axiom](https://cloud.axiom.co) and a personal token.
7+
You'll need an account at [Axiom](https://cloud.axiom.co), a dataset and an API
8+
token that can ingest into that dataset.
9+
10+
## cli
11+
12+
This example implements a very basic CLI for [Axiom](https://axiom.co).
13+
14+
> **Warning**: This is meant to show some examples on how to call the various
15+
> methods.
16+
> Please don't actually use this, we have an
17+
> [official CLI](https://github.com/axiomhq/cli).
1218
13-
## Start the example
19+
### Start the example
1420

1521
```sh
1622
export AXIOM_TOKEN=<your personal token>
1723
export AXIOM_ORG_ID=<your axiom org id>
1824
cargo run
1925
```
2026

21-
## Usage
27+
### Usage
2228

2329
```
2430
$ cd examples/cli && cargo run
@@ -37,5 +43,17 @@ SUBCOMMANDS:
3743
users Work with users
3844
```
3945

40-
You can run something like `cargo run -- datasets --help` to get more
41-
information about subcommands and available flags.
46+
You can run something like `cargo run -- datasets --help` to get more
47+
information about subcommands and available flags.
48+
49+
## ingest-hn
50+
51+
This example ingests all HN posts into an Axiom dataset.
52+
53+
### Start the example
54+
55+
```sh
56+
export DATASET_NAME=<your dataset name>
57+
export AXIOM_TOKEN=<your api token>
58+
cargo run
59+
```

examples/cli/src/main.rs renamed to examples/cli.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
100100
let mut buf = Vec::new();
101101
stdin().read_to_end(&mut buf).await?;
102102
let ingest_status = client
103-
.datasets
104-
.ingest_raw(&name, buf, content_type, content_encoding)
103+
.ingest_bytes(&name, buf, content_type, content_encoding)
105104
.await?;
106105
println!("{:?}", ingest_status);
107106
}
108107
Datasets::Query { apl } => {
109-
let result = client.datasets.apl_query(apl, None).await?;
108+
let result = client.query(apl, None).await?;
110109
println!("{:?}", result);
111110
}
112111
},

examples/cli/Cargo.toml

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/ingest-hn/src/main.rs renamed to examples/ingest-hn.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3333
})
3434
.buffered(100);
3535
Client::new()?
36-
.datasets
3736
.try_ingest_stream(dataset_name, stream)
3837
.await?;
3938
Ok(())

examples/ingest-hn/Cargo.toml

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/ingest-hn/README.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)