Skip to content

Commit

Permalink
Added support for AWS EC2 instance monitored resources. (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkohen authored Aug 20, 2018
1 parent 08d8b23 commit 5bf957c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions retrieval/resource_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ type ResourceMap struct {
LabelMap map[string]labelTranslation
}

var EC2ResourceMap = ResourceMap{
Type: "aws_ec2_instance",
LabelMap: map[string]labelTranslation{
ProjectIDLabel: constValue("project_id"),
"__meta_ec2_instance_id": constValue("instance_id"),
"__meta_ec2_availability_zone": labelTranslation{
stackdriverLabelName: "region",
convert: func(s string) string {
return "aws:" + s
},
},
"__meta_ec2_owner_id": constValue("aws_account"),
},
}

var GCEResourceMap = ResourceMap{
Type: "gce_instance",
LabelMap: map[string]labelTranslation{
Expand Down Expand Up @@ -96,6 +111,7 @@ var ResourceMappings = []ResourceMap{
"__meta_kubernetes_node_name": constValue("node_name"),
},
},
EC2ResourceMap,
GCEResourceMap,
}

Expand Down
20 changes: 20 additions & 0 deletions retrieval/resource_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ func TestTranslate(t *testing.T) {
}
}

func TestTranslateEc2Instance(t *testing.T) {
target := labels.Labels{
{ProjectIDLabel, "my-project"},
{"__meta_ec2_availability_zone", "us-east-1b"},
{"__meta_ec2_instance_id", "i-040c37401c02cb03b"},
{"__meta_ec2_owner_id", "12345678"},
}
expectedLabels := map[string]string{
"project_id": "my-project",
"instance_id": "i-040c37401c02cb03b",
"region": "aws:us-east-1b",
"aws_account": "12345678",
}
if labels := EC2ResourceMap.Translate(target); labels == nil {
t.Errorf("Expected %v, actual nil", expectedLabels)
} else if !reflect.DeepEqual(labels, expectedLabels) {
t.Errorf("Expected %v, actual %v", expectedLabels, labels)
}
}

func TestTranslateGceInstance(t *testing.T) {
target := labels.Labels{
{"__meta_gce_project", "my-project"},
Expand Down

0 comments on commit 5bf957c

Please sign in to comment.