vector/sinks/gcs_common/
sink.rs1use std::fmt;
2
3use vector_lib::{event::Event, partition::Partitioner};
4
5use crate::sinks::{prelude::*, util::partitioner::KeyPartitioner};
6
7pub struct GcsSink<Svc, RB, P = KeyPartitioner> {
8 service: Svc,
9 request_builder: RB,
10 partitioner: P,
11 batcher_settings: BatcherSettings,
12 protocol: &'static str,
13}
14
15impl<Svc, RB, P> GcsSink<Svc, RB, P> {
16 pub const fn new(
17 service: Svc,
18 request_builder: RB,
19 partitioner: P,
20 batcher_settings: BatcherSettings,
21 protocol: &'static str,
22 ) -> Self {
23 Self {
24 service,
25 request_builder,
26 partitioner,
27 batcher_settings,
28 protocol,
29 }
30 }
31}
32
33impl<Svc, RB, P> GcsSink<Svc, RB, P>
34where
35 Svc: Service<RB::Request> + Send + 'static,
36 Svc::Future: Send + 'static,
37 Svc::Response: DriverResponse + Send + 'static,
38 Svc::Error: fmt::Debug + Into<crate::Error> + Send,
39 RB: RequestBuilder<(String, Vec<Event>)> + Send + Sync + 'static,
40 RB::Error: fmt::Display + Send,
41 RB::Request: Finalizable + MetaDescriptive + Send,
42 P: Partitioner<Item = Event, Key = Option<String>> + Unpin + Send,
43 P::Key: Eq + std::hash::Hash + Clone,
44 P::Item: ByteSizeOf,
45{
46 async fn run_inner(self: Box<Self>, input: BoxStream<'_, Event>) -> Result<(), ()> {
47 let partitioner = self.partitioner;
48 let settings = self.batcher_settings;
49
50 let request_builder = self.request_builder;
51
52 input
53 .batched_partitioned(partitioner, || settings.as_byte_size_config())
54 .filter_map(|(key, batch)| async move {
55 key.map(move |k| (k, batch))
58 })
59 .request_builder(default_request_builder_concurrency_limit(), request_builder)
60 .filter_map(|request| async move {
61 match request {
62 Err(error) => {
63 emit!(SinkRequestBuildError { error });
64 None
65 }
66 Ok(req) => Some(req),
67 }
68 })
69 .into_driver(self.service)
70 .protocol(self.protocol)
71 .run()
72 .await
73 }
74}
75
76#[async_trait]
77impl<Svc, RB, P> StreamSink<Event> for GcsSink<Svc, RB, P>
78where
79 Svc: Service<RB::Request> + Send + 'static,
80 Svc::Future: Send + 'static,
81 Svc::Response: DriverResponse + Send + 'static,
82 Svc::Error: fmt::Debug + Into<crate::Error> + Send,
83 RB: RequestBuilder<(String, Vec<Event>)> + Send + Sync + 'static,
84 RB::Error: fmt::Display + Send,
85 RB::Request: Finalizable + MetaDescriptive + Send,
86 P: Partitioner<Item = Event, Key = Option<String>> + Unpin + Send,
87 P::Key: Eq + std::hash::Hash + Clone,
88 P::Item: ByteSizeOf,
89{
90 async fn run(mut self: Box<Self>, input: BoxStream<'_, Event>) -> Result<(), ()> {
91 self.run_inner(input).await
92 }
93}