Skip to content

Commit adcf43c

Browse files
authored
Add AnthosL4LB resource map (#246)
1 parent ecaede8 commit adcf43c

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

retrieval/resource_map.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,23 @@ var ProxyV2ResourceMap = ResourceMap{
131131
},
132132
}
133133

134+
var AnthosL4LBMap = ResourceMap{
135+
Type: "anthos_l4lb",
136+
MatchLabel: "__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_type",
137+
LabelMap: map[string]labelTranslation{
138+
ProjectIDLabel: constValue("project_id"),
139+
KubernetesLocationLabel: constValue("location"),
140+
"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_kind": constValue("kind"),
141+
"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_group_name": constValue("group_name"),
142+
"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_hostname": constValue("hostname"),
143+
},
144+
}
145+
134146
type ResourceMapList []ResourceMap
135147

136148
// When you add new elements, you also probably want to update TestResourceMappingsOrder.
137149
var ResourceMappings = ResourceMapList{
150+
AnthosL4LBMap,
138151
ProxyV2ResourceMap,
139152
ProxyResourceMap,
140153
DevappResourceMap,

retrieval/resource_map_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,46 @@ func TestTranslateProxyV2(t *testing.T) {
243243
}
244244
}
245245

246+
func TestTranslateAnthosL4LB(t *testing.T) {
247+
discoveredLabels := labels.Labels{
248+
{ProjectIDLabel, "my-project"},
249+
{KubernetesLocationLabel, "my-location"},
250+
{"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_type", "true"},
251+
{"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_kind", "my-kind"},
252+
{"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_group_name", "my-group-name"},
253+
{"__meta_kubernetes_service_annotation_gke_googleapis_com_anthos_l4lb_hostname", "my-hostname"},
254+
{"__meta_kubernetes_namespace", "my-namespace"},
255+
{"__meta_kubernetes_node_name", "my-instance"},
256+
{"__meta_kubernetes_pod_name", "my-pod"},
257+
{"__meta_kubernetes_pod_container_name", "my-container"},
258+
}
259+
metricsLabels := labels.Labels{
260+
{"label_name1", "label1"},
261+
{"label_name2", "label2"},
262+
}
263+
expectedLabels := map[string]string{
264+
"project_id": "my-project",
265+
"location": "my-location",
266+
"kind": "my-kind",
267+
"group_name": "my-group-name",
268+
"hostname": "my-hostname",
269+
}
270+
expectedFinalLabels := labels.Labels{
271+
{"label_name1", "label1"},
272+
{"label_name2", "label2"},
273+
}
274+
if labels, finalLabels := AnthosL4LBMap.Translate(discoveredLabels, metricsLabels); labels == nil {
275+
t.Errorf("Expected %v, actual nil", expectedLabels)
276+
} else {
277+
if diff := cmp.Diff(expectedLabels, labels); len(diff) > 0 {
278+
t.Error(diff)
279+
}
280+
if diff := cmp.Diff(expectedFinalLabels, finalLabels); len(diff) > 0 {
281+
t.Error(diff)
282+
}
283+
}
284+
}
285+
246286
func (m *ResourceMapList) getByType(t string) (*ResourceMap, bool) {
247287
for _, m := range *m {
248288
if m.Type == t {
@@ -274,6 +314,7 @@ func TestResourceMappingsOrder(t *testing.T) {
274314
{"k8s_pod", "k8s_node"},
275315
{"k8s_node", "gce_instance"},
276316
{"k8s_node", "aws_ec2_instance"},
317+
{"anthos_l4lb", "k8s_container"},
277318
{"apigee.googleapis.com/ProxyV2", "k8s_container"},
278319
{"apigee.googleapis.com/Proxy", "k8s_container"},
279320
{"apigee.googleapis.com/Devapp", "k8s_container"},

0 commit comments

Comments
 (0)