@@ -365,6 +365,61 @@ mod tests {
365365 names
366366 }
367367
368+ /// Every metrics Service must carry the Prometheus scrape label and the
369+ /// `prometheus.io/path|port|scheme|scrape` annotations, or Prometheus stops discovering the
370+ /// endpoints (caught by the HDFS smoke test 2026-07-23 after the labels migration dropped
371+ /// them).
372+ #[ test]
373+ fn metrics_services_carry_prometheus_label_and_annotations ( ) {
374+ let cluster = validated_cluster ( ) ;
375+ let resources = build ( & cluster, & cluster_info ( ) ) . expect ( "build succeeds" ) ;
376+
377+ let metrics_services: Vec < _ > = resources
378+ . services
379+ . iter ( )
380+ . filter ( |service| {
381+ service
382+ . metadata
383+ . name
384+ . as_deref ( )
385+ . is_some_and ( |name| name. ends_with ( "-metrics" ) )
386+ } )
387+ . collect ( ) ;
388+ assert ! ( !metrics_services. is_empty( ) , "no metrics Services built" ) ;
389+
390+ for service in metrics_services {
391+ let name = service. metadata . name . as_deref ( ) . unwrap_or_default ( ) ;
392+ let labels = service. metadata . labels . as_ref ( ) . expect ( "labels are set" ) ;
393+ assert_eq ! (
394+ labels. get( "prometheus.io/scrape" ) . map( String :: as_str) ,
395+ Some ( "true" ) ,
396+ "{name} lacks the scrape label"
397+ ) ;
398+
399+ // The native metrics port of the role, as asserted by the smoke test.
400+ let expected_port = match name {
401+ n if n. contains ( "-namenode-" ) => "9870" ,
402+ n if n. contains ( "-datanode-" ) => "9864" ,
403+ n if n. contains ( "-journalnode-" ) => "8480" ,
404+ other => panic ! ( "unexpected metrics Service {other}" ) ,
405+ } ;
406+ let expected_annotations = BTreeMap :: from (
407+ [
408+ ( "prometheus.io/path" , "/prom" ) ,
409+ ( "prometheus.io/port" , expected_port) ,
410+ ( "prometheus.io/scheme" , "http" ) ,
411+ ( "prometheus.io/scrape" , "true" ) ,
412+ ]
413+ . map ( |( key, value) | ( key. to_string ( ) , value. to_string ( ) ) ) ,
414+ ) ;
415+ assert_eq ! (
416+ service. metadata. annotations. as_ref( ) ,
417+ Some ( & expected_annotations) ,
418+ "{name} annotations mismatch"
419+ ) ;
420+ }
421+ }
422+
368423 /// The aggregator emits, for the minimal three-role cluster (one `default` role group each):
369424 /// one StatefulSet and one ConfigMap per role group, one headless plus one metrics Service per
370425 /// role group, and one default PDB per role.
0 commit comments