Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logging): allow nil zones in resource autodetection #3997

Merged
merged 2 commits into from May 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion logging/logging.go
Expand Up @@ -404,7 +404,11 @@ func monitoredResource(parent string) *mrpb.MonitoredResource {
}

func regionFromZone(zone string) string {
return zone[:strings.LastIndex(zone, "-")]
cutoff := strings.LastIndex(zone, "-")
if cutoff > 0 {
return zone[:cutoff]
}
return zone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this value is not what is expected should we put zone in at all? Or just ""?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can help out here, in my experience, passing in the values causing this to panic (e.g. us16) will work and be accepted by Cloud Logging. I've been using my own autodetect code to stand up our logging client which does this and have had no issues logging:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should accept any user specified/custom zones. Per user docs:
CommonResource sets the monitored resource associated with all log entries written from a Logger. If not provided, the resource is automatically detected based on the running environment (on GCE, GCR, GCF and GAE Standard only). This value can be overridden per-entry by setting an Entry's Resource field.

}

func globalResource(projectID string) *mrpb.MonitoredResource {
Expand Down