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

Commit 1d104f7

Browse files
authored
Allow exporting metrics with resource gae_instance. (#253)
* Allow exporting metrics with resource gae_instance. * Add gae_instance resources to testdata for metrics_proto_api_test.
1 parent f86b8f1 commit 1d104f7

6 files changed

Lines changed: 97 additions & 2 deletions

File tree

resource.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const (
4040
knativeRevisionName = "revision_name"
4141
knativeConfigurationName = "configuration_name"
4242
knativeNamespaceName = "namespace_name"
43+
44+
appEngineInstanceType = "gae_instance"
45+
46+
appEngineService = "appengine.service.id"
47+
appEngineVersion = "appengine.version.id"
48+
appEngineInstance = "appengine.instance.id"
4349
)
4450

4551
var (
@@ -100,6 +106,14 @@ var awsResourceMap = map[string]string{
100106
"aws_account": resourcekeys.CloudKeyAccountID,
101107
}
102108

109+
var appEngineInstanceMap = map[string]string{
110+
"project_id": stackdriverProjectID,
111+
"location": resourcekeys.CloudKeyRegion,
112+
"module_id": appEngineService,
113+
"version_id": appEngineVersion,
114+
"instance_id": appEngineInstance,
115+
}
116+
103117
// Generic task resource.
104118
var genericResourceMap = map[string]string{
105119
"project_id": stackdriverProjectID,
@@ -186,6 +200,9 @@ func defaultMapResource(res *resource.Resource) *monitoredrespb.MonitoredResourc
186200
case res.Type == resourcekeys.HostType && res.Labels[resourcekeys.K8SKeyClusterName] != "":
187201
result.Type = "k8s_node"
188202
match = k8sNodeMap
203+
case res.Type == appEngineInstanceType:
204+
result.Type = appEngineInstanceType
205+
match = appEngineInstanceMap
189206
case res.Labels[resourcekeys.CloudKeyProvider] == resourcekeys.CloudProviderGCP:
190207
result.Type = "gce_instance"
191208
match = gcpResourceMap

resource_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,29 @@ func TestDefaultMapResource(t *testing.T) {
238238
},
239239
},
240240
},
241+
// Convert to App Engine Instance.
242+
{
243+
input: &resource.Resource{
244+
Type: appEngineInstanceType,
245+
Labels: map[string]string{
246+
stackdriverProjectID: "proj1",
247+
resourcekeys.CloudKeyRegion: "region1",
248+
appEngineService: "default",
249+
appEngineVersion: "version1",
250+
appEngineInstance: "inst1",
251+
},
252+
},
253+
want: &monitoredrespb.MonitoredResource{
254+
Type: "gae_instance",
255+
Labels: map[string]string{
256+
"project_id": "proj1",
257+
"location": "region1",
258+
"module_id": "default",
259+
"version_id": "version1",
260+
"instance_id": "inst1",
261+
},
262+
},
263+
},
241264
// Convert to Global.
242265
{
243266
input: &resource.Resource{

testdata/Resources/in.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,21 @@ labels: <
121121
key: "k8s.pod.name"
122122
value: "pod1"
123123
>
124+
---
125+
type: "gae_instance"
126+
labels: <
127+
key: "appengine.service.id"
128+
value: "default"
129+
>
130+
labels: <
131+
key: "appengine.version.id"
132+
value: "version1"
133+
>
134+
labels: <
135+
key: "appengine.instance.id"
136+
value: "inst1"
137+
>
138+
labels: <
139+
key: "cloud.region"
140+
value: "region1"
141+
>

testdata/Resources/out.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,21 @@ labels: <
7777
>
7878
---
7979
type: "global"
80-
80+
---
81+
type: "gae_instance"
82+
labels: <
83+
key: "module_id"
84+
value: "default"
85+
>
86+
labels: <
87+
key: "version_id"
88+
value: "version1"
89+
>
90+
labels: <
91+
key: "instance_id"
92+
value: "inst1"
93+
>
94+
labels: <
95+
key: "location"
96+
value: "region1"
97+
>

testdata/ResourcesWithMissingFields/in.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,22 @@ labels: <
121121
key: "k8s.pod.name"
122122
value: "pod1"
123123
>
124+
---
125+
type: "gae_instance"
126+
#labels: <
127+
# key: "appengine.service.id"
128+
# value: "default"
129+
#>
130+
labels: <
131+
key: "appengine.version.id"
132+
value: "version1"
133+
>
134+
labels: <
135+
key: "appengine.instance.id"
136+
value: "inst1"
137+
>
138+
labels: <
139+
key: "cloud.region"
140+
value: "region1"
141+
>
142+

testdata/ResourcesWithMissingFields/out.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ type: "global"
99
type: "global"
1010
---
1111
type: "global"
12-
12+
---
13+
type: "global"

0 commit comments

Comments
 (0)