Skip to content

Commit

Permalink
chore: switch to compact greptimedb rust client
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed May 9, 2023
1 parent 3c2cd6f commit 73f6b7d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .github/actions/spelling/allow.txt
Expand Up @@ -294,6 +294,8 @@ gpg
gql
grafana
graphiql
greptime
greptimedb
gvisor
gws
hadoop
Expand Down
31 changes: 31 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -229,7 +229,7 @@ hex = { version = "0.4.3", default-features = false, optional = true }
sha2 = { version = "0.10.6", default-features = false, optional = true }

# Greptime
greptimedb-client = { git = "https://github.com/GreptimeTeam/greptimedb.git", rev = "b5e5f8e555065da0ba1d3f13b6b76fad59cb4017", package = "client", optional = true }
greptimedb-client = { git = "https://github.com/GreptimeTeam/greptimedb-client-rust.git", rev = "2b5d575fd4aaff2955b20e59e752e1eba71c4b75", package = "greptimedb-client-rust", optional = true }

# VRL Lang
vrl = { package = "vrl", git = "https://github.com/vectordotdev/vrl", rev = "v0.2.0" }
Expand Down
19 changes: 0 additions & 19 deletions sample.toml

This file was deleted.

17 changes: 7 additions & 10 deletions src/sinks/greptimedb/client.rs
Expand Up @@ -122,8 +122,6 @@ impl Service<Vec<Metric>> for GreptimeDBService {

// Convert vector metrics into GreptimeDB format and send them in batch
fn call(&mut self, items: Vec<Metric>) -> Self::Future {
// TODO(sunng87): group metrics by name and send metrics with same name
// in batch
let requests = items.into_iter().map(metric_to_insert_request);
let client = Arc::clone(&self.client);

Expand Down Expand Up @@ -187,7 +185,7 @@ fn metric_to_insert_request(metric: Metric) -> InsertRequest {
};

let mut columns = Vec::new();
// timetamp
// timestamp
let timestamp = metric
.timestamp()
.map(|t| t.timestamp_millis())
Expand Down Expand Up @@ -267,7 +265,6 @@ fn encode_histogram(buckets: &[Bucket], columns: &mut Vec<Column>) {
fn encode_quantiles(quantiles: &[Quantile], columns: &mut Vec<Column>) {
for quantile in quantiles {
let column_name = format!("p{:02}", quantile.quantile * 100f64);
dbg!(&column_name);
columns.push(f64_field(&column_name, quantile.value));
}
}
Expand Down Expand Up @@ -328,7 +325,7 @@ mod tests {
MetricValue::Gauge { value: 1.1 },
)
.with_namespace(Some("ns"))
.with_tags(Some([("host".to_owned(), "thinkneo".to_owned())].into()))
.with_tags(Some([("host".to_owned(), "thinkpad".to_owned())].into()))

Check failure on line 328 in src/sinks/greptimedb/client.rs

View workflow job for this annotation

GitHub Actions / Check Spelling

`thinkpad` is not a recognized word. (unrecognized-spelling)
.with_timestamp(Some(Utc::now()));

let insert = metric_to_insert_request(metric);
Expand Down Expand Up @@ -413,7 +410,7 @@ mod tests {
#[test]
fn test_histogram() {
let metric = Metric::new(
"cpu_seconds_totoal",
"cpu_seconds_total",
MetricKind::Incremental,
MetricValue::AggregatedHistogram {
buckets: vector_core::buckets![1.0 => 1, 2.0 => 2, 3.0 => 1],
Expand All @@ -434,7 +431,7 @@ mod tests {
#[test]
fn test_summary() {
let metric = Metric::new(
"cpu_seconds_totoal",
"cpu_seconds_total",
MetricKind::Incremental,
MetricValue::AggregatedSummary {
quantiles: vector_core::quantiles![0.01 => 1.5, 0.5 => 2.0, 0.99 => 3.0],
Expand Down Expand Up @@ -493,7 +490,7 @@ mod integration_tests {
std::env::var("GREPTIMEDB_HTTP")
.unwrap_or_else(|_| "http://localhost:4000".to_owned())
))
.query(&[("sql", "SELECT region, value FROM ms_mycounter")])
.query(&[("sql", "SELECT region, value FROM ns_my_counter")])
.send()
.await
.unwrap()
Expand All @@ -506,7 +503,7 @@ mod integration_tests {
result
.pointer("/output/0/records/rows")
.and_then(|v| v.as_array())
.expect("Error getting greptimedb resposne array")
.expect("Error getting greptimedb response array")
.len(),
10
)
Expand All @@ -519,7 +516,7 @@ mod integration_tests {
fn create_event(i: i32) -> Event {
Event::Metric(
Metric::new(
format!("mycounter"),
format!("my_counter"),
MetricKind::Incremental,
MetricValue::Counter { value: i as f64 },
)
Expand Down

0 comments on commit 73f6b7d

Please sign in to comment.