Skip to content

Commit

Permalink
fix(prometheus_remote_write source, prometheus_scrape source): Fix fe…
Browse files Browse the repository at this point in the history
…ature check (#18440)

* Correct feature flag for http_client module

* Fix compilation for prometheus-scrape

* Replace sources-prometheus

* Fix compilation sources-prometheus-remote-write

* Replace sources-prometheus

* Fix test compilation
  • Loading branch information
wbew authored Aug 31, 2023
1 parent a112704 commit 9c1abd6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ sources-opentelemetry = ["dep:hex", "dep:opentelemetry-proto", "dep:prost-types"
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-client"]
sources-prometheus-remote-write = ["dep:prometheus-parser", "sinks-prometheus", "sources-utils-http"]
sources-redis= ["dep:redis"]
sources-socket = ["sources-utils-net", "tokio-util/net"]
sources-splunk_hec = ["dep:roaring"]
Expand Down
12 changes: 10 additions & 2 deletions src/internal_events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ mod parser;
#[cfg(feature = "sources-postgresql_metrics")]
mod postgresql_metrics;
mod process;
#[cfg(any(feature = "sources-prometheus", feature = "sinks-prometheus"))]
#[cfg(any(
feature = "sources-prometheus-scrape",
feature = "sources-prometheus-remote-write",
feature = "sinks-prometheus"
))]
mod prometheus;
#[cfg(feature = "sinks-pulsar")]
mod pulsar;
Expand Down Expand Up @@ -230,7 +234,11 @@ pub(crate) use self::nginx_metrics::*;
pub(crate) use self::parser::*;
#[cfg(feature = "sources-postgresql_metrics")]
pub(crate) use self::postgresql_metrics::*;
#[cfg(any(feature = "sources-prometheus", feature = "sinks-prometheus"))]
#[cfg(any(
feature = "sources-prometheus-scrape",
feature = "sources-prometheus-remote-write",
feature = "sinks-prometheus"
))]
pub(crate) use self::prometheus::*;
#[cfg(feature = "sinks-pulsar")]
pub(crate) use self::pulsar::*;
Expand Down
8 changes: 4 additions & 4 deletions src/internal_events/prometheus.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(feature = "sources-prometheus")]
#[cfg(feature = "sources-prometheus-scrape")]
use std::borrow::Cow;

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

Expand All @@ -12,15 +12,15 @@ use vector_common::internal_event::{
error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL,
};

#[cfg(feature = "sources-prometheus")]
#[cfg(feature = "sources-prometheus-scrape")]
#[derive(Debug)]
pub struct PrometheusParseError<'a> {
pub error: ParserError,
pub url: http::Uri,
pub body: Cow<'a, str>,
}

#[cfg(feature = "sources-prometheus")]
#[cfg(feature = "sources-prometheus-scrape")]
impl<'a> InternalEvent for PrometheusParseError<'a> {
fn emit(self) {
error!(
Expand Down
1 change: 0 additions & 1 deletion src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ pub mod opentelemetry;
#[cfg(feature = "sources-postgresql_metrics")]
pub mod postgresql_metrics;
#[cfg(any(
feature = "sources-prometheus",
feature = "sources-prometheus-scrape",
feature = "sources-prometheus-remote-write"
))]
Expand Down
6 changes: 5 additions & 1 deletion src/sources/prometheus/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::cmp::Ordering;

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

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

#[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)
}

#[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)
}
Expand Down
5 changes: 3 additions & 2 deletions src/sources/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod grpc;
feature = "sources-utils-http-query"
))]
pub mod http;
#[cfg(any(feature = "sources-http_client", feature = "sources-prometheus"))]
#[cfg(any(feature = "sources-http_client", feature = "sources-prometheus-scrape",))]
pub mod http_client;
#[cfg(any(feature = "sources-aws_sqs", feature = "sources-gcp_pubsub"))]
mod message_decoding;
Expand Down Expand Up @@ -51,7 +51,8 @@ pub use self::body_decoding::Encoding;
#[cfg(feature = "sources-utils-http-query")]
pub use self::http::add_query_parameters;
#[cfg(any(
feature = "sources-prometheus",
feature = "sources-prometheus-scrape",
feature = "sources-prometheus-remote-write",
feature = "sources-utils-http-encoding"
))]
pub use self::http::decode;
Expand Down

0 comments on commit 9c1abd6

Please sign in to comment.