Skip to content

Commit 2ab2d4f

Browse files
committed
applications export Prometheus metrics
1 parent 2bb8dff commit 2ab2d4f

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

rust/operator-binary/src/crd/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,14 @@ impl v1alpha1::SparkApplication {
649649
)]);
650650
}
651651

652+
// Enable Prometheus metrics export
653+
submit_cmd.extend(vec![
654+
"--conf spark.metrics.conf.\\*.sink.prometheusServlet.class=org.apache.spark.metrics.sink.PrometheusServlet".to_string(),
655+
"--conf spark.metrics.conf.\\*.sink.prometheusServlet.path=/metrics/prometheus".to_string(),
656+
"--conf spark.ui.prometheus.enabled=true".to_string(),
657+
"--conf spark.sql.streaming.metricsEnabled=true".to_string(),
658+
]);
659+
652660
// some command elements need to be initially stored in a map (to allow overwrites) and
653661
// then added to the vector once complete.
654662
let mut submit_conf: BTreeMap<String, String> = BTreeMap::new();

rust/operator-binary/src/spark_k8s_controller.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use stackable_operator::{
3737
core::{DeserializeGuard, error_boundary},
3838
runtime::{controller::Action, reflector::ObjectRef},
3939
},
40+
kvp::Label,
4041
logging::controller::ReconcilerError,
4142
product_config_utils::ValidatedRoleConfigByPropertyKind,
4243
product_logging::{
@@ -610,27 +611,32 @@ fn pod_template(
610611
);
611612
}
612613

614+
let mut omb = ObjectMetaBuilder::new();
615+
omb.name(&container_name)
616+
// this reference is not pointing to a controller but only provides a UID that can used to clean up resources
617+
// cleanly (specifically driver pods and related config maps) when the spark application is deleted.
618+
.ownerreference_from_resource(spark_application, None, None)
619+
.context(ObjectMissingMetadataForOwnerRefSnafu)?
620+
.with_recommended_labels(
621+
spark_application
622+
.build_recommended_labels(&spark_image.app_version_label, &container_name),
623+
)
624+
.context(MetadataBuildSnafu)?;
625+
626+
// Only the driver pod should be scraped by Prometheus
627+
// because the executor metrics are also available via /metrics/executors/prometheus/
628+
if role == SparkApplicationRole::Driver {
629+
omb.with_label(Label::try_from(("prometheus.io/scrape", "true")).context(LabelBuildSnafu)?);
630+
}
631+
613632
let mut pb = PodBuilder::new();
614-
pb.metadata(
615-
ObjectMetaBuilder::new()
616-
.name(&container_name)
617-
// this reference is not pointing to a controller but only provides a UID that can used to clean up resources
618-
// cleanly (specifically driver pods and related config maps) when the spark application is deleted.
619-
.ownerreference_from_resource(spark_application, None, None)
620-
.context(ObjectMissingMetadataForOwnerRefSnafu)?
621-
.with_recommended_labels(
622-
spark_application
623-
.build_recommended_labels(&spark_image.app_version_label, &container_name),
624-
)
625-
.context(MetadataBuildSnafu)?
626-
.build(),
627-
)
628-
.add_container(cb.build())
629-
.add_volumes(volumes.to_vec())
630-
.context(AddVolumeSnafu)?
631-
.security_context(security_context())
632-
.image_pull_secrets_from_product_image(spark_image)
633-
.affinity(&config.affinity);
633+
pb.metadata(omb.build())
634+
.add_container(cb.build())
635+
.add_volumes(volumes.to_vec())
636+
.context(AddVolumeSnafu)?
637+
.security_context(security_context())
638+
.image_pull_secrets_from_product_image(spark_image)
639+
.affinity(&config.affinity);
634640

635641
let init_containers = init_containers(
636642
spark_application,

0 commit comments

Comments
 (0)