Skip to content

Commit

Permalink
Add Connection resource map (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
mju authored Aug 16, 2021
1 parent 94d4795 commit a761cb3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions retrieval/resource_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ var TargetV2ResourceMap = ResourceMap{
},
}

var ConnectionResourceMap = ResourceMap{
Type: "connectors.googleapis.com/Connection",
MatchLabel: "__meta_kubernetes_pod_label_type_connection",
LabelMap: map[string]labelTranslation{
ProjectIDLabel: constValue("resource_container"),
KubernetesLocationLabel: constValue("location"),
"connection": constValue("connection"),
},
}

var AnthosL4LBMap = ResourceMap{
Type: "anthos_l4lb",
MatchLabel: "__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_type",
Expand All @@ -164,6 +174,7 @@ type ResourceMapList []ResourceMap
// When you add new elements, you also probably want to update TestResourceMappingsOrder.
var ResourceMappings = ResourceMapList{
AnthosL4LBMap,
ConnectionResourceMap,
TargetV2ResourceMap,
ProxyV2ResourceMap,
ProxyResourceMap,
Expand Down
31 changes: 31 additions & 0 deletions retrieval/resource_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,36 @@ func TestTranslateProxyV2(t *testing.T) {
}
}

func TestTranslateConnection(t *testing.T) {
discoveredLabels := labels.Labels{
{"__meta_kubernetes_pod_label_type_connection", "true"},
{ProjectIDLabel, "my-project"},
{KubernetesLocationLabel, "us-central1-a"},
}
metricLabels := labels.Labels{
{"connection", "my-connection-name"},
{"extra_label", "my-label"},
}
expectedLabels := map[string]string{
"resource_container": "my-project",
"location": "us-central1-a",
"connection": "my-connection-name",
}
expectedFinalLabels := labels.Labels{
{"extra_label", "my-label"},
}
if labels, finalLabels := ConnectionResourceMap.Translate(discoveredLabels, metricLabels); labels == nil {
t.Errorf("Expected %v, actual nil", expectedLabels)
} else {
if diff := cmp.Diff(expectedLabels, labels); len(diff) > 0 {
t.Error(diff)
}
if diff := cmp.Diff(expectedFinalLabels, finalLabels); len(diff) > 0 {
t.Error(diff)
}
}
}

func TestTranslateAnthosL4LB(t *testing.T) {
discoveredLabels := labels.Labels{
{ProjectIDLabel, "my-project"},
Expand Down Expand Up @@ -357,6 +387,7 @@ func TestResourceMappingsOrder(t *testing.T) {
{"k8s_node", "gce_instance"},
{"k8s_node", "aws_ec2_instance"},
{"anthos_l4lb", "k8s_container"},
{"connectors.googleapis.com/Connection", "k8s_container"},
{"apigee.googleapis.com/TargetV2", "k8s_container"},
{"apigee.googleapis.com/ProxyV2", "k8s_container"},
{"apigee.googleapis.com/Proxy", "k8s_container"},
Expand Down

0 comments on commit a761cb3

Please sign in to comment.