feat(ops/yandex-cloud-rs): generated gRPC clients for Yandex Cloud
This uses tonic to generate the full set of gRPC clients for Yandex Cloud. Includes some utility functions like an authentication interceptor to make these actually work. Since the upstream protos are exported regularly I've decided that the versioning will simply be date-based. The point of this is journaldriver integration, of course, hence also the log-centric example code. Change-Id: I00a615dcba80030e7f9bcfd476b2cfdb298f130d Reviewed-on: https://cl.tvl.fyi/c/depot/+/8525 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
f1ca5a3096
commit
ea1383682d
7 changed files with 1613 additions and 0 deletions
37
ops/yandex-cloud-rs/examples/log-write.rs
Normal file
37
ops/yandex-cloud-rs/examples/log-write.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//! This example uses the Yandex Cloud Logging API to write a log entry.
|
||||
|
||||
use prost_types::Timestamp;
|
||||
use tonic::transport::channel::Endpoint;
|
||||
use yandex_cloud::yandex::cloud::logging::v1::destination::Destination;
|
||||
use yandex_cloud::yandex::cloud::logging::v1::log_ingestion_service_client::LogIngestionServiceClient;
|
||||
use yandex_cloud::yandex::cloud::logging::v1::Destination as OuterDestination;
|
||||
use yandex_cloud::yandex::cloud::logging::v1::IncomingLogEntry;
|
||||
use yandex_cloud::yandex::cloud::logging::v1::WriteRequest;
|
||||
use yandex_cloud::AuthInterceptor;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let channel = Endpoint::from_static("https://ingester.logging.yandexcloud.net")
|
||||
.connect()
|
||||
.await?;
|
||||
|
||||
let mut client = LogIngestionServiceClient::with_interceptor(
|
||||
channel,
|
||||
AuthInterceptor::new("YOUR_TOKEN_HERE"),
|
||||
);
|
||||
|
||||
let request = WriteRequest {
|
||||
destination: Some(OuterDestination {
|
||||
destination: Some(Destination::LogGroupId("YOUR_LOG_GROUP_ID".into())),
|
||||
}),
|
||||
entries: vec![IncomingLogEntry {
|
||||
timestamp: Some(Timestamp::date_time(2023, 04, 24, 23, 44, 30).unwrap()),
|
||||
message: "test log message".into(),
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
client.write(request).await.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue