-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(new sink): Adding greptimedb metrics sink #17198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
StephenWakely
merged 37 commits into
vectordotdev:master
from
GreptimeTeam:feature/greptimedb
Jul 11, 2023
Merged
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
e82ed07
feat: add greptimedb sink (wip)
sunng87 5e951fb
feat: configure greptimedb as git dependency
sunng87 4efa4c0
feat: transforming vector metric to greptimedb insert request
sunng87 52094b8
feat: address issues in latest greptimedb client
sunng87 a080f30
feat: add grpc auth support
sunng87 9e8d354
refactor: default value for catalog and schema, rename column fn
sunng87 7c13cea
refactor: small tweaks
sunng87 6f7add6
test: add integration test wip
sunng87 c51c2ef
feat: update greptimedb grpc client, dbname and healthcheck for grpc
sunng87 e766b62
feat: change default timestmap column name to ts
sunng87 2c5cafc
test: add integration tests for greptimedb
sunng87 64704f7
test: correct column count in test cases
sunng87 945cf90
test: resolve lint and test errors
sunng87 9c37da8
chore: switch to compact greptimedb rust client
sunng87 a888bf9
docs: add website docs
sunng87 2bfbce3
chore: update 3rd-party license file
sunng87 b4774ff
fix: add greptimedb-integration-tests feature
sunng87 31107a4
chore: remove network section from integration tests
sunng87 2dc19f5
fix: resolve new lint warnings
sunng87 352bd13
test: fix compose file by adding command
sunng87 b320d61
feat: use latest client protocol
sunng87 26a7a61
refactor: use stream sink apis
sunng87 828bebc
fix: integration tests
sunng87 8fb9943
feat: add retry logic back
sunng87 542a820
fix: change default column name to val instead of value
sunng87 2d39446
refactor: minor tunes
sunng87 156a35e
docs: update cue files
sunng87 3cdeb51
feat: add some tlsconfig support for custom ca and client cert
sunng87 930f97d
docs: add greptime.md for website
sunng87 1e6b6df
Merge remote-tracking branch 'upstream/master' into feature/greptimedb
sunng87 d590c7b
refactor: adopt latest master changes
sunng87 7cde107
fix: avoid panic for tlsconfig error
sunng87 74ba665
Merge branch 'master' into feature/greptimedb
sunng87 c16cc6d
Merge branch 'master' into feature/greptimedb
sunng87 2968854
Apply suggestions from code review
sunng87 289f4a8
Update src/sinks/greptimedb/service.rs
sunng87 e247b68
refactor: address review issues
sunng87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -295,6 +295,9 @@ gpg | |
| gql | ||
| grafana | ||
| graphiql | ||
| greptime | ||
| greptimecloud | ||
| greptimedb | ||
| gvisor | ||
| gws | ||
| hadoop | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| version: '3' | ||
|
|
||
| services: | ||
| greptimedb: | ||
| image: docker.io/greptime/greptimedb:${CONFIG_VERSION} | ||
| command: "standalone start --http-addr=0.0.0.0:4000 --rpc-addr=0.0.0.0:4001" | ||
| healthcheck: | ||
| test: "curl -f localhost:4000/health || exit 1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| features: | ||
| - greptimedb-integration-tests | ||
|
|
||
| test_filter: '::greptimedb::' | ||
|
|
||
| runner: | ||
| env: | ||
| GREPTIMEDB_ENDPOINT: greptimedb:4001 | ||
| GREPTIMEDB_HTTP: http://greptimedb:4000 | ||
|
|
||
| matrix: | ||
| version: ['latest'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| use vector_core::{ | ||
| event::{Metric, MetricValue}, | ||
| stream::batcher::limiter::ItemBatchSize, | ||
| }; | ||
|
|
||
| #[derive(Default)] | ||
| pub(super) struct GreptimeDBBatchSizer; | ||
|
|
||
| impl GreptimeDBBatchSizer { | ||
| pub(super) fn estimated_size_of(&self, item: &Metric) -> usize { | ||
| // Metric name. | ||
| item.series().name().name().len() | ||
| // Metric namespace, with an additional 1 to account for the namespace separator. | ||
| + item.series().name().namespace().map(|s| s.len() + 1).unwrap_or(0) | ||
| // Metric tags, with an additional 1 per tag to account for the tag key/value separator. | ||
| + item.series().tags().map(|t| { | ||
| t.iter_all().map(|(k, v)| { | ||
| k.len() + 1 + v.map(|v| v.len()).unwrap_or(0) | ||
| }) | ||
| .sum() | ||
| }) | ||
| .unwrap_or(0) | ||
| + | ||
| // value size | ||
| match item.value() { | ||
| MetricValue::Counter { .. } | MetricValue::Gauge { .. } | MetricValue::Set { ..} => 8, | ||
| MetricValue::Distribution { .. } => 8 * 10, | ||
| MetricValue::AggregatedHistogram { buckets, .. } => 8 * (buckets.len() + 2), | ||
| MetricValue::AggregatedSummary { quantiles, .. } => 8 * (quantiles.len() + 2), | ||
| MetricValue::Sketch { .. } => 8 * 10, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl ItemBatchSize<Metric> for GreptimeDBBatchSizer { | ||
| fn size(&self, item: &Metric) -> usize { | ||
| self.estimated_size_of(item) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use chrono::{DateTime, Duration, Utc}; | ||
| use futures::stream; | ||
| use vector_core::event::{Event, Metric, MetricKind, MetricValue}; | ||
| use vector_core::metric_tags; | ||
|
|
||
| use crate::sinks::util::test::load_sink; | ||
| use crate::{ | ||
| config::{SinkConfig, SinkContext}, | ||
| test_util::{ | ||
| components::{run_and_assert_sink_compliance, SINK_TAGS}, | ||
| trace_init, | ||
| }, | ||
| }; | ||
|
|
||
| use super::GreptimeDBConfig; | ||
|
|
||
| #[tokio::test] | ||
| async fn test_greptimedb_sink() { | ||
| trace_init(); | ||
| let cfg = format!( | ||
| r#"endpoint= "{}" | ||
| "#, | ||
| std::env::var("GREPTIMEDB_ENDPOINT").unwrap_or_else(|_| "localhost:4001".to_owned()) | ||
| ); | ||
|
|
||
| let (config, _) = load_sink::<GreptimeDBConfig>(&cfg).unwrap(); | ||
| let (sink, _hc) = config.build(SinkContext::default()).await.unwrap(); | ||
|
|
||
| let query_client = query_client(); | ||
|
|
||
| // Drop the table and data inside | ||
| let _ = query_client | ||
| .get(&format!( | ||
| "{}/v1/sql", | ||
| std::env::var("GREPTIMEDB_HTTP").unwrap_or_else(|_| "http://localhost:4000".to_owned()) | ||
| )) | ||
| .query(&[("sql", "DROP TABLE ns_my_counter")]) | ||
| .send() | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| let base_time = Utc::now(); | ||
| let events: Vec<_> = (0..10).map(|idx| create_event(idx, base_time)).collect(); | ||
| run_and_assert_sink_compliance(sink, stream::iter(events), &SINK_TAGS).await; | ||
|
|
||
| let query_response = query_client | ||
| .get(&format!( | ||
| "{}/v1/sql", | ||
| std::env::var("GREPTIMEDB_HTTP").unwrap_or_else(|_| "http://localhost:4000".to_owned()) | ||
| )) | ||
| .query(&[("sql", "SELECT region, val FROM ns_my_counter")]) | ||
| .send() | ||
| .await | ||
| .unwrap() | ||
| .text() | ||
| .await | ||
| .expect("Fetch json from greptimedb failed"); | ||
| let result: serde_json::Value = | ||
| serde_json::from_str(&query_response).expect("Invalid json returned from greptimedb query"); | ||
| assert_eq!( | ||
| result | ||
| .pointer("/output/0/records/rows") | ||
| .and_then(|v| v.as_array()) | ||
| .expect("Error getting greptimedb response array") | ||
| .len(), | ||
| 10 | ||
| ) | ||
| } | ||
|
|
||
| fn query_client() -> reqwest::Client { | ||
| reqwest::Client::builder().build().unwrap() | ||
| } | ||
|
|
||
| fn create_event(i: i32, base_time: DateTime<Utc>) -> Event { | ||
| Event::Metric( | ||
| Metric::new( | ||
| "my_counter".to_owned(), | ||
| MetricKind::Incremental, | ||
| MetricValue::Counter { value: i as f64 }, | ||
| ) | ||
| .with_namespace(Some("ns")) | ||
| .with_tags(Some(metric_tags!( | ||
| "region" => "us-west-1", | ||
| "production" => "true", | ||
| ))) | ||
| .with_timestamp(Some(base_time + Duration::seconds(i as i64))), | ||
| ) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.