Skip to content

Commit

Permalink
feat: downgrade jeager and add client test
Browse files Browse the repository at this point in the history
  • Loading branch information
smorihira committed Sep 12, 2024
1 parent e0cd1b0 commit 83f9921
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 3 deletions.
2 changes: 1 addition & 1 deletion k8s/metrics/jaeger/jaeger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ metadata:
spec:
strategy: allInOne
allInOne:
image: jaegertracing/all-in-one:latest
image: jaegertracing/all-in-one:1.31
options:
log-level: debug
# spec for jaeger-collector components.
Expand Down
1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"libs/observability",
"libs/proto",
"bin/meta",
"bin/test",
# "bin/agent",
# "libs/algorithm",
# "libs/algorithms/ngt",
Expand Down
2 changes: 1 addition & 1 deletion rust/bin/meta/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.attribute("target_node", "target_node")
.attribute("exported_kubernetes_namaspace", "default")
.attribute("kubernetes_name", "vald-lb-gateway")
.endpoint("127.0.0.1:4318")
.endpoint("http://127.0.0.1:4318")
.tracer(Tracer::new().enabled(true));
let mut observability = ObservabilityImpl::new(observability_cfg)?;

Expand Down
15 changes: 15 additions & 0 deletions rust/bin/test_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "test"
version = "0.1.0"
edition = "2021"

[dependencies]
kv = "0.24.0"
opentelemetry = "0.25.0"
prost-types = "0.13.2"
proto = { version = "0.1.0", path = "../../libs/proto" }
sled = "0.34.7"
tokio = { version = "1.40.0", features = ["full"] }
tonic = "0.12.2"
observability = { path = "../../libs/observability" }
defer = "0.2.1"
191 changes: 191 additions & 0 deletions rust/bin/test_client/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
use proto::meta::v1::meta_client::MetaClient;
use proto::payload::v1::meta;
use prost_types::Any;
use opentelemetry::global;
use opentelemetry::propagation::Injector;
use tonic::metadata::MetadataMap;
use tonic::Request;

// MetadataInjector構造体を定義して、Injectorトレイトを実装する
struct MetadataInjector<'a>(&'a mut MetadataMap);

impl<'a> Injector for MetadataInjector<'a> {
fn set(&mut self, key: &str, value: String) {
// keyを所有権を持つ文字列に変換してから、挿入する
let key_owned = key.to_owned(); // Stringに変換
let parsed_key = key_owned.parse::<tonic::metadata::MetadataKey<_>>().unwrap();
self.0.insert(parsed_key, value.parse().unwrap());
}
}

// ジェネリック型を用いたトレースコンテキストの挿入関数
fn inject_trace_context<T>(request: &mut Request<T>) {
let metadata = request.metadata_mut(); // mutは不要
let mut injector = MetadataInjector(metadata); // injectorをミュータブルに

// Contextの取得
let current_context = opentelemetry::Context::current();

// グローバルプロパゲータを使ってトレースコンテキストを挿入
global::get_text_map_propagator(|propagator| {
propagator.inject_context(&current_context, &mut injector); // injectorをミュータブルで渡す
});
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// gRPC サーバーに接続するクライアントを作成
let mut client = MetaClient::connect("http://[::1]:8081").await?;

// 1. set key: aaa, value: 1
let any_value = Any {
type_url: "".to_string(), // 型URLを設定(必要なら適切なURLに)
value: b"1".to_vec(), // Vec<u8> を prost_types::Any に変換
};
let mut request = tonic::Request::new(meta::KeyValue {
key: Some(meta::Key{key: "aaa".to_string()}),
value: Some(meta::Value { value: Some(any_value) }),
});
// トレースコンテキストをリクエストに挿入
inject_trace_context(&mut request);
client.set(request).await?;
println!("Set key: aaa, value: 1");

// 2. set key: bbb, value: 2
let any_value = Any {
type_url: "".to_string(), // 型URLを設定
value: b"2".to_vec(),
};
let mut request = tonic::Request::new(meta::KeyValue {
key: Some(meta::Key{key: "bbb".to_string()}),
value: Some(meta::Value { value: Some(any_value) }),
});
inject_trace_context(&mut request); // トレースコンテキストを挿入
client.set(request).await?;
println!("Set key: bbb, value: 2");

// 3. get key: bbb
let mut request = tonic::Request::new(meta::Key {
key: "bbb".to_string(),
});
inject_trace_context(&mut request); // トレースコンテキストを挿入
let response = client.get(request).await?;
println!("Get key: bbb, RESPONSE={:?}", response.into_inner());

// 4. set key: bbb, value: 3
let any_value = Any {
type_url: "".to_string(),
value: b"3".to_vec(),
};
let mut request = tonic::Request::new(meta::KeyValue {
key: Some(meta::Key{key: "bbb".to_string()}),
value: Some(meta::Value { value: Some(any_value) }),
});
inject_trace_context(&mut request); // トレースコンテキストを挿入
client.set(request).await?;
println!("Set key: bbb, value: 3");

// 5. get key: bbb
let mut request = tonic::Request::new(meta::Key {
key: "bbb".to_string(),
});
inject_trace_context(&mut request); // トレースコンテキストを挿入
let response = client.get(request).await?;
println!("Get key: bbb, RESPONSE={:?}", response.into_inner());

// 6. delete key: aaa
let mut request = tonic::Request::new(meta::Key {
key: "aaa".to_string(),
});
inject_trace_context(&mut request); // トレースコンテキストを挿入
client.delete(request).await?;
println!("Deleted key: aaa");

// 7. get key: aaa (after deletion)
let mut request = tonic::Request::new(meta::Key {
key: "aaa".to_string(),
});
inject_trace_context(&mut request); // トレースコンテキストを挿入
let response = client.get(request).await;
match response {
Ok(res) => println!("Get key: aaa, RESPONSE={:?}", res.into_inner()),
Err(e) => println!("Get key: aaa failed with error: {:?}", e),
}

Ok(())
}

