Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Allow exporting metrics with resource gae_instance. #253

Merged
merged 3 commits into from
Feb 20, 2020
Merged
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
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"