Skip to content

Commit

Permalink
Merge pull request #2 from census-ecosystem/master
Browse files Browse the repository at this point in the history
Allow exporting metrics with resource gae_instance. (census-ecosystem#253)
  • Loading branch information
imccarten1 authored Feb 23, 2020
2 parents 9dfd96d + 1d104f7 commit a219fc8
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
17 changes: 17 additions & 0 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ const (
knativeRevisionName = "revision_name"
knativeConfigurationName = "configuration_name"
knativeNamespaceName = "namespace_name"

appEngineInstanceType = "gae_instance"

appEngineService = "appengine.service.id"
appEngineVersion = "appengine.version.id"
appEngineInstance = "appengine.instance.id"
)

var (
Expand Down Expand Up @@ -100,6 +106,14 @@ var awsResourceMap = map[string]string{
"aws_account": resourcekeys.CloudKeyAccountID,
}

var appEngineInstanceMap = map[string]string{
"project_id": stackdriverProjectID,
"location": resourcekeys.CloudKeyRegion,
"module_id": appEngineService,
"version_id": appEngineVersion,
"instance_id": appEngineInstance,
}

// Generic task resource.
var genericResourceMap = map[string]string{
"project_id": stackdriverProjectID,
Expand Down Expand Up @@ -186,6 +200,9 @@ func defaultMapResource(res *resource.Resource) *monitoredrespb.MonitoredResourc
case res.Type == resourcekeys.HostType && res.Labels[resourcekeys.K8SKeyClusterName] != "":
result.Type = "k8s_node"
match = k8sNodeMap
case res.Type == appEngineInstanceType:
result.Type = appEngineInstanceType
match = appEngineInstanceMap
case res.Labels[resourcekeys.CloudKeyProvider] == resourcekeys.CloudProviderGCP:
result.Type = "gce_instance"
match = gcpResourceMap
Expand Down
23 changes: 23 additions & 0 deletions resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,29 @@ func TestDefaultMapResource(t *testing.T) {
},
},
},
// Convert to App Engine Instance.
{
input: &resource.Resource{
Type: appEngineInstanceType,
Labels: map[string]string{
stackdriverProjectID: "proj1",
resourcekeys.CloudKeyRegion: "region1",
appEngineService: "default",
appEngineVersion: "version1",
appEngineInstance: "inst1",
},
},
want: &monitoredrespb.MonitoredResource{
Type: "gae_instance",
Labels: map[string]string{
"project_id": "proj1",
"location": "region1",
"module_id": "default",
"version_id": "version1",
"instance_id": "inst1",
},
},
},
// Convert to Global.
{
input: &resource.Resource{
Expand Down
18 changes: 18 additions & 0 deletions testdata/Resources/in.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,21 @@ labels: <
key: "k8s.pod.name"
value: "pod1"
>
---
type: "gae_instance"
labels: <
key: "appengine.service.id"
value: "default"
>
labels: <
key: "appengine.version.id"
value: "version1"
>
labels: <
key: "appengine.instance.id"
value: "inst1"
>
labels: <
key: "cloud.region"
value: "region1"
>
19 changes: 18 additions & 1 deletion testdata/Resources/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ labels: <
>
---
type: "global"

---
type: "gae_instance"
labels: <
key: "module_id"
value: "default"
>
labels: <
key: "version_id"
value: "version1"
>
labels: <
key: "instance_id"
value: "inst1"
>
labels: <
key: "location"
value: "region1"
>
19 changes: 19 additions & 0 deletions testdata/ResourcesWithMissingFields/in.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,22 @@ labels: <
key: "k8s.pod.name"
value: "pod1"
>
---
type: "gae_instance"
#labels: <
# key: "appengine.service.id"
# value: "default"
#>
labels: <
key: "appengine.version.id"
value: "version1"
>
labels: <
key: "appengine.instance.id"
value: "inst1"
>
labels: <
key: "cloud.region"
value: "region1"
>

3 changes: 2 additions & 1 deletion testdata/ResourcesWithMissingFields/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type: "global"
type: "global"
---
type: "global"

---
type: "global"

0 comments on commit a219fc8

Please sign in to comment.