@@ -6742,6 +6742,14 @@ const STUB_COUNTER_TAG_EXTRACTED_NAMES: [&str; 2] = ["cluster.rq_total", "counte
67426742const STUB_COUNTER_TAGS : [ & [ ( & str , & str ) ] ; 2 ] =
67436743 [ & [ ( "envoy.cluster_name" , "foo" ) , ( "envoy.response_code" , "200" ) ] , & [ ] ] ;
67446744
6745+ // Tag data for the single stub gauge and text readout, matching STUB_GAUGES / STUB_TEXT_READOUTS.
6746+ // Both carry one tag so the gauge and text-readout tag wrappers are exercised distinctly from the
6747+ // counter ones, guarding against a wrapper wired to the wrong ABI callback.
6748+ const STUB_GAUGE_TAG_EXTRACTED_NAMES : [ & str ; 1 ] = [ "cluster.cx_active" ] ;
6749+ const STUB_GAUGE_TAGS : [ & [ ( & str , & str ) ] ; 1 ] = [ & [ ( "envoy.cluster_name" , "bar" ) ] ] ;
6750+ const STUB_TEXT_READOUT_TAG_EXTRACTED_NAMES : [ & str ; 1 ] = [ "control_plane.identifier" ] ;
6751+ const STUB_TEXT_READOUT_TAGS : [ & [ ( & str , & str ) ] ; 1 ] = [ & [ ( "envoy.control_plane" , "xds" ) ] ] ;
6752+
67456753// Counts stub_write invocations on the calling thread so tests can assert the grow-and-retry
67466754// behavior (each ABI getter call writes its name once, plus a value for text readouts). It is
67476755// thread-local so it stays correct even if tests run in parallel.
@@ -6866,9 +6874,8 @@ pub extern "C" fn envoy_dynamic_module_callback_stat_sink_snapshot_get_counter_t
68666874 true
68676875}
68686876
6869- // Gauge and text-readout tag callbacks share the counter tag code paths, so the harness stubs
6870- // them as empty (no tags) purely to satisfy linkage; the counter stubs above carry the tag data
6871- // the tests exercise.
6877+ // The gauge and text-readout tag callbacks share the counter tag code paths, but each stub serves
6878+ // its own canned data so the corresponding SDK wrappers are exercised distinctly.
68726879#[ no_mangle]
68736880pub extern "C" fn envoy_dynamic_module_callback_stat_sink_snapshot_get_gauge_tag_extracted_name (
68746881 _snapshot : abi:: envoy_dynamic_module_type_stat_sink_snapshot_envoy_ptr ,
@@ -6877,10 +6884,17 @@ pub extern "C" fn envoy_dynamic_module_callback_stat_sink_snapshot_get_gauge_tag
68776884 name_buffer_capacity : usize ,
68786885 name_size : * mut usize ,
68796886) -> bool {
6880- if index >= STUB_GAUGES . len ( ) {
6887+ if index >= STUB_GAUGE_TAG_EXTRACTED_NAMES . len ( ) {
68816888 return false ;
68826889 }
6883- unsafe { stub_write ( STUB_GAUGES [ index] . 0 , name_buffer, name_buffer_capacity, name_size) } ;
6890+ unsafe {
6891+ stub_write (
6892+ STUB_GAUGE_TAG_EXTRACTED_NAMES [ index] ,
6893+ name_buffer,
6894+ name_buffer_capacity,
6895+ name_size,
6896+ ) ;
6897+ }
68846898 true
68856899}
68866900
@@ -6890,26 +6904,34 @@ pub extern "C" fn envoy_dynamic_module_callback_stat_sink_snapshot_get_gauge_tag
68906904 index : usize ,
68916905 tag_count : * mut usize ,
68926906) -> bool {
6893- if index >= STUB_GAUGES . len ( ) {
6907+ if index >= STUB_GAUGE_TAGS . len ( ) {
68946908 return false ;
68956909 }
6896- unsafe { * tag_count = 0 } ;
6910+ unsafe { * tag_count = STUB_GAUGE_TAGS [ index ] . len ( ) } ;
68976911 true
68986912}
68996913
69006914#[ no_mangle]
69016915pub extern "C" fn envoy_dynamic_module_callback_stat_sink_snapshot_get_gauge_tag (
69026916 _snapshot : abi:: envoy_dynamic_module_type_stat_sink_snapshot_envoy_ptr ,
6903- _index : usize ,
6904- _tag_index : usize ,
6905- _name_buffer : * mut std:: ffi:: c_char ,
6906- _name_buffer_capacity : usize ,
6907- _name_size : * mut usize ,
6908- _value_buffer : * mut std:: ffi:: c_char ,
6909- _value_buffer_capacity : usize ,
6910- _value_size : * mut usize ,
6917+ index : usize ,
6918+ tag_index : usize ,
6919+ name_buffer : * mut std:: ffi:: c_char ,
6920+ name_buffer_capacity : usize ,
6921+ name_size : * mut usize ,
6922+ value_buffer : * mut std:: ffi:: c_char ,
6923+ value_buffer_capacity : usize ,
6924+ value_size : * mut usize ,
69116925) -> bool {
6912- false
6926+ if index >= STUB_GAUGE_TAGS . len ( ) || tag_index >= STUB_GAUGE_TAGS [ index] . len ( ) {
6927+ return false ;
6928+ }
6929+ let ( name, value) = STUB_GAUGE_TAGS [ index] [ tag_index] ;
6930+ unsafe {
6931+ stub_write ( name, name_buffer, name_buffer_capacity, name_size) ;
6932+ stub_write ( value, value_buffer, value_buffer_capacity, value_size) ;
6933+ }
6934+ true
69136935}
69146936
69156937#[ no_mangle]
@@ -6920,10 +6942,17 @@ pub extern "C" fn envoy_dynamic_module_callback_stat_sink_snapshot_get_text_read
69206942 name_buffer_capacity : usize ,
69216943 name_size : * mut usize ,
69226944) -> bool {
6923- if index >= STUB_TEXT_READOUTS . len ( ) {
6945+ if index >= STUB_TEXT_READOUT_TAG_EXTRACTED_NAMES . len ( ) {
69246946 return false ;
69256947 }
6926- unsafe { stub_write ( STUB_TEXT_READOUTS [ index] . 0 , name_buffer, name_buffer_capacity, name_size) } ;
6948+ unsafe {
6949+ stub_write (
6950+ STUB_TEXT_READOUT_TAG_EXTRACTED_NAMES [ index] ,
6951+ name_buffer,
6952+ name_buffer_capacity,
6953+ name_size,
6954+ ) ;
6955+ }
69276956 true
69286957}
69296958
@@ -6933,26 +6962,34 @@ pub extern "C" fn envoy_dynamic_module_callback_stat_sink_snapshot_get_text_read
69336962 index : usize ,
69346963 tag_count : * mut usize ,
69356964) -> bool {
6936- if index >= STUB_TEXT_READOUTS . len ( ) {
6965+ if index >= STUB_TEXT_READOUT_TAGS . len ( ) {
69376966 return false ;
69386967 }
6939- unsafe { * tag_count = 0 } ;
6968+ unsafe { * tag_count = STUB_TEXT_READOUT_TAGS [ index ] . len ( ) } ;
69406969 true
69416970}
69426971
69436972#[ no_mangle]
69446973pub extern "C" fn envoy_dynamic_module_callback_stat_sink_snapshot_get_text_readout_tag (
69456974 _snapshot : abi:: envoy_dynamic_module_type_stat_sink_snapshot_envoy_ptr ,
6946- _index : usize ,
6947- _tag_index : usize ,
6948- _name_buffer : * mut std:: ffi:: c_char ,
6949- _name_buffer_capacity : usize ,
6950- _name_size : * mut usize ,
6951- _value_buffer : * mut std:: ffi:: c_char ,
6952- _value_buffer_capacity : usize ,
6953- _value_size : * mut usize ,
6975+ index : usize ,
6976+ tag_index : usize ,
6977+ name_buffer : * mut std:: ffi:: c_char ,
6978+ name_buffer_capacity : usize ,
6979+ name_size : * mut usize ,
6980+ value_buffer : * mut std:: ffi:: c_char ,
6981+ value_buffer_capacity : usize ,
6982+ value_size : * mut usize ,
69546983) -> bool {
6955- false
6984+ if index >= STUB_TEXT_READOUT_TAGS . len ( ) || tag_index >= STUB_TEXT_READOUT_TAGS [ index] . len ( ) {
6985+ return false ;
6986+ }
6987+ let ( name, value) = STUB_TEXT_READOUT_TAGS [ index] [ tag_index] ;
6988+ unsafe {
6989+ stub_write ( name, name_buffer, name_buffer_capacity, name_size) ;
6990+ stub_write ( value, value_buffer, value_buffer_capacity, value_size) ;
6991+ }
6992+ true
69566993}
69576994
69586995#[ no_mangle]
@@ -7139,6 +7176,27 @@ fn test_metric_snapshot_reads_tags() {
71397176 assert_eq ! ( snapshot. counter_tag_count( 2 ) , None ) ;
71407177 assert ! ( !snapshot. counter_tag( 0 , 2 , & mut name, & mut value) ) ;
71417178 assert ! ( !snapshot. counter_tag( 2 , 0 , & mut name, & mut value) ) ;
7179+
7180+ // gauge_0: one tag. Exercises the gauge tag wrappers, which are distinct entry points from the
7181+ // counter ones.
7182+ assert ! ( snapshot. gauge_tag_extracted_name( 0 , & mut name) ) ;
7183+ assert_eq ! ( name. as_slice( ) , b"cluster.cx_active" ) ;
7184+ assert_eq ! ( snapshot. gauge_tag_count( 0 ) , Some ( 1 ) ) ;
7185+ assert ! ( snapshot. gauge_tag( 0 , 0 , & mut name, & mut value) ) ;
7186+ assert_eq ! ( name. as_slice( ) , b"envoy.cluster_name" ) ;
7187+ assert_eq ! ( value. as_slice( ) , b"bar" ) ;
7188+ assert_eq ! ( snapshot. gauge_tag_count( 1 ) , None ) ;
7189+ assert ! ( !snapshot. gauge_tag( 0 , 1 , & mut name, & mut value) ) ;
7190+
7191+ // text_0: one tag. Exercises the text-readout tag wrappers.
7192+ assert ! ( snapshot. text_readout_tag_extracted_name( 0 , & mut name) ) ;
7193+ assert_eq ! ( name. as_slice( ) , b"control_plane.identifier" ) ;
7194+ assert_eq ! ( snapshot. text_readout_tag_count( 0 ) , Some ( 1 ) ) ;
7195+ assert ! ( snapshot. text_readout_tag( 0 , 0 , & mut name, & mut value) ) ;
7196+ assert_eq ! ( name. as_slice( ) , b"envoy.control_plane" ) ;
7197+ assert_eq ! ( value. as_slice( ) , b"xds" ) ;
7198+ assert_eq ! ( snapshot. text_readout_tag_count( 1 ) , None ) ;
7199+ assert ! ( !snapshot. text_readout_tag( 0 , 1 , & mut name, & mut value) ) ;
71427200}
71437201
71447202#[ test]
0 commit comments