-
Notifications
You must be signed in to change notification settings - Fork 66
feat: Add internal telemetry prometheus exporter #1691
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
Merged
lquerel
merged 9 commits into
open-telemetry:main
from
andborja:andborja/36262190PrometheusExporter
Jan 3, 2026
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18d1ef7
feat: Add internal telemetry prometheus exporter.
andborja 04a95f4
Improve test coverage
andborja 820d32c
Merge branch 'main' into andborja/36262190PrometheusExporter
andborja 8eb4c24
Fix fmt
andborja df28ff2
Merge branch 'main' into andborja/36262190PrometheusExporter
andborja 760904c
Merge branch 'main' into andborja/36262190PrometheusExporter
andborja f2449de
Add defaults to host and port
andborja eeac03e
Merge branch 'main' into andborja/36262190PrometheusExporter
andborja 722c935
Update readme with prometheus information
andborja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
rust/otap-dataflow/configs/fake-debug-noop-promethueus-telemetry.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| settings: | ||
| default_pipeline_ctrl_msg_channel_size: 100 | ||
| default_node_ctrl_msg_channel_size: 100 | ||
| default_pdata_channel_size: 100 | ||
|
|
||
| nodes: | ||
| receiver: | ||
| kind: receiver | ||
| plugin_urn: "urn:otel:otap:fake_data_generator:receiver" | ||
| out_ports: | ||
| out_port: | ||
| destinations: | ||
| - debug | ||
| dispatch_strategy: round_robin | ||
| config: | ||
| traffic_config: | ||
| max_signal_count: 1000 | ||
| max_batch_size: 1000 | ||
| signals_per_second: 1000 | ||
| log_weight: 100 | ||
| registry_path: https://github.com/open-telemetry/semantic-conventions.git[model] | ||
| debug: | ||
| kind: processor | ||
| plugin_urn: "urn:otel:debug:processor" | ||
| out_ports: | ||
| out_port: | ||
| destinations: | ||
| - noop | ||
| dispatch_strategy: round_robin | ||
| config: | ||
| verbosity: basic | ||
| noop: | ||
| kind: exporter | ||
| plugin_urn: "urn:otel:noop:exporter" | ||
| config: | ||
|
|
||
| service: | ||
| telemetry: | ||
| metrics: | ||
| readers: | ||
| - pull: | ||
| exporter: | ||
| prometheus: | ||
| host: "0.0.0.0" | ||
| port: 9090 | ||
| path: "/metrics" | ||
| views: | ||
| - selector: | ||
| instrument_name: "logs.produced" | ||
| stream: | ||
| name: "otlp.logs.produced.count" | ||
| description: "Count of logs produced" | ||
| resource: | ||
| service.name: "fake-debug-noop-service" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
rust/otap-dataflow/crates/config/src/pipeline/service/telemetry/metrics/readers/pull.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Pull reader level configurations. | ||
|
|
||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// OpenTelemetry Metrics Pull Exporter configuration. | ||
| #[derive(Debug, Clone, Serialize, JsonSchema, PartialEq)] | ||
| #[serde(rename_all = "lowercase")] | ||
| pub enum MetricsPullExporterConfig { | ||
| /// Prometheus exporter that exposes metrics for scraping. | ||
| Prometheus(PrometheusExporterConfig), | ||
| } | ||
|
|
||
| impl<'de> Deserialize<'de> for MetricsPullExporterConfig { | ||
| /// Custom deserialization to handle different exporter types. | ||
| fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| { | ||
| use serde::de::{MapAccess, Visitor}; | ||
| use std::fmt; | ||
| struct MetricsPullExporterConfigVisitor; | ||
|
|
||
| impl<'de> Visitor<'de> for MetricsPullExporterConfigVisitor { | ||
| type Value = MetricsPullExporterConfig; | ||
|
|
||
| fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| formatter.write_str("a map with 'prometheus' key") | ||
| } | ||
|
|
||
| fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> | ||
| where | ||
| M: MapAccess<'de>, | ||
| { | ||
| if let Some(key) = map.next_key::<String>()? { | ||
| match key.as_str() { | ||
| "prometheus" => { | ||
| let prometheus_config: PrometheusExporterConfig = map.next_value()?; | ||
| Ok(MetricsPullExporterConfig::Prometheus(prometheus_config)) | ||
| } | ||
| _ => Err(serde::de::Error::unknown_field(&key, &["prometheus"])), | ||
| } | ||
| } else { | ||
| Err(serde::de::Error::custom("Expected 'prometheus' exporter")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| deserializer.deserialize_map(MetricsPullExporterConfigVisitor) | ||
| } | ||
| } | ||
|
|
||
| /// Prometheus Exporter configuration. | ||
| #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub struct PrometheusExporterConfig { | ||
| /// The host address where the Prometheus exporter will expose metrics. | ||
| #[serde(default = "default_host")] | ||
| pub host: String, | ||
|
|
||
| /// The port on which the Prometheus exporter will listen for scrape requests. | ||
| #[serde(default = "default_port")] | ||
| pub port: u16, | ||
|
|
||
| /// The HTTP path where metrics will be exposed. | ||
| #[serde(default = "default_metrics_path")] | ||
| pub path: String, | ||
| } | ||
|
|
||
| fn default_host() -> String { | ||
| "0.0.0.0".to_string() | ||
| } | ||
|
|
||
| fn default_port() -> u16 { | ||
| 9090 | ||
| } | ||
|
|
||
| fn default_metrics_path() -> String { | ||
| "/metrics".to_string() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_metrics_pull_exporter_config_deserialize() { | ||
| let yaml_str = r#" | ||
| prometheus: | ||
| host: "127.0.0.1" | ||
| port: 9090 | ||
| path: "/" | ||
| "#; | ||
| let config: MetricsPullExporterConfig = serde_yaml::from_str(yaml_str).unwrap(); | ||
|
|
||
| let MetricsPullExporterConfig::Prometheus(prometheus_config) = config; | ||
| assert_eq!(prometheus_config.host, "127.0.0.1"); | ||
| assert_eq!(prometheus_config.port, 9090); | ||
| assert_eq!(prometheus_config.path, "/"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_metrics_pull_exporter_invalid_config_deserialize() { | ||
| let yaml_str = r#" | ||
| unknown_exporter: | ||
| some_field: "value" | ||
| "#; | ||
| let result: Result<MetricsPullExporterConfig, _> = serde_yaml::from_str(yaml_str); | ||
| match result { | ||
| Ok(_) => panic!("Deserialization should have failed for unknown exporter"), | ||
| Err(err) => { | ||
| let err_msg = err.to_string(); | ||
| assert!(err_msg.contains("unknown field")); | ||
| assert!(err_msg.contains("prometheus")); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_prometheus_exporter_config_deserialize() { | ||
| let yaml_str = r#" | ||
| host: "127.0.0.1" | ||
| port: 9090 | ||
| path: "/custom_metrics" | ||
| "#; | ||
| let config: PrometheusExporterConfig = serde_yaml::from_str(yaml_str).unwrap(); | ||
| assert_eq!(config.host, "127.0.0.1"); | ||
| assert_eq!(config.port, 9090); | ||
| assert_eq!(config.path, "/custom_metrics"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_prometheus_exporter_config_default_path_deserialize() { | ||
| let yaml_str = r#" | ||
| host: "127.0.0.1" | ||
| port: 9090 | ||
| "#; | ||
| let config: PrometheusExporterConfig = serde_yaml::from_str(yaml_str).unwrap(); | ||
| assert_eq!(config.host, "127.0.0.1"); | ||
| assert_eq!(config.port, 9090); | ||
| assert_eq!(config.path, "/metrics"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_prometheus_exporter_unknown_field_config_deserialize() { | ||
| let yaml_str = r#" | ||
| host: "0.0.0.0" | ||
| port: 8080 | ||
| extra_field: "unexpected" | ||
| "#; | ||
| let result: Result<PrometheusExporterConfig, _> = serde_yaml::from_str(yaml_str); | ||
| match result { | ||
| Ok(_) => panic!("Deserialization should have failed for unknown field"), | ||
| Err(err) => { | ||
| let err_msg = err.to_string(); | ||
| assert!(err_msg.contains("unknown field `extra_field`")); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_prometheus_exporter_config_defaults() { | ||
| let yaml_str = r#""#; | ||
| let config: PrometheusExporterConfig = serde_yaml::from_str(yaml_str).unwrap(); | ||
| assert_eq!(config.host, "0.0.0.0"); | ||
| assert_eq!(config.port, 9090); | ||
| assert_eq!(config.path, "/metrics"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.