GoogleCloudPlatform / golang-samples

Sample apps and code written for Google Cloud in the Go programming language.
Apache License 2.0
4.32k stars 1.75k forks source link

CloudProfiler: Labels is always null in matadata.csv #4323

Open s4s7 opened 3 months ago

s4s7 commented 3 months ago

In which file did you encounter the issue?

https://github.com/GoogleCloudPlatform/golang-samples/blob/66fabfc8f7e333f244e80e811c0110f4647d1316/profiler/export/main.go#L104

Did you change the file? If so, how?

To fill Labels value in matadata.csv

Before:

labelBytes, err := json.Marshal(profile.Labels)

After:

labelBytes, err := json.Marshal(profile.Deployment.Labels)

To make label data more readable:

Before:

err = writer.Write([]string{filename, profile.Name, profile.Deployment.Target, profile.Duration.String(), string(labelBytes)})

After:

err = writer.Write([]string{filename, profile.Name, profile.Deployment.Target, profile.Duration.String(), strings.ReplaceAll(string(labelBytes), `"`, ``)})

Describe the issue

Before: Output results of the metadata.csv

Labels is always null in my environment.

File,Name,ProfileType,Target,Duration,Labels
profiles_1723995611/profile000001.pb.gz,,api,,null
profiles_1723995611/profile000002.pb.gz,,api,,null
profiles_1723995611/profile000003.pb.gz,,api,,null
profiles_1723995611/profile000004.pb.gz,,api,,null
profiles_1723995611/profile000005.pb.gz,,api,,null

After: Output results of the metadata.csv

File,Name,ProfileType,Target,Duration,Labels
profiles_1723998663/profile000001.pb.gz,,api,,"{language:go,version:v1.0.6,zone:asia-northeast1-1}"
profiles_1723998663/profile000002.pb.gz,,api,,"{language:go,version:v1.0.6,zone:asia-northeast1-1}"
profiles_1723998663/profile000003.pb.gz,,api,,"{language:go,version:v1.0.6,zone:asia-northeast1-1}"
profiles_1723998663/profile000004.pb.gz,,api,,"{language:go,version:v1.0.6,zone:asia-northeast1-1}"
profiles_1723998663/profile000005.pb.gz,,api,,"{language:go,version:v1.0.6,zone:asia-northeast1-1}"

how do you think ?