Skip to content

Commit

Permalink
Add ProxyV2 resource map
Browse files Browse the repository at this point in the history
  • Loading branch information
msukruth committed Jun 15, 2020
1 parent e96e730 commit 8067923
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions retrieval/resource_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,25 @@ var ProxyResourceMap = ResourceMap{
},
}

var ProxyV2ResourceMap = ResourceMap{
Type: "apigee.googleapis.com/ProxyV2",
MatchLabel: "__meta_kubernetes_pod_label_type_proxy_v2",
LabelMap: map[string]labelTranslation{
ProjectIDLabel: constValue("resource_container"),
KubernetesLocationLabel: constValue("location"),
"org": constValue("org"),
"env": constValue("env"),
"proxy_name": constValue("proxy_name"),
"runtime_version": constValue("runtime_version"),
"instance_id": constValue("instance_id"),
},
}

type ResourceMapList []ResourceMap

// When you add new elements, you also probably want to update TestResourceMappingsOrder.
var ResourceMappings = ResourceMapList{
ProxyV2ResourceMap,
ProxyResourceMap,
DevappResourceMap,
{
Expand Down
39 changes: 39 additions & 0 deletions retrieval/resource_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,44 @@ func TestTranslateProxy(t *testing.T) {
}
}

func TestTranslateProxyV2(t *testing.T) {
discoveredLabels := labels.Labels{
{"__meta_kubernetes_pod_label_type_proxy_v2", "true"},
{ProjectIDLabel, "my-project"},
{KubernetesLocationLabel, "us-central1-a"},
}
metricLabels := labels.Labels{
{"proxy_name", "my-name"},
{"org", "my-org"},
{"env", "my-env"},
{"runtime_version", "my-revision"},
{"instance_id", "my-instance"},
{"extra_label", "my-label"},
}
expectedLabels := map[string]string{
"resource_container": "my-project",
"location": "us-central1-a",
"org": "my-org",
"env": "my-env",
"proxy_name": "my-name",
"runtime_version": "my-revision",
"instance_id": "my-instance",
}
expectedFinalLabels := labels.Labels{
{"extra_label", "my-label"},
}
if labels, finalLabels := ProxyV2ResourceMap.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 (m *ResourceMapList) getByType(t string) (*ResourceMap, bool) {
for _, m := range *m {
if m.Type == t {
Expand Down Expand Up @@ -236,6 +274,7 @@ func TestResourceMappingsOrder(t *testing.T) {
{"k8s_pod", "k8s_node"},
{"k8s_node", "gce_instance"},
{"k8s_node", "aws_ec2_instance"},
{"apigee.googleapis.com/ProxyV2", "k8s_container"},
{"apigee.googleapis.com/Proxy", "k8s_container"},
{"apigee.googleapis.com/Devapp", "k8s_container"},
}
Expand Down

0 comments on commit 8067923

Please sign in to comment.