satellite/api;repair: Have monkit pick the hostname as it's unique identifier

https://storjlabs.atlassian.net/browse/SM-157

Change-Id: If91c5a41234fac5ee93b151fc6799c07e0250239
This commit is contained in:
Ethan 2020-02-18 11:16:51 -05:00 committed by Ethan Adams
parent e6da8d0249
commit 154ebdea69
3 changed files with 16 additions and 2 deletions

View File

@ -79,7 +79,7 @@ func cmdAPIRun(cmd *cobra.Command, args []string) (err error) {
return err
}
if err := process.InitMetricsWithCertPath(ctx, log, nil, runCfg.Identity.CertPath); err != nil {
if err := process.InitMetricsWithHostname(ctx, log, nil); err != nil {
zap.S().Warn("Failed to initialize telemetry batcher on satellite api: ", err)
}

View File

@ -80,7 +80,7 @@ func cmdRepairerRun(cmd *cobra.Command, args []string) (err error) {
return err
}
if err := process.InitMetricsWithCertPath(ctx, log, nil, runCfg.Identity.CertPath); err != nil {
if err := process.InitMetricsWithHostname(ctx, log, nil); err != nil {
zap.S().Warn("Failed to initialize telemetry batcher on repairer: ", err)
}

View File

@ -8,6 +8,7 @@ import (
"flag"
"os"
"path/filepath"
"strings"
hw "github.com/jtolds/monkit-hw/v2"
"github.com/spacemonkeygo/monkit/v3"
@ -90,3 +91,16 @@ func InitMetricsWithCertPath(ctx context.Context, log *zap.Logger, r *monkit.Reg
}
return InitMetrics(ctx, log, r, metricsID)
}
// InitMetricsWithHostname initializes telemetry reporting, using the hostname as the telemetry instance ID.
func InitMetricsWithHostname(ctx context.Context, log *zap.Logger, r *monkit.Registry) error {
var metricsID string
hostname, err := os.Hostname()
if err != nil {
log.Sugar().Errorf("Could not read hostname for telemetry setup: %v", err)
metricsID = "" // InitMetrics() will fill in a default value
} else {
metricsID = strings.ReplaceAll(hostname, ".", "_")
}
return InitMetrics(ctx, log, r, metricsID)
}