Skip to content

Commit f55e0cc

Browse files
author
David Huie
authored
docs(apache_metrics): Use generated docs (#15847)
apache_metrics: switch to auto-generated metrics
1 parent 6559102 commit f55e0cc

File tree

4 files changed

+21
-41
lines changed

4 files changed

+21
-41
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ sources-metrics = [
505505
]
506506

507507
sources-amqp = ["lapin"]
508-
sources-apache_metrics = []
508+
sources-apache_metrics = ["dep:serde_with"]
509509
sources-aws_ecs_metrics = ["dep:serde_with"]
510510
sources-aws_kinesis_firehose = ["dep:base64", "dep:infer"]
511511
sources-aws_s3 = ["aws-core", "dep:aws-sdk-sqs", "dep:aws-sdk-s3", "dep:semver", "dep:async-compression", "sources-aws_sqs", "tokio-util/io"]

src/sources/apache_metrics/mod.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use chrono::Utc;
77
use futures::{stream, FutureExt, StreamExt, TryFutureExt};
88
use http::uri::Scheme;
99
use hyper::{Body, Request};
10+
use serde_with::serde_as;
1011
use snafu::ResultExt;
1112
use tokio_stream::wrappers::IntervalStream;
1213
use vector_config::configurable_component;
@@ -30,15 +31,18 @@ pub use parser::ParseError;
3031
use vector_core::config::LogNamespace;
3132

3233
/// Configuration for the `apache_metrics` source.
34+
#[serde_as]
3335
#[configurable_component(source("apache_metrics"))]
3436
#[derive(Clone, Debug)]
3537
pub struct ApacheMetricsConfig {
3638
/// The list of `mod_status` endpoints to scrape metrics from.
39+
#[configurable(metadata(docs::examples = "http://localhost:8080/server-status/?auto"))]
3740
endpoints: Vec<String>,
3841

39-
/// The interval between scrapes, in seconds.
42+
/// The interval between scrapes.
4043
#[serde(default = "default_scrape_interval_secs")]
41-
scrape_interval_secs: u64,
44+
#[serde_as(as = "serde_with::DurationSeconds<u64>")]
45+
scrape_interval_secs: Duration,
4246

4347
/// The namespace of the metric.
4448
///
@@ -47,8 +51,8 @@ pub struct ApacheMetricsConfig {
4751
namespace: String,
4852
}
4953

50-
pub const fn default_scrape_interval_secs() -> u64 {
51-
15
54+
pub const fn default_scrape_interval_secs() -> Duration {
55+
Duration::from_secs(15)
5256
}
5357

5458
pub fn default_namespace() -> String {
@@ -141,14 +145,14 @@ impl UriExt for http::Uri {
141145

142146
fn apache_metrics(
143147
urls: Vec<http::Uri>,
144-
interval: u64,
148+
interval: Duration,
145149
namespace: Option<String>,
146150
shutdown: ShutdownSignal,
147151
mut out: SourceSender,
148152
proxy: ProxyConfig,
149153
) -> super::Source {
150154
Box::pin(async move {
151-
let mut stream = IntervalStream::new(tokio::time::interval(Duration::from_secs(interval)))
155+
let mut stream = IntervalStream::new(tokio::time::interval(interval))
152156
.take_until(shutdown)
153157
.map(move |_| stream::iter(urls.clone()))
154158
.flatten()
@@ -360,7 +364,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
360364

361365
let config = ApacheMetricsConfig {
362366
endpoints: vec![format!("http://foo:bar@{}/metrics", in_addr)],
363-
scrape_interval_secs: 1,
367+
scrape_interval_secs: Duration::from_secs(1),
364368
namespace: "custom".to_string(),
365369
};
366370

@@ -420,7 +424,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
420424

421425
let source = ApacheMetricsConfig {
422426
endpoints: vec![format!("http://{}", in_addr)],
423-
scrape_interval_secs: 1,
427+
scrape_interval_secs: Duration::from_secs(1),
424428
namespace: "apache".to_string(),
425429
}
426430
.build(SourceContext::new_test(tx, None))
@@ -454,7 +458,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
454458

455459
let source = ApacheMetricsConfig {
456460
endpoints: vec![format!("http://{}", in_addr)],
457-
scrape_interval_secs: 1,
461+
scrape_interval_secs: Duration::from_secs(1),
458462
namespace: "custom".to_string(),
459463
}
460464
.build(SourceContext::new_test(tx, None))

website/cue/reference/components/sources/apache_metrics.cue

+1-28
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,7 @@ components: sources: apache_metrics: {
5050
platform_name: null
5151
}
5252

53-
configuration: {
54-
endpoints: {
55-
description: "`mod_status` endpoints to scrape metrics from."
56-
required: true
57-
type: array: {
58-
items: type: string: {
59-
examples: ["http://localhost:8080/server-status/?auto"]
60-
}
61-
}
62-
}
63-
scrape_interval_secs: {
64-
description: "The interval between scrapes."
65-
common: true
66-
required: false
67-
type: uint: {
68-
default: 15
69-
unit: "seconds"
70-
}
71-
}
72-
namespace: {
73-
description: "The namespace of the metric. Disabled if empty."
74-
required: false
75-
common: false
76-
type: string: {
77-
default: "apache"
78-
}
79-
}
80-
}
53+
configuration: base.components.sources.apache_metrics.configuration
8154

8255
output: metrics: {
8356
// Default Apache metrics tags

website/cue/reference/components/sources/base/apache_metrics.cue

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ base: components: sources: apache_metrics: configuration: {
44
endpoints: {
55
description: "The list of `mod_status` endpoints to scrape metrics from."
66
required: true
7-
type: array: items: type: string: {}
7+
type: array: items: type: string: examples: ["http://localhost:8080/server-status/?auto"]
88
}
99
namespace: {
1010
description: """
@@ -16,8 +16,11 @@ base: components: sources: apache_metrics: configuration: {
1616
type: string: default: "apache"
1717
}
1818
scrape_interval_secs: {
19-
description: "The interval between scrapes, in seconds."
19+
description: "The interval between scrapes."
2020
required: false
21-
type: uint: default: 15
21+
type: uint: {
22+
default: 15
23+
unit: "seconds"
24+
}
2225
}
2326
}

0 commit comments

Comments
 (0)