Skip to content

Commit

Permalink
aligning function name and log message to the official product name (G…
Browse files Browse the repository at this point in the history
…oogleCloudPlatform#229)

* log: change log format to JSON payload for better log in Stackdriver

change the log format in Go written service from text payload to
JSON payload using 3rd party logging library (logrus).

https://cloud.google.com/logging/docs/structured-logging
https://github.com/sirupsen/logrus/blob/33a1e118e113c7d1dd24a80f80670864cd598519/json_formatter.go#L40-L49

Effected services are frontend, productcatalogservice, checkoutservice,
and shippinservice.

Also change target container registry and locust scenario for testing.

* revert kubernetes manifests to point to the original container registry URLs

* revert skaffold.yaml to point to the original registry

* loadgenerator: revert locust settings

* align all function names and messages to the official product name "Stackdriver"
  • Loading branch information
ymotongpoo authored and ahmetb committed Jun 13, 2019
1 parent dc98b16 commit 1c057fc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/adservice/src/main/java/hipstershop/AdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private static ImmutableListMultimap<String, Ad> createAdsMap() {
}

private static void initStackdriver() {
logger.info("Initialize StackDriver");
logger.info("Initialize Stackdriver");

long sleepTime = 10; /* seconds */
int maxAttempts = 5;
Expand Down Expand Up @@ -252,7 +252,7 @@ private static void initStackdriver() {
}
}
}
logger.info("StackDriver initialization complete.");
logger.info("Stackdriver initialization complete.");
}

private static void initJaeger() {
Expand Down
16 changes: 8 additions & 8 deletions src/checkoutservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func initStats(exporter *stackdriver.Exporter) {
}
}

func initStackDriverTracing() {
func initStackdriverTracing() {
// TODO(ahmetb) this method is duplicated in other microservices using Go
// since they are not sharing packages.
for i := 1; i <= 3; i++ {
Expand All @@ -140,22 +140,22 @@ func initStackDriverTracing() {
log.Infof("failed to initialize stackdriver exporter: %+v", err)
} else {
trace.RegisterExporter(exporter)
log.Info("registered stackdriver tracing")
log.Info("registered Stackdriver tracing")

// Register the views to collect server stats.
initStats(exporter)
return
}
d := time.Second * 10 * time.Duration(i)
log.Infof("sleeping %v to retry initializing stackdriver exporter", d)
log.Infof("sleeping %v to retry initializing Stackdriver exporter", d)
time.Sleep(d)
}
log.Warn("could not initialize stackdriver exporter after retrying, giving up")
log.Warn("could not initialize Stackdriver exporter after retrying, giving up")
}

func initTracing() {
initJaegerTracing()
initStackDriverTracing()
initStackdriverTracing()
}

func initProfiling(service, version string) {
Expand All @@ -170,14 +170,14 @@ func initProfiling(service, version string) {
}); err != nil {
log.Warnf("failed to start profiler: %+v", err)
} else {
log.Info("started stackdriver profiler")
log.Info("started Stackdriver profiler")
return
}
d := time.Second * 10 * time.Duration(i)
log.Infof("sleeping %v to retry initializing stackdriver profiler", d)
log.Infof("sleeping %v to retry initializing Stackdriver profiler", d)
time.Sleep(d)
}
log.Warn("could not initialize stackdriver profiler after retrying, giving up")
log.Warn("could not initialize Stackdriver profiler after retrying, giving up")
}

func mustMapEnv(target *string, envKey string) {
Expand Down
14 changes: 7 additions & 7 deletions src/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,20 @@ func initStackdriverTracing(log logrus.FieldLogger) {
// log.Warnf is used since there are multiple backends (stackdriver & jaeger)
// to store the traces. In production setup most likely you would use only one backend.
// In that case you should use log.Fatalf.
log.Warnf("failed to initialize stackdriver exporter: %+v", err)
log.Warnf("failed to initialize Stackdriver exporter: %+v", err)
} else {
trace.RegisterExporter(exporter)
log.Info("registered stackdriver tracing")
log.Info("registered Stackdriver tracing")

// Register the views to collect server stats.
initStats(log, exporter)
return
}
d := time.Second * 20 * time.Duration(i)
log.Debugf("sleeping %v to retry initializing stackdriver exporter", d)
log.Debugf("sleeping %v to retry initializing Stackdriver exporter", d)
time.Sleep(d)
}
log.Warn("could not initialize stackdriver exporter after retrying, giving up")
log.Warn("could not initialize Stackdriver exporter after retrying, giving up")
}

func initTracing(log logrus.FieldLogger) {
Expand Down Expand Up @@ -232,14 +232,14 @@ func initProfiling(log logrus.FieldLogger, service, version string) {
}); err != nil {
log.Warnf("warn: failed to start profiler: %+v", err)
} else {
log.Info("started stackdriver profiler")
log.Info("started Stackdriver profiler")
return
}
d := time.Second * 10 * time.Duration(i)
log.Debugf("sleeping %v to retry initializing stackdriver profiler", d)
log.Debugf("sleeping %v to retry initializing Stackdriver profiler", d)
time.Sleep(d)
}
log.Warn("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) {
Expand Down
18 changes: 9 additions & 9 deletions src/productcatalogservice/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,32 @@ func initStats(exporter *stackdriver.Exporter) {
}
}

func initStackDriverTracing() {
func initStackdriverTracing() {
// TODO(ahmetb) this method is duplicated in other microservices using Go
// since they are not sharing packages.
for i := 1; i <= 3; i++ {
exporter, err := stackdriver.NewExporter(stackdriver.Options{})
if err != nil {
log.Warnf("failed to initialize stackdriver exporter: %+v", err)
log.Warnf("failed to initialize Stackdriver exporter: %+v", err)
} else {
trace.RegisterExporter(exporter)
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
log.Info("registered stackdriver tracing")
log.Info("registered Stackdriver tracing")

// Register the views to collect server stats.
initStats(exporter)
return
}
d := time.Second * 10 * time.Duration(i)
log.Infof("sleeping %v to retry initializing stackdriver exporter", d)
log.Infof("sleeping %v to retry initializing Stackdriver exporter", d)
time.Sleep(d)
}
log.Warn("could not initialize stackdriver exporter after retrying, giving up")
log.Warn("could not initialize Stackdriver exporter after retrying, giving up")
}

func initTracing() {
initJaegerTracing()
initStackDriverTracing()
initStackdriverTracing()
}

func initProfiling(service, version string) {
Expand All @@ -198,14 +198,14 @@ func initProfiling(service, version string) {
}); err != nil {
log.Warnf("failed to start profiler: %+v", err)
} else {
log.Info("started stackdriver profiler")
log.Info("started Stackdriver profiler")
return
}
d := time.Second * 10 * time.Duration(i)
log.Infof("sleeping %v to retry initializing stackdriver profiler", d)
log.Infof("sleeping %v to retry initializing Stackdriver profiler", d)
time.Sleep(d)
}
log.Warn("could not initialize stackdriver profiler after retrying, giving up")
log.Warn("could not initialize Stackdriver profiler after retrying, giving up")
}

type productCatalog struct{}
Expand Down
18 changes: 9 additions & 9 deletions src/shippingservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,32 +161,32 @@ func initStats(exporter *stackdriver.Exporter) {
}
}

func initStackDriverTracing() {
func initStackdriverTracing() {
// TODO(ahmetb) this method is duplicated in other microservices using Go
// since they are not sharing packages.
for i := 1; i <= 3; i++ {
exporter, err := stackdriver.NewExporter(stackdriver.Options{})
if err != nil {
log.Warnf("failed to initialize stackdriver exporter: %+v", err)
log.Warnf("failed to initialize Stackdriver exporter: %+v", err)
} else {
trace.RegisterExporter(exporter)
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
log.Info("registered stackdriver tracing")
log.Info("registered Stackdriver tracing")

// Register the views to collect server stats.
initStats(exporter)
return
}
d := time.Second * 10 * time.Duration(i)
log.Infof("sleeping %v to retry initializing stackdriver exporter", d)
log.Infof("sleeping %v to retry initializing Stackdriver exporter", d)
time.Sleep(d)
}
log.Warn("could not initialize stackdriver exporter after retrying, giving up")
log.Warn("could not initialize Stackdriver exporter after retrying, giving up")
}

func initTracing() {
initJaegerTracing()
initStackDriverTracing()
initStackdriverTracing()
}

func initProfiling(service, version string) {
Expand All @@ -201,12 +201,12 @@ func initProfiling(service, version string) {
}); err != nil {
log.Warnf("failed to start profiler: %+v", err)
} else {
log.Info("started stackdriver profiler")
log.Info("started Stackdriver profiler")
return
}
d := time.Second * 10 * time.Duration(i)
log.Infof("sleeping %v to retry initializing stackdriver profiler", d)
log.Infof("sleeping %v to retry initializing Stackdriver profiler", d)
time.Sleep(d)
}
log.Warn("could not initialize stackdriver profiler after retrying, giving up")
log.Warn("could not initialize Stackdriver profiler after retrying, giving up")
}

0 comments on commit 1c057fc

Please sign in to comment.