shippingservice: prevent crash on profiler init
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
71c47b0869
commit
0a1054c75d
2 changed files with 6 additions and 15 deletions
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
@ -68,7 +67,7 @@ func main() {
|
||||||
log.Level = logrus.DebugLevel
|
log.Level = logrus.DebugLevel
|
||||||
log.Formatter = &logrus.TextFormatter{}
|
log.Formatter = &logrus.TextFormatter{}
|
||||||
|
|
||||||
go initProfiling("frontend", "1.0.0")
|
go initProfiling(log, "frontend", "1.0.0")
|
||||||
go initTracing(log)
|
go initTracing(log)
|
||||||
|
|
||||||
srvPort := port
|
srvPort := port
|
||||||
|
@ -134,23 +133,24 @@ func initTracing(log logrus.FieldLogger) {
|
||||||
log.Warn("could not initialize stackdriver exporter after retrying, giving up")
|
log.Warn("could not initialize stackdriver exporter after retrying, giving up")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initProfiling(service, version string) {
|
func initProfiling(log logrus.FieldLogger, service, version string) {
|
||||||
// TODO(ahmetb) this method is duplicated in other microservices using Go
|
// TODO(ahmetb) this method is duplicated in other microservices using Go
|
||||||
// since they are not sharing packages.
|
// since they are not sharing packages.
|
||||||
for i := 1; i <= 3; i++ {
|
for i := 1; i <= 3; i++ {
|
||||||
|
log = log.WithField("retry", i)
|
||||||
if err := profiler.Start(profiler.Config{
|
if err := profiler.Start(profiler.Config{
|
||||||
Service: service,
|
Service: service,
|
||||||
ServiceVersion: version,
|
ServiceVersion: version,
|
||||||
// ProjectID must be set if not running on GCP.
|
// ProjectID must be set if not running on GCP.
|
||||||
// ProjectID: "my-project",
|
// ProjectID: "my-project",
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Printf("warn: failed to start profiler: %+v", err)
|
log.Warnf("warn: failed to start profiler: %+v", err)
|
||||||
}
|
}
|
||||||
d := time.Second * 10 * time.Duration(i)
|
d := time.Second * 10 * time.Duration(i)
|
||||||
log.Printf("sleeping %v to retry initializing stackdriver profiler", d)
|
log.Debugf("sleeping %v to retry initializing stackdriver profiler", d)
|
||||||
time.Sleep(d)
|
time.Sleep(d)
|
||||||
}
|
}
|
||||||
log.Printf("warning: could not initialize stackdriver profiler after retrying, giving up")
|
log.Warn("warning: could not initialize stackdriver profiler after retrying, giving up")
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustMapEnv(target *string, envKey string) {
|
func mustMapEnv(target *string, envKey string) {
|
||||||
|
|
|
@ -32,15 +32,6 @@ func main() {
|
||||||
}
|
}
|
||||||
port = fmt.Sprintf(":%s", port)
|
port = fmt.Sprintf(":%s", port)
|
||||||
|
|
||||||
if err := profiler.Start(profiler.Config{
|
|
||||||
Service: "shippingservice",
|
|
||||||
ServiceVersion: "1.0.0",
|
|
||||||
// ProjectID must be set if not running on GCP.
|
|
||||||
// ProjectID: "my-project",
|
|
||||||
}); err != nil {
|
|
||||||
log.Fatalf("failed to start profiler: %+v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
lis, err := net.Listen("tcp", port)
|
lis, err := net.Listen("tcp", port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to listen: %v", err)
|
log.Fatalf("failed to listen: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue