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 0e4e868
Show file tree
Hide file tree
Showing 2 changed files with 53 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 AggregatedProxyResourceMap = ResourceMap{
Type: "apigee.googleapis.com/ProxyV2",
MatchLabel: "__meta_kubernetes_pod_label_type_aggregate_proxy",
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{
AggregatedProxyResourceMap,
ProxyResourceMap,
DevappResourceMap,
{
Expand Down
38 changes: 38 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 TestTranslateAggregateProxy(t *testing.T) {
discoveredLabels := labels.Labels{
{"__meta_kubernetes_pod_label_type_aggregate_proxy", "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 := AggregatedProxyResourceMap.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

0 comments on commit 0e4e868

Please sign in to comment.