Skip to content
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

chore(gcp_stackdriver_logs sink): refactor to new style #18335

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a16de09
First iteration, unit tests pass.
neuronull Aug 9, 2023
969653d
Extract common Service functionality for HTTP based stream sinks.
neuronull Aug 9, 2023
5dc4921
docs touchup
neuronull Aug 9, 2023
10fef82
Touch ups
neuronull Aug 9, 2023
d320b10
spell checker
neuronull Aug 9, 2023
a496821
fix rust doc
neuronull Aug 10, 2023
44c99b3
hopefully fix encoding regression
neuronull Aug 10, 2023
4aa3eca
Try item sized batching
neuronull Aug 14, 2023
68ff83c
Refactor a bit
neuronull Aug 15, 2023
98c3113
cleanup
neuronull Aug 15, 2023
152de8a
cleanup
neuronull Aug 15, 2023
1e696d4
doc clean up
neuronull Aug 16, 2023
06381de
extract common service code for re use in other HTTP sinks
neuronull Aug 16, 2023
24a28f7
Merge branch 'master' into neuronull/sink_newstyle_refactor_http
neuronull Aug 16, 2023
9efe546
feeback sw
neuronull Aug 17, 2023
c22f4d3
Merge branch 'master' into neuronull/sink_newstyle_refactor_http
neuronull Aug 17, 2023
2ea6181
duplicate
neuronull Aug 17, 2023
2bfe0d0
feedback ds
neuronull Aug 18, 2023
b2fac79
feedback ds
neuronull Aug 18, 2023
5316602
clippy
neuronull Aug 18, 2023
38969d2
unit tests pass
neuronull Aug 21, 2023
2fe1f05
First iteration, unit tests pass.
neuronull Aug 9, 2023
fe2e4a4
Extract common Service functionality for HTTP based stream sinks.
neuronull Aug 9, 2023
3fc23a1
docs touchup
neuronull Aug 9, 2023
fcc1851
Touch ups
neuronull Aug 9, 2023
a521b2f
spell checker
neuronull Aug 9, 2023
b99b9a7
fix rust doc
neuronull Aug 10, 2023
d9c6acc
hopefully fix encoding regression
neuronull Aug 10, 2023
ebf8e77
Try item sized batching
neuronull Aug 14, 2023
8f8d2a2
Refactor a bit
neuronull Aug 15, 2023
8f91d17
cleanup
neuronull Aug 15, 2023
527a919
cleanup
neuronull Aug 15, 2023
89d3909
doc clean up
neuronull Aug 16, 2023
dfe2335
extract common service code for re use in other HTTP sinks
neuronull Aug 16, 2023
43ae60f
feeback sw
neuronull Aug 17, 2023
7c3e56d
duplicate
neuronull Aug 17, 2023
d4337f8
feedback ds
neuronull Aug 18, 2023
a66a924
feedback ds
neuronull Aug 18, 2023
bc6ec0d
clippy
neuronull Aug 18, 2023
b58e48f
unit tests pass
neuronull Aug 21, 2023
17aacf4
Merge branch 'neuronull/sink_newstyle_refactor_gcp_stackdriver_logs' …
neuronull Aug 21, 2023
e6ddb44
cleanup
neuronull Aug 21, 2023
517c692
use the common batcher
neuronull Aug 21, 2023
20c9199
Merge branch 'master' into neuronull/sink_newstyle_refactor_gcp_stack…
neuronull Aug 21, 2023
4933945
merge conflicts
neuronull Aug 21, 2023
6571e8d
clippy
neuronull Aug 21, 2023
71c5c03
feedback ds
neuronull Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
neuronull committed Aug 15, 2023
commit 98c3113d84c37284ce6d0d3c7c7a5879f0f10285
3 changes: 3 additions & 0 deletions src/sinks/http/batch.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//! Batch settings for the `http` sink.

use codecs::encoding::Framer;
use vector_core::{
event::Event, stream::batcher::limiter::ItemBatchSize, ByteSizeOf, EstimatedJsonEncodedSizeOf,
};

use crate::codecs::Encoder;

