Collect the hostname of the machine as a metric.
The hostname is collected during a build to determine where the user
is build from (from office workstation, cloudtop, etc...). This is a
useful metrics for RBE related builds.
Bug: b/169395325
Test: m nothing, ran printproto to verify that soong_metrics has the
hostname.
Change-Id: I3e5d64f948ae43c5dda60de1d4a52b187e36dff8
Merged-In: I3e5d64f948ae43c5dda60de1d4a52b187e36dff8
Merged-In: Ib6898b49c16a830d814efe74581bde463caedf76
diff --git a/ui/metrics/metrics.go b/ui/metrics/metrics.go
index 9929b9e..1d7e00b 100644
--- a/ui/metrics/metrics.go
+++ b/ui/metrics/metrics.go
@@ -141,7 +141,12 @@
}
// exports the output to the file at outputPath
-func (m *Metrics) Dump(outputPath string) (err error) {
+func (m *Metrics) Dump(outputPath string) error {
+ // ignore the error if the hostname could not be retrieved as it
+ // is not a critical metric to extract.
+ if hostname, err := os.Hostname(); err == nil {
+ m.metrics.Hostname = proto.String(hostname)
+ }
m.metrics.HostOs = proto.String(runtime.GOOS)
data, err := m.Serialize()
if err != nil {