Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- run: go run github.com/vkcom/statshouse/cmd/statshouse-client-test@master
- run: go run github.com/VKCOM/statshouse/cmd/statshouse-client-test@master
10 changes: 5 additions & 5 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 @@ -15,8 +15,8 @@ opt-level = 1
[workspace.package]
version = "0.1.0"
authors = ["V Kontakte LLC"]
homepage = "https://github.com/vkcom/statshouse-rs"
repository = "https://github.com/vkcom/statshouse-rs"
homepage = "https://github.com/VKCOM/statshouse-rs"
repository = "https://github.com/VKCOM/statshouse-rs"
categories = [
"statshouse",
"observability",
Expand Down
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# statshouse-rs

Rust client library for StatsHouse.

This repository is a Cargo workspace with:
- `statshouse/`: the client library crate
- `xtask/`: developer tooling (`cargo x`)

## Usage

Add the dependency:

```toml
[dependencies]
statshouse = "0.1.0"
```

Send a counter metric:

```rust
use statshouse::{MetricBuilder, Transport};

fn main() {
let mut transport = Transport::default();

MetricBuilder::new(b"requests_total")
.tag(b"env", b"staging")
.tag(b"service", b"api")
.write_count(&mut transport, 1.0, 0);
}
```

Send value metric:

```rust
use statshouse::{MetricBuilder, Transport};

fn main() {
let mut transport = Transport::new("127.0.0.1:13337");

MetricBuilder::new(b"latency_ms")
.tag(b"env", b"staging")
.write_values(&mut transport, &[12.3, 18.9, 7.4], 0.0, 0);

}
```

## Development

Single command to run all checks: `cargo x ci`

## License

MPL-2.0
5 changes: 4 additions & 1 deletion statshouse/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[package]
name = "statshouse"
version.workspace = true
description = "StatsHouse client library for Rust"
authors.workspace = true
homepage.workspace = true
repository.workspace = true
categories.workspace = true
categories = ["api-bindings"]
keywords = ["statshouse", "metrics"]
readme = "../README.md"
license.workspace = true
edition.workspace = true

Expand Down
7 changes: 5 additions & 2 deletions statshouse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ use std::io::{Error, ErrorKind};
use std::net::{Ipv4Addr, ToSocketAddrs, UdpSocket};
use std::time::{SystemTime, UNIX_EPOCH};

#[cfg(target_os = "macos")]
const MAX_DATAGRAM_SIZE: usize = 9216; // sysctl net.inet.udp.maxdgram
#[cfg(not(target_os = "macos"))]
const MAX_DATAGRAM_SIZE: usize = 65507; // https://stackoverflow.com/questions/42609561/udp-maximum-packet-size/42610200
const MAX_FULL_KEY_SIZE: usize = 1024; // roughly metric plus all tags
const MAX_FULL_KEY_SIZE: usize = 4096; // roughly metric plus all tags
const TL_MAX_TINY_STRING_LEN: usize = 253;
const TL_BIG_STRING_LEN: usize = 0x00ff_ffff;
const TL_BIG_STRING_MARKER: usize = 0xfe;
Expand Down Expand Up @@ -282,7 +285,7 @@ impl MetricBuilder {
m.tl_buffer_overflow = !m.tl_buffer.write_u32(0);
} else {
m.tl_buffer_overflow = true;
};
}
m
}

Expand Down
4 changes: 2 additions & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn assert_no_more_args(parser: &mut Parser) -> Result<(), BoxedError> {
match parser.next()? {
Some(Short(c)) => Err(format!("unexpected option: -{c}").into()),
Some(Long(s)) => Err(format!("unexpected option: --{s}").into()),
Some(Value(v)) => Err(format!("unexpected value: {v:?}").into()),
Some(Value(v)) => Err(format!("unexpected value: {}", v.display()).into()),
None => Ok(()),
}
}
Expand All @@ -56,7 +56,7 @@ fn run_ci(parser: &mut Parser, sh: &Shell) -> Result<(), BoxedError> {

cmd!(
sh,
"go run github.com/vkcom/statshouse/cmd/statshouse-client-test@master"
"go run github.com/VKCOM/statshouse/cmd/statshouse-client-test@master"
)
.run()?;
cmd!(sh, "cargo fmt --check").run()?;
Expand Down