Skip to content

Commit a761cb3

Browse files
authored
Add Connection resource map (#289)
1 parent 94d4795 commit a761cb3

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

retrieval/resource_map.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ var TargetV2ResourceMap = ResourceMap{
147147
},
148148
}
149149

150+
var ConnectionResourceMap = ResourceMap{
151+
Type: "connectors.googleapis.com/Connection",
152+
MatchLabel: "__meta_kubernetes_pod_label_type_connection",
153+
LabelMap: map[string]labelTranslation{
154+
ProjectIDLabel: constValue("resource_container"),
155+
KubernetesLocationLabel: constValue("location"),
156+
"connection": constValue("connection"),
157+
},
158+
}
159+
150160
var AnthosL4LBMap = ResourceMap{
151161
Type: "anthos_l4lb",
152162
MatchLabel: "__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_type",
@@ -164,6 +174,7 @@ type ResourceMapList []ResourceMap
164174
// When you add new elements, you also probably want to update TestResourceMappingsOrder.
165175
var ResourceMappings = ResourceMapList{
166176
AnthosL4LBMap,
177+
ConnectionResourceMap,
167178
TargetV2ResourceMap,
168179
ProxyV2ResourceMap,
169180
ProxyResourceMap,

retrieval/resource_map_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
288318
func 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

Comments
 (0)