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

Commit 5b851ab

Browse files
authored
Use generic_task resource type when all generic labels are present (#286)
While converting an ocagent resource to a cloud resource, stackdriver exporter looks for a set of labels that apply to a generic_task resource: https://cloud.google.com/monitoring/api/resources#tag_generic_task However, if it doesn't find one of the labels, it falls back to "global" resource with just the project id label, and it works OK. But if it does find all of the labels, it will attach them to the exported resource, and Cloud API fails with "Unrecognized resource label" error, because those labels do not exist on a "global" resource. This change replaces use of global resource with generic resource throughout stackdriver exporter code.
1 parent f81d98c commit 5b851ab

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

resource.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,15 @@ func transformResource(match, input map[string]string) (map[string]string, bool)
205205

206206
// DefaultMapResource implements default resource mapping for well-known resource types
207207
func DefaultMapResource(res *resource.Resource) *monitoredrespb.MonitoredResource {
208+
if res == nil || res.Labels == nil {
209+
return &monitoredrespb.MonitoredResource{
210+
Type: "global",
211+
}
212+
}
213+
208214
match := genericResourceMap
209215
result := &monitoredrespb.MonitoredResource{
210-
Type: "global",
211-
}
212-
if res == nil || res.Labels == nil {
213-
return result
216+
Type: "generic_task",
214217
}
215218

216219
switch {

resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func TestDefaultMapResource(t *testing.T) {
276276
},
277277
},
278278
want: &monitoredrespb.MonitoredResource{
279-
Type: "global",
279+
Type: "generic_task",
280280
Labels: map[string]string{
281281
"project_id": "proj1",
282282
"location": "zone1",

0 commit comments

Comments
 (0)