Skip to content

Commit

Permalink
chore(dev): Add vector-lib wrapper for three more libs (#18992)
Browse files Browse the repository at this point in the history
* chore(dev): Add wrapper for `opentelemetry_proto` in `vector-lib`

* chore(dev): Add wrapper for `prometheus-parser` in `vector-lib`

* chore(dev): Add wrapper for `vector-api-client` in `vector-lib`

* Reformat
  • Loading branch information
bruceg authored Oct 31, 2023
1 parent 4a4eb61 commit 1eb418b
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ dnsmsg-parser = { path = "lib/dnsmsg-parser", optional = true }
fakedata = { path = "lib/fakedata", optional = true }
lookup = { package = "vector-lookup", path = "lib/vector-lookup" }
portpicker = { path = "lib/portpicker" }
prometheus-parser = { path = "lib/prometheus-parser", optional = true }
opentelemetry-proto = { path = "lib/opentelemetry-proto", optional = true }
tracing-limit = { path = "lib/tracing-limit" }
vector-api-client = { path = "lib/vector-api-client", optional = true }
vector-lib = { path = "lib/vector-lib", default-features = false, features = ["vrl"] }
vector-vrl-functions = { path = "lib/vector-vrl/functions" }
loki-logproto = { path = "lib/loki-logproto", optional = true }
Expand Down Expand Up @@ -439,7 +436,7 @@ api-client = [
"dep:number_prefix",
"dep:ratatui",
"vector-lib/api",
"dep:vector-api-client",
"vector-lib/api-client",
]

aws-core = [
Expand Down Expand Up @@ -541,11 +538,11 @@ sources-logstash = ["sources-utils-net-tcp", "tokio-util/net"]
sources-mongodb_metrics = ["dep:mongodb"]
sources-nats = ["dep:async-nats", "dep:nkeys"]
sources-nginx_metrics = ["dep:nom"]
sources-opentelemetry = ["dep:hex", "dep:opentelemetry-proto", "dep:prost-types", "sources-http_server", "sources-utils-http", "sources-vector"]
sources-opentelemetry = ["dep:hex", "vector-lib/opentelemetry", "dep:prost-types", "sources-http_server", "sources-utils-http", "sources-vector"]
sources-postgresql_metrics = ["dep:postgres-openssl", "dep:tokio-postgres"]
sources-prometheus = ["sources-prometheus-scrape", "sources-prometheus-remote-write"]
sources-prometheus-scrape = ["dep:prometheus-parser", "sinks-prometheus", "sources-utils-http-client"]
sources-prometheus-remote-write = ["dep:prometheus-parser", "sinks-prometheus", "sources-utils-http"]
sources-prometheus-scrape = ["sinks-prometheus", "sources-utils-http-client", "vector-lib/prometheus"]
sources-prometheus-remote-write = ["sinks-prometheus", "sources-utils-http", "vector-lib/prometheus"]
sources-redis= ["dep:redis"]
sources-socket = ["sources-utils-net", "tokio-util/net"]
sources-splunk_hec = ["dep:roaring"]
Expand Down Expand Up @@ -707,7 +704,7 @@ sinks-nats = ["dep:async-nats", "dep:nkeys"]
sinks-new_relic_logs = ["sinks-http"]
sinks-new_relic = []
sinks-papertrail = ["dep:syslog"]
sinks-prometheus = ["dep:base64", "dep:prometheus-parser"]
sinks-prometheus = ["dep:base64", "vector-lib/prometheus"]
sinks-pulsar = ["dep:apache-avro", "dep:pulsar", "dep:lru"]
sinks-redis = ["dep:redis"]
sinks-sematext = ["sinks-elasticsearch", "sinks-influxdb"]
Expand Down
6 changes: 6 additions & 0 deletions lib/vector-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ publish = false
codecs = { path = "../codecs", default-features = false }
enrichment = { path = "../enrichment" }
file-source = { path = "../file-source", optional = true }
opentelemetry-proto = { path = "../opentelemetry-proto", optional = true }
prometheus-parser = { path = "../prometheus-parser", optional = true }
vector-api-client = { path = "../vector-api-client", optional = true }
vector-buffers = { path = "../vector-buffers", default-features = false }
vector-common = { path = "../vector-common" }
vector-config = { path = "../vector-config" }
Expand All @@ -17,8 +20,11 @@ vector-stream = { path = "../vector-stream" }

[features]
api = ["vector-core/api"]
api-client = ["dep:vector-api-client"]
lua = ["vector-core/lua"]
file-source = ["dep:file-source"]
opentelemetry = ["dep:opentelemetry-proto"]
prometheus = ["dep:prometheus-parser"]
syslog = ["codecs/syslog"]
test = ["vector-core/test"]
vrl = ["vector-core/vrl"]
12 changes: 12 additions & 0 deletions lib/vector-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub use codecs;
pub use enrichment;
#[cfg(feature = "file-source")]
pub use file_source;
#[cfg(feature = "api-client")]
pub use vector_api_client as api_client;
pub use vector_buffers as buffers;
pub use vector_common::{
assert_event_data_eq, btreemap, byte_size_of, byte_size_of::ByteSizeOf, conversion,
Expand Down Expand Up @@ -29,3 +31,13 @@ pub mod config {
MEMORY_BUFFER_DEFAULT_MAX_EVENTS,
};
}

#[cfg(feature = "opentelemetry")]
pub mod opentelemetry {
pub use opentelemetry_proto::{convert, proto};
}

#[cfg(feature = "prometheus")]
pub mod prometheus {
pub use prometheus_parser as parser;
}
4 changes: 2 additions & 2 deletions src/internal_events/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::borrow::Cow;

use hyper::StatusCode;
use metrics::counter;
#[cfg(feature = "sources-prometheus-scrape")]
use prometheus_parser::ParserError;
use vector_lib::internal_event::InternalEvent;
#[cfg(feature = "sources-prometheus-scrape")]
use vector_lib::prometheus::parser::ParserError;

use crate::emit;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/prometheus/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{collections::BTreeMap, fmt::Write as _};

use chrono::Utc;
use indexmap::map::IndexMap;
use prometheus_parser::{proto, METRIC_NAME_LABEL};
use vector_lib::event::metric::{samples_to_buckets, MetricSketch, MetricTags, Quantile};
use vector_lib::prometheus::parser::{proto, METRIC_NAME_LABEL};

use crate::{
event::metric::{Metric, MetricKind, MetricValue, StatisticKind},
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/prometheus/remote_write/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use bytes::Bytes;
use futures::StreamExt;
use http::HeaderMap;
use indoc::indoc;
use prometheus_parser::proto;
use prost::Message;
use vector_lib::metric_tags;
use vector_lib::prometheus::parser::proto;

use super::*;
use crate::{
Expand Down
6 changes: 3 additions & 3 deletions src/sources/opentelemetry/grpc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use futures::TryFutureExt;
use opentelemetry_proto::proto::collector::logs::v1::{
logs_service_server::LogsService, ExportLogsServiceRequest, ExportLogsServiceResponse,
};
use tonic::{Request, Response, Status};
use vector_lib::internal_event::{CountByteSize, InternalEventHandle as _, Registered};
use vector_lib::opentelemetry::proto::collector::logs::v1::{
logs_service_server::LogsService, ExportLogsServiceRequest, ExportLogsServiceResponse,
};
use vector_lib::{
config::LogNamespace,
event::{BatchNotifier, BatchStatus, BatchStatusReceiver, Event},
Expand Down
6 changes: 3 additions & 3 deletions src/sources/opentelemetry/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ use bytes::Bytes;
use futures_util::FutureExt;
use http::StatusCode;
use hyper::{service::make_service_fn, Server};
use opentelemetry_proto::proto::collector::logs::v1::{
ExportLogsServiceRequest, ExportLogsServiceResponse,
};
use prost::Message;
use snafu::Snafu;
use tower::ServiceBuilder;
use tracing::Span;
use vector_lib::internal_event::{
ByteSize, BytesReceived, CountByteSize, InternalEventHandle as _, Registered,
};
use vector_lib::opentelemetry::proto::collector::logs::v1::{
ExportLogsServiceRequest, ExportLogsServiceResponse,
};
use vector_lib::{
config::LogNamespace,
event::{BatchNotifier, BatchStatus},
Expand Down
4 changes: 2 additions & 2 deletions src/sources/opentelemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use std::net::SocketAddr;

use futures::{future::join, FutureExt, TryFutureExt};
use lookup::{owned_value_path, OwnedTargetPath};
use opentelemetry_proto::convert::{
use vector_lib::opentelemetry::convert::{
ATTRIBUTES_KEY, DROPPED_ATTRIBUTES_COUNT_KEY, FLAGS_KEY, OBSERVED_TIMESTAMP_KEY, RESOURCE_KEY,
SEVERITY_NUMBER_KEY, SEVERITY_TEXT_KEY, SPAN_ID_KEY, TRACE_ID_KEY,
};

use opentelemetry_proto::proto::collector::logs::v1::logs_service_server::LogsServiceServer;
use vector_lib::configurable::configurable_component;
use vector_lib::internal_event::{BytesReceived, EventsReceived, Protocol};
use vector_lib::opentelemetry::proto::collector::logs::v1::logs_service_server::LogsServiceServer;
use vector_lib::{
config::{log_schema, LegacyKey, LogNamespace},
schema::Definition,
Expand Down
12 changes: 6 additions & 6 deletions src/sources/opentelemetry/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use chrono::{TimeZone, Utc};
use futures::Stream;
use futures_util::StreamExt;
use lookup::path;
use opentelemetry_proto::proto::{
collector::logs::v1::{logs_service_client::LogsServiceClient, ExportLogsServiceRequest},
common::v1::{any_value, AnyValue, KeyValue},
logs::v1::{LogRecord, ResourceLogs, ScopeLogs},
resource::v1::Resource as OtelResource,
};
use similar_asserts::assert_eq;
use std::collections::BTreeMap;
use std::sync::Arc;
use tonic::Request;
use vector_lib::config::LogNamespace;
use vector_lib::opentelemetry::proto::{
collector::logs::v1::{logs_service_client::LogsServiceClient, ExportLogsServiceRequest},
common::v1::{any_value, AnyValue, KeyValue},
logs::v1::{LogRecord, ResourceLogs, ScopeLogs},
resource::v1::Resource as OtelResource,
};
use vrl::value;

use crate::config::OutputId;
Expand Down
8 changes: 4 additions & 4 deletions src/sources/prometheus/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::cmp::Ordering;

use chrono::{DateTime, TimeZone, Utc};
#[cfg(feature = "sources-prometheus-remote-write")]
use prometheus_parser::proto;
use prometheus_parser::{GroupKind, MetricGroup, ParserError};
use vector_lib::prometheus::parser::proto;
use vector_lib::prometheus::parser::{GroupKind, MetricGroup, ParserError};

use crate::event::{
metric::{Bucket, Metric, MetricKind, MetricTags, MetricValue, Quantile},
Expand All @@ -21,12 +21,12 @@ fn utc_timestamp(timestamp: Option<i64>, default: DateTime<Utc>) -> DateTime<Utc

#[cfg(any(test, feature = "sources-prometheus-scrape"))]
pub(super) fn parse_text(packet: &str) -> Result<Vec<Event>, ParserError> {
prometheus_parser::parse_text(packet).map(reparse_groups)
vector_lib::prometheus::parser::parse_text(packet).map(reparse_groups)
}

#[cfg(feature = "sources-prometheus-remote-write")]
pub(super) fn parse_request(request: proto::WriteRequest) -> Result<Vec<Event>, ParserError> {
prometheus_parser::parse_request(request).map(reparse_groups)
vector_lib::prometheus::parser::parse_request(request).map(reparse_groups)
}

fn reparse_groups(groups: Vec<MetricGroup>) -> Vec<Event> {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/prometheus/remote_write.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{collections::HashMap, net::SocketAddr};

use bytes::Bytes;
use prometheus_parser::proto;
use prost::Message;
use vector_lib::config::LogNamespace;
use vector_lib::configurable::configurable_component;
use vector_lib::prometheus::parser::proto;
use warp::http::{HeaderMap, StatusCode};

use super::parser;
Expand Down
2 changes: 1 addition & 1 deletion src/tap/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{borrow::Cow, collections::BTreeMap, time::Duration};
use colored::{ColoredString, Colorize};
use tokio_stream::StreamExt;
use url::Url;
use vector_api_client::{
use vector_lib::api_client::{
connect_subscription_client,
gql::{
output_events_by_component_id_patterns_subscription::OutputEventsByComponentIdPatternsSubscriptionOutputEventsByComponentIdPatterns,
Expand Down
2 changes: 1 addition & 1 deletion src/tap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::Parser;
pub(crate) use cmd::cmd;
pub use cmd::tap;
use url::Url;
use vector_api_client::gql::TapEncodingFormat;
use vector_lib::api_client::gql::TapEncodingFormat;

use crate::config::api::default_graphql_url;

Expand Down
2 changes: 1 addition & 1 deletion src/top/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use chrono::Local;
use futures_util::future::join_all;
use tokio::sync::{mpsc, oneshot};
use vector_api_client::{connect_subscription_client, Client};
use vector_lib::api_client::{connect_subscription_client, Client};

use super::{
dashboard::{init_dashboard, is_tty},
Expand Down
2 changes: 1 addition & 1 deletion src/top/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use tokio::task::JoinHandle;
use tokio_stream::StreamExt;
use vector_api_client::{
use vector_lib::api_client::{
gql::{ComponentsQueryExt, ComponentsSubscriptionExt, MetricsSubscriptionExt},
Client, SubscriptionClient,
};
Expand Down

0 comments on commit 1eb418b

Please sign in to comment.