aligning function name and log message to the official product name (#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
33a1e118e1/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"
This commit is contained in:
Yoshi Yamaguchi 2019-06-13 15:46:33 +08:00 committed by Ahmet Alp Balkan
parent dc98b16a4d
commit 1c057fcbd8
5 changed files with 35 additions and 35 deletions

View file

@ -214,7 +214,7 @@ public final class AdService {
} }
private static void initStackdriver() { private static void initStackdriver() {
logger.info("Initialize StackDriver"); logger.info("Initialize Stackdriver");
long sleepTime = 10; /* seconds */ long sleepTime = 10; /* seconds */
int maxAttempts = 5; int maxAttempts = 5;
@ -252,7 +252,7 @@ public final class AdService {
} }
} }
} }
logger.info("StackDriver initialization complete."); logger.info("Stackdriver initialization complete.");
} }
private static void initJaeger() { private static void initJaeger() {

View file

@ -131,7 +131,7 @@ func initStats(exporter *stackdriver.Exporter) {
} }
} }
func initStackDriverTracing() { func initStackdriverTracing() {
// 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++ {
@ -140,22 +140,22 @@ func initStackDriverTracing() {
log.Infof("failed to initialize stackdriver exporter: %+v", err) log.Infof("failed to initialize stackdriver exporter: %+v", err)
} else { } else {
trace.RegisterExporter(exporter) trace.RegisterExporter(exporter)
log.Info("registered stackdriver tracing") log.Info("registered Stackdriver tracing")
// Register the views to collect server stats. // Register the views to collect server stats.
initStats(exporter) initStats(exporter)
return return
} }
d := time.Second * 10 * time.Duration(i) 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) 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() { func initTracing() {
initJaegerTracing() initJaegerTracing()
initStackDriverTracing() initStackdriverTracing()
} }
func initProfiling(service, version string) { func initProfiling(service, version string) {
@ -170,14 +170,14 @@ func initProfiling(service, version string) {
}); err != nil { }); err != nil {
log.Warnf("failed to start profiler: %+v", err) log.Warnf("failed to start profiler: %+v", err)
} else { } else {
log.Info("started stackdriver profiler") log.Info("started Stackdriver profiler")
return return
} }
d := time.Second * 10 * time.Duration(i) 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) 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) { func mustMapEnv(target *string, envKey string) {

View file

@ -191,20 +191,20 @@ func initStackdriverTracing(log logrus.FieldLogger) {
// log.Warnf is used since there are multiple backends (stackdriver & jaeger) // 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. // to store the traces. In production setup most likely you would use only one backend.
// In that case you should use log.Fatalf. // 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 { } else {
trace.RegisterExporter(exporter) trace.RegisterExporter(exporter)
log.Info("registered stackdriver tracing") log.Info("registered Stackdriver tracing")
// Register the views to collect server stats. // Register the views to collect server stats.
initStats(log, exporter) initStats(log, exporter)
return return
} }
d := time.Second * 20 * time.Duration(i) 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) 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) { func initTracing(log logrus.FieldLogger) {
@ -232,14 +232,14 @@ func initProfiling(log logrus.FieldLogger, service, version string) {
}); err != nil { }); err != nil {
log.Warnf("warn: failed to start profiler: %+v", err) log.Warnf("warn: failed to start profiler: %+v", err)
} else { } else {
log.Info("started stackdriver profiler") log.Info("started Stackdriver profiler")
return return
} }
d := time.Second * 10 * time.Duration(i) 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) 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) { func mustMapEnv(target *string, envKey string) {

View file

@ -158,32 +158,32 @@ func initStats(exporter *stackdriver.Exporter) {
} }
} }
func initStackDriverTracing() { func initStackdriverTracing() {
// 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++ {
exporter, err := stackdriver.NewExporter(stackdriver.Options{}) exporter, err := stackdriver.NewExporter(stackdriver.Options{})
if err != nil { if err != nil {
log.Warnf("failed to initialize stackdriver exporter: %+v", err) log.Warnf("failed to initialize Stackdriver exporter: %+v", err)
} else { } else {
trace.RegisterExporter(exporter) trace.RegisterExporter(exporter)
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
log.Info("registered stackdriver tracing") log.Info("registered Stackdriver tracing")
// Register the views to collect server stats. // Register the views to collect server stats.
initStats(exporter) initStats(exporter)
return return
} }
d := time.Second * 10 * time.Duration(i) 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) 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() { func initTracing() {
initJaegerTracing() initJaegerTracing()
initStackDriverTracing() initStackdriverTracing()
} }
func initProfiling(service, version string) { func initProfiling(service, version string) {
@ -198,14 +198,14 @@ func initProfiling(service, version string) {
}); err != nil { }); err != nil {
log.Warnf("failed to start profiler: %+v", err) log.Warnf("failed to start profiler: %+v", err)
} else { } else {
log.Info("started stackdriver profiler") log.Info("started Stackdriver profiler")
return return
} }
d := time.Second * 10 * time.Duration(i) 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) 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{} type productCatalog struct{}

View file

@ -161,32 +161,32 @@ func initStats(exporter *stackdriver.Exporter) {
} }
} }
func initStackDriverTracing() { func initStackdriverTracing() {
// 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++ {
exporter, err := stackdriver.NewExporter(stackdriver.Options{}) exporter, err := stackdriver.NewExporter(stackdriver.Options{})
if err != nil { if err != nil {
log.Warnf("failed to initialize stackdriver exporter: %+v", err) log.Warnf("failed to initialize Stackdriver exporter: %+v", err)
} else { } else {
trace.RegisterExporter(exporter) trace.RegisterExporter(exporter)
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
log.Info("registered stackdriver tracing") log.Info("registered Stackdriver tracing")
// Register the views to collect server stats. // Register the views to collect server stats.
initStats(exporter) initStats(exporter)
return return
} }
d := time.Second * 10 * time.Duration(i) 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) 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() { func initTracing() {
initJaegerTracing() initJaegerTracing()
initStackDriverTracing() initStackdriverTracing()
} }
func initProfiling(service, version string) { func initProfiling(service, version string) {
@ -201,12 +201,12 @@ func initProfiling(service, version string) {
}); err != nil { }); err != nil {
log.Warnf("failed to start profiler: %+v", err) log.Warnf("failed to start profiler: %+v", err)
} else { } else {
log.Info("started stackdriver profiler") log.Info("started Stackdriver profiler")
return return
} }
d := time.Second * 10 * time.Duration(i) 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) 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")
} }