/// Uses the configured encoder to determine batch sizing.
#[derive(Default)]
pub(super) struct HttpBatchSizer {
pub(super) encoder: Encoder<Framer>,
Expand Down
38 changes: 19 additions & 19 deletions src/sinks/http/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@ const CONTENT_TYPE_JSON: &str = "application/json";
#[configurable_component(sink("http", "Deliver observability event data to an HTTP server."))]
#[derive(Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct HttpSinkConfig {
pub(super) struct HttpSinkConfig {
/// The full URI to make HTTP requests to.
///
/// This should include the protocol and host, but can also include the port, path, and any other valid part of a URI.
#[configurable(metadata(docs::examples = "https://10.22.212.22:9000/endpoint"))]
pub uri: UriSerde,
pub(super) uri: UriSerde,

/// The HTTP method to use when making the request.
#[serde(default)]
pub method: HttpMethod,
pub(super) method: HttpMethod,

#[configurable(derived)]
pub auth: Option<Auth>,
pub(super) auth: Option<Auth>,

/// A list of custom headers to add to each request.
#[configurable(deprecated)]
#[configurable(metadata(
docs::additional_props_description = "An HTTP request header and it's value."
))]
pub headers: Option<IndexMap<String, String>>,
pub(super) headers: Option<IndexMap<String, String>>,

#[configurable(derived)]
#[serde(default)]
pub compression: Compression,
pub(super) compression: Compression,

#[serde(flatten)]
pub encoding: EncodingConfigWithFraming,
pub(super) encoding: EncodingConfigWithFraming,

/// A string to prefix the payload with.
///
Expand All @@ -70,7 +70,7 @@ pub struct HttpSinkConfig {
/// If specified, the `payload_suffix` must also be specified and together they must produce a valid JSON object.
#[configurable(metadata(docs::examples = "{\"data\":"))]
#[serde(default)]
pub payload_prefix: String,
pub(super) payload_prefix: String,

/// A string to suffix the payload with.
///
Expand All @@ -79,26 +79,26 @@ pub struct HttpSinkConfig {
/// If specified, the `payload_prefix` must also be specified and together they must produce a valid JSON object.
#[configurable(metadata(docs::examples = "}"))]
#[serde(default)]
pub payload_suffix: String,
pub(super) payload_suffix: String,

#[configurable(derived)]
#[serde(default)]
pub batch: BatchConfig<RealtimeSizeBasedDefaultBatchSettings>,
pub(super) batch: BatchConfig<RealtimeSizeBasedDefaultBatchSettings>,

#[configurable(derived)]
#[serde(default)]
pub request: RequestConfig,
pub(super) request: RequestConfig,

#[configurable(derived)]
pub tls: Option<TlsConfig>,
pub(super) tls: Option<TlsConfig>,

#[configurable(derived)]
#[serde(
default,
deserialize_with = "crate::serde::bool_or_struct",
skip_serializing_if = "crate::serde::skip_serializing_if_default"
)]
pub acknowledgements: AcknowledgementsConfig,
pub(super) acknowledgements: AcknowledgementsConfig,
}

