@@ -285,6 +285,36 @@ func TestTranslateProxyV2(t *testing.T) {
285285 }
286286}
287287
288+ func TestTranslateConnection (t * testing.T ) {
289+ discoveredLabels := labels.Labels {
290+ {"__meta_kubernetes_pod_label_type_connection" , "true" },
291+ {ProjectIDLabel , "my-project" },
292+ {KubernetesLocationLabel , "us-central1-a" },
293+ }
294+ metricLabels := labels.Labels {
295+ {"connection" , "my-connection-name" },
296+ {"extra_label" , "my-label" },
297+ }
298+ expectedLabels := map [string ]string {
299+ "resource_container" : "my-project" ,
300+ "location" : "us-central1-a" ,
301+ "connection" : "my-connection-name" ,
302+ }
303+ expectedFinalLabels := labels.Labels {
304+ {"extra_label" , "my-label" },
305+ }
306+ if labels , finalLabels := ConnectionResourceMap .Translate (discoveredLabels , metricLabels ); labels == nil {
307+ t .Errorf ("Expected %v, actual nil" , expectedLabels )
308+ } else {
309+ if diff := cmp .Diff (expectedLabels , labels ); len (diff ) > 0 {
310+ t .Error (diff )
311+ }
312+ if diff := cmp .Diff (expectedFinalLabels , finalLabels ); len (diff ) > 0 {
313+ t .Error (diff )
314+ }
315+ }
316+ }
317+
288318func TestTranslateAnthosL4LB (t * testing.T ) {
289319 discoveredLabels := labels.Labels {
290320 {ProjectIDLabel , "my-project" },
@@ -357,6 +387,7 @@ func TestResourceMappingsOrder(t *testing.T) {
357387 {"k8s_node" , "gce_instance" },
358388 {"k8s_node" , "aws_ec2_instance" },
359389 {"anthos_l4lb" , "k8s_container" },
390+ {"connectors.googleapis.com/Connection" , "k8s_container" },
360391 {"apigee.googleapis.com/TargetV2" , "k8s_container" },
361392 {"apigee.googleapis.com/ProxyV2" , "k8s_container" },
362393 {"apigee.googleapis.com/Proxy" , "k8s_container" },
0 commit comments