@@ -62,10 +62,22 @@ public class RecordUtilsTest {
6262 private static final TagKey METHOD = TagKey .create ("method" );
6363 private static final TagValue CALLER_V = TagValue .create ("some caller" );
6464 private static final TagValue METHOD_V = TagValue .create ("some method" );
65+ private static final TagValue METHOD_V_2 = TagValue .create ("some other method" );
66+ private static final TagValue METHOD_V_3 = TagValue .create ("the third method" );
67+ private static final TagValue STATUS_V = TagValue .create ("ok" );
68+ private static final TagValue STATUS_V_2 = TagValue .create ("error" );
6569 private static final TagValueWithMetadata CALLER_V_WITH_MD =
6670 TagValueWithMetadata .create (CALLER_V , METADATA_UNLIMITED_PROPAGATION );
6771 private static final TagValueWithMetadata METHOD_V_WITH_MD =
6872 TagValueWithMetadata .create (METHOD_V , METADATA_UNLIMITED_PROPAGATION );
73+ private static final TagValueWithMetadata METHOD_V_2_WITH_MD =
74+ TagValueWithMetadata .create (METHOD_V_2 , METADATA_UNLIMITED_PROPAGATION );
75+ private static final TagValueWithMetadata METHOD_V_3_WITH_MD =
76+ TagValueWithMetadata .create (METHOD_V_3 , METADATA_UNLIMITED_PROPAGATION );
77+ private static final TagValueWithMetadata STATUS_V_WITH_MD =
78+ TagValueWithMetadata .create (STATUS_V , METADATA_UNLIMITED_PROPAGATION );
79+ private static final TagValueWithMetadata STATUS_V_2_WITH_MD =
80+ TagValueWithMetadata .create (STATUS_V_2 , METADATA_UNLIMITED_PROPAGATION );
6981
7082 @ Test
7183 public void testConstants () {
@@ -83,6 +95,75 @@ public void testGetTagValues() {
8395 .inOrder ();
8496 }
8597
98+ @ Test
99+ public void testGetTagValues_MapDeprecatedRpcTag () {
100+ List <TagKey > columns = Arrays .asList (RecordUtils .RPC_STATUS , RecordUtils .RPC_METHOD );
101+ Map <TagKey , TagValueWithMetadata > tags =
102+ ImmutableMap .of (
103+ RecordUtils .GRPC_CLIENT_METHOD , METHOD_V_WITH_MD ,
104+ RecordUtils .GRPC_CLIENT_STATUS , STATUS_V_WITH_MD );
105+
106+ assertThat (RecordUtils .getTagValues (tags , columns ))
107+ .containsExactly (STATUS_V , METHOD_V )
108+ .inOrder ();
109+ }
110+
111+ @ Test
112+ public void testGetTagValues_MapDeprecatedRpcTag_WithServerTag () {
113+ List <TagKey > columns = Arrays .asList (RecordUtils .RPC_STATUS , RecordUtils .RPC_METHOD );
114+ Map <TagKey , TagValueWithMetadata > tags =
115+ ImmutableMap .of (
116+ RecordUtils .GRPC_SERVER_METHOD , METHOD_V_WITH_MD ,
117+ RecordUtils .GRPC_SERVER_STATUS , STATUS_V_WITH_MD );
118+
119+ assertThat (RecordUtils .getTagValues (tags , columns ))
120+ .containsExactly (STATUS_V , METHOD_V )
121+ .inOrder ();
122+ }
123+
124+ @ Test
125+ public void testGetTagValues_MapDeprecatedRpcTag_PreferClientTag () {
126+ List <TagKey > columns = Arrays .asList (RecordUtils .RPC_STATUS , RecordUtils .RPC_METHOD );
127+ Map <TagKey , TagValueWithMetadata > tags =
128+ ImmutableMap .of (
129+ RecordUtils .GRPC_SERVER_METHOD , METHOD_V_WITH_MD ,
130+ RecordUtils .GRPC_SERVER_STATUS , STATUS_V_WITH_MD ,
131+ RecordUtils .GRPC_CLIENT_METHOD , METHOD_V_2_WITH_MD ,
132+ RecordUtils .GRPC_CLIENT_STATUS , STATUS_V_2_WITH_MD );
133+
134+ // When both client and server new tags are present, client values take precedence.
135+ assertThat (RecordUtils .getTagValues (tags , columns ))
136+ .containsExactly (STATUS_V_2 , METHOD_V_2 )
137+ .inOrder ();
138+ }
139+
140+ @ Test
141+ public void testGetTagValues_WithOldMethodTag () {
142+ List <TagKey > columns = Arrays .asList (RecordUtils .RPC_METHOD );
143+ Map <TagKey , TagValueWithMetadata > tags =
144+ ImmutableMap .of (
145+ RecordUtils .GRPC_SERVER_METHOD , METHOD_V_WITH_MD ,
146+ RecordUtils .GRPC_CLIENT_METHOD , METHOD_V_2_WITH_MD ,
147+ RecordUtils .RPC_METHOD , METHOD_V_3_WITH_MD );
148+
149+ // When the old "method" tag is set, it always takes precedence.
150+ assertThat (RecordUtils .getTagValues (tags , columns )).containsExactly (METHOD_V_3 ).inOrder ();
151+ }
152+
153+ @ Test
154+ public void testGetTagValues_WithNewTags () {
155+ List <TagKey > columns =
156+ Arrays .asList (RecordUtils .GRPC_CLIENT_METHOD , RecordUtils .GRPC_SERVER_METHOD );
157+ Map <TagKey , TagValueWithMetadata > tags =
158+ ImmutableMap .of (
159+ RecordUtils .GRPC_SERVER_METHOD , METHOD_V_WITH_MD ,
160+ RecordUtils .GRPC_CLIENT_METHOD , METHOD_V_2_WITH_MD );
161+
162+ assertThat (RecordUtils .getTagValues (tags , columns ))
163+ .containsExactly (METHOD_V_2 , METHOD_V )
164+ .inOrder ();
165+ }
166+
86167 @ Test
87168 public void createMutableAggregation () {
88169 BucketBoundaries bucketBoundaries = BucketBoundaries .create (Arrays .asList (-1.0 , 0.0 , 1.0 ));
0 commit comments