// #[tokio::main]
// async fn main() -> Result<(), Box<dyn std::error::Error>> {
// // gRPC サーバーに接続するクライアントを作成
// let mut client = MetaClient::connect("http://[::1]:8081").await?;

// // 1. set key: aaa, value: 1
// let any_value = Any {
// type_url: "".to_string(), // 型URLを設定(必要なら適切なURLに)
// value: b"1".to_vec(), // Vec<u8> を prost_types::Any に変換
// };
// let request = tonic::Request::new(meta::KeyValue {
// key: Some(meta::Key{key: "aaa".to_string()}),
// value: Some(meta::Value { value: Some(any_value) }),
// });
// client.set(request).await?;
// println!("Set key: aaa, value: 1");

// // 2. set key: bbb, value: 2
// let any_value = Any {
// type_url: "".to_string(), // 型URLを設定
// value: b"2".to_vec(),
// };
// let request = tonic::Request::new(meta::KeyValue {
// key: Some(meta::Key{key: "bbb".to_string()}),
// value: Some(meta::Value { value: Some(any_value) }),
// });
// client.set(request).await?;
// println!("Set key: bbb, value: 2");

// // 3. get key: bbb
// let request = tonic::Request::new(meta::Key {
// key: "bbb".to_string(),
// });
// let response = client.get(request).await?;
// println!("Get key: bbb, RESPONSE={:?}", response.into_inner());

// // 4. set key: bbb, value: 3
// let any_value = Any {
// type_url: "".to_string(),
// value: b"3".to_vec(),
// };
// let request = tonic::Request::new(meta::KeyValue {
// key: Some(meta::Key{key: "bbb".to_string()}),
// value: Some(meta::Value { value: Some(any_value) }),
// });
// client.set(request).await?;
// println!("Set key: bbb, value: 3");

// // 5. get key: bbb
// let request = tonic::Request::new(meta::Key {
// key: "bbb".to_string(),
// });
// let response = client.get(request).await?;
// println!("Get key: bbb, RESPONSE={:?}", response.into_inner());

// // 6. delete key: aaa
// let request = tonic::Request::new(meta::Key {
// key: "aaa".to_string(),
// });
// client.delete(request).await?;
// println!("Deleted key: aaa");

// // 7. get key: aaa (after deletion)
// let request = tonic::Request::new(meta::Key {
// key: "aaa".to_string(),
// });
// let response = client.get(request).await;
// match response {
// Ok(res) => println!("Get key: aaa, RESPONSE={:?}", res.into_inner()),
// Err(e) => println!("Get key: aaa failed with error: {:?}", e),
// }

// Ok(())
// }
2 changes: 1 addition & 1 deletion versions/JAEGER_OPERATOR_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.56.0
2.51.0

0 comments on commit 83f9921

Please sign in to comment.