/// HTTP method.
Expand All @@ -110,7 +110,7 @@ pub struct HttpSinkConfig {
#[derive(Clone, Copy, Debug, Derivative, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
#[derivative(Default)]
pub enum HttpMethod {
pub(super) enum HttpMethod {
/// GET.
Get,

Expand Down Expand Up @@ -277,14 +277,14 @@ impl SinkConfig for HttpSinkConfig {
.to_string()
});

let http_service_request_builder = HttpSinkRequestBuilder {
uri: self.uri.with_default_parts(),
method: self.method,
auth: self.auth.choose_one(&self.uri.auth)?,
let http_service_request_builder = HttpSinkRequestBuilder::new(
self.uri.with_default_parts(),
self.method,
self.auth.choose_one(&self.uri.auth)?,
headers,
content_type,
content_encoding,
};
);

let service = HttpService::new(client, http_service_request_builder);

Expand Down
2 changes: 0 additions & 2 deletions src/sinks/http/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ impl RequestBuilder<Vec<Event>> for HttpRequestBuilder {

fn compression(&self) -> Compression {
self.compression
// Compression is handled in the Service
//Compression::None
}

fn encoder(&self) -> &Self::Encoder {
Expand Down
53 changes: 34 additions & 19 deletions src/sinks/http/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ use crate::{

use super::config::HttpMethod;

/// Request type for use in `RequestBuilder` implementations of HTTP stream sinks.
#[derive(Clone)]
pub struct HttpRequest {
pub payload: Bytes,
pub finalizers: EventFinalizers,
pub request_metadata: RequestMetadata,
pub(super) struct HttpRequest {
payload: Bytes,
finalizers: EventFinalizers,
request_metadata: RequestMetadata,
}

impl HttpRequest {
/// Creates a new `HttpRequest`.
pub fn new(
pub(super) fn new(
payload: Bytes,
finalizers: EventFinalizers,
request_metadata: RequestMetadata,
Expand Down Expand Up @@ -69,10 +68,10 @@ impl ByteSizeOf for HttpRequest {
}

/// Response type for use in the `Service` implementation of HTTP stream sinks.
pub struct HttpResponse {
pub(super) struct HttpResponse {
pub(super) http_response: Response<Bytes>,
pub(super) events_byte_size: GroupedCountByteSize,
pub(super) raw_byte_size: usize,
events_byte_size: GroupedCountByteSize,
raw_byte_size: usize,
}

impl DriverResponse for HttpResponse {
Expand All @@ -95,19 +94,37 @@ impl DriverResponse for HttpResponse {

#[derive(Debug, Clone)]
pub(super) struct HttpSinkRequestBuilder {
pub(super) uri: UriSerde,
pub(super) method: HttpMethod,
pub(super) auth: Option<Auth>,
pub(super) headers: IndexMap<HeaderName, HeaderValue>,
pub(super) content_type: Option<String>,
pub(super) content_encoding: Option<String>,
uri: UriSerde,
method: HttpMethod,
auth: Option<Auth>,
headers: IndexMap<HeaderName, HeaderValue>,
content_type: Option<String>,
content_encoding: Option<String>,
}

impl HttpSinkRequestBuilder {
/// Creates a new `HttpSinkRequestBuilder`
pub(super) const fn new(
uri: UriSerde,
method: HttpMethod,
auth: Option<Auth>,
headers: IndexMap<HeaderName, HeaderValue>,
content_type: Option<String>,
content_encoding: Option<String>,
) -> Self {
Self {
uri,
method,
auth,
headers,
content_type,
content_encoding,
}
}

fn build(&self, body: Bytes) -> Request<Bytes> {
let method: Method = self.method.into();
let uri: Uri = self.uri.uri.clone();

let mut builder = Request::builder().method(method).uri(uri);

if let Some(content_type) = &self.content_type {
Expand Down Expand Up @@ -142,14 +159,12 @@ impl HttpSinkRequestBuilder {

#[derive(Clone)]
pub(super) struct HttpService {
// pub(crate) batch_service:
// HttpBatchService<Ready<Result<http::Request<Bytes>, crate::Error>>, HttpRequest>,
batch_service:
HttpBatchService<BoxFuture<'static, Result<Request<Bytes>, crate::Error>>, HttpRequest>,
}

impl HttpService {
pub fn new(
pub(super) fn new(
http_client: HttpClient<Body>,
http_request_builder: HttpSinkRequestBuilder,
) -> Self {
Expand Down
3 changes: 1 addition & 2 deletions src/sinks/http/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ where
async fn run_inner(self: Box<Self>, input: BoxStream<'_, Event>) -> Result<(), ()> {
let service = ServiceBuilder::new().service(self.service);
input
// .batched(self.batch_settings.into_byte_size_config())
// Batch the input stream with size calculation dependent on the configured codec
// Batch the input stream with size calculation based on the configured codec
.batched(self.batch_settings.into_item_size_config(HttpBatchSizer {
encoder: self.request_builder.encoder.encoder.clone(),
}))
Expand Down