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:
parent
e6da8d0249
commit
154ebdea69
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user