Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AnthosL4LB monitored resource type #245

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions retrieval/resource_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ var GCEResourceMap = ResourceMap{
},
}

var AnthosL4LBMap = ResourceMap{
Type: "anthos_l4lb",
LabelMap: map[string]labelTranslation{
ProjectIDLabel: constValue("project_id"),
KubernetesLocationLabel: constValue("location"),
"__meta_kubernetes_service_annotation_anthos_l4lb_kind": constValue("kind"),
"__meta_kubernetes_service_annotation_anthos_l4lb_group_name": constValue("group_name"),
"__meta_kubernetes_service_annotation_anthos_l4lb_hostname": constValue("hostname"),
Comment on lines +85 to +87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be run through gofmt again?

},
}

Comment on lines +80 to +90
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you added this here, and not at the end (just before the declaration of ResourceMapList)?

var GKEResourceMap = ResourceMap{
Type: "gke_container",
LabelMap: map[string]labelTranslation{
Expand Down Expand Up @@ -135,6 +146,7 @@ type ResourceMapList []ResourceMap

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

func TestTranslateAnthosL4LB(t *testing.T) {
discoveredLabels := labels.Labels {
{ProjectIDLabel, "my-project"},
{KubernetesLocationLabel, "my-location"},
{"__meta_kubernetes_service_annotation_anthos_l4lb_kind", "my-kind"},
{"__meta_kubernetes_service_annotation_anthos_l4lb_group_name", "my-group-name"},
{"__meta_kubernetes_service_annotation_anthos_l4lb_hostname", "my-hostname"},
{"__meta_kubernetes_namespace", "my-namespace"},
{"__meta_kubernetes_node_name", "my-instance"},
{"__meta_kubernetes_pod_name", "my-pod"},
{"__meta_kubernetes_pod_container_name", "my-container"},
}
metricsLabels := labels.Labels {
{"label_name1", "label1"},
{"label_name2", "label2"},
}
expectedLabels := map[string]string {
"project_id": "my-project",
"location": "my-location",
"kind": "my-kind",
"group_name": "my-group-name",
"hostname": "my-hostname",
}
expectedFinalLabels := labels.Labels {
{"label_name1", "label1"},
{"label_name2", "label2"},
}
if labels, finalLabels := AnthosL4LBMap.Translate(discoveredLabels, metricsLabels); 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 @@ -274,6 +313,7 @@ func TestResourceMappingsOrder(t *testing.T) {
{"k8s_pod", "k8s_node"},
{"k8s_node", "gce_instance"},
{"k8s_node", "aws_ec2_instance"},
{"anthos_l4lb", "k8s_container"},
{"apigee.googleapis.com/ProxyV2", "k8s_container"},
{"apigee.googleapis.com/Proxy", "k8s_container"},
{"apigee.googleapis.com/Devapp", "k8s_container"},
Expand Down
Loading