Add jaeger export to checkoutservice. (#116)

* Add jaeger export to checkoutservice.

* fix review comments.
This commit is contained in:
rghetia 2019-01-10 10:25:07 -08:00 committed by GitHub
parent 33ca3b63d8
commit 2b074f7ff3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 149 additions and 37 deletions

View file

@ -46,6 +46,8 @@ spec:
value: "currencyservice:7000"
- name: CART_SERVICE_ADDR
value: "cartservice:7070"
# - name: JAEGER_SERVICE_ADDR
# value: "jaeger-collector:14268"
resources:
requests:
cpu: 100m

View file

@ -2,27 +2,49 @@
[[projects]]
digest = "1:467af0aad47996b25b838d6f14c8371123a8a76ec239020a6c5894e1f8f60272"
name = "cloud.google.com/go"
packages = [
"compute/metadata",
"internal/version",
"monitoring/apiv3",
"profiler",
"trace/apiv2"
"trace/apiv2",
]
pruneopts = "UT"
revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad"
version = "v0.27.0"
[[projects]]
digest = "1:4b96dcd8534bc6450a922bd16a76360ba3381f0d1daf40abbaec91c053fbfeb5"
name = "contrib.go.opencensus.io/exporter/stackdriver"
packages = [
".",
"propagation"
]
packages = ["."]
pruneopts = "UT"
revision = "37aa2801fbf0205003e15636096ebf0373510288"
version = "v0.5.0"
[[projects]]
branch = "master"
digest = "1:1d8f3cb93c42c5652bb509fde29ecdd1feede9334e355e8bbdc0f9f95b40c254"
name = "git.apache.org/thrift.git"
packages = ["lib/go/thrift"]
pruneopts = "UT"
revision = "a5df39032ca206e2e6a9ec975147e81746d9a255"
source = "github.com/apache/thrift"
[[projects]]
branch = "master"
digest = "1:f6bdf3d8d3cbb2f98d3ebaa66b3ac25166a06830027ece7d592d9ea09dedf504"
name = "github.com/GoogleCloudPlatform/microservices-demo"
packages = [
"src/checkoutservice/genproto",
"src/checkoutservice/money",
]
pruneopts = "UT"
revision = "33ca3b63d82698035ffc1230dcb650885a005197"
[[projects]]
digest = "1:72856926f8208767b837bf51e3373f49139f61889b67dc7fd3c2a0fd711e3f7a"
name = "github.com/golang/protobuf"
packages = [
"proto",
@ -33,41 +55,62 @@
"ptypes/empty",
"ptypes/struct",
"ptypes/timestamp",
"ptypes/wrappers"
"ptypes/wrappers",
]
pruneopts = "UT"
revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5"
version = "v1.2.0"
[[projects]]
branch = "master"
digest = "1:089d56c0adb79140365b5c86815ce97233986da6f3a525c6b706773e4b83876f"
name = "github.com/google/pprof"
packages = ["profile"]
revision = "e027b505a088ac3c68c339a1d7ce7724bf34538b"
pruneopts = "UT"
revision = "985cf9b4fdd2b479e4563ec57352005f69d5f9f6"
[[projects]]
digest = "1:236d7e1bdb50d8f68559af37dbcf9d142d56b431c9b2176d41e2a009b664cda8"
name = "github.com/google/uuid"
packages = ["."]
revision = "d460ce9f8df2e77fb1ba55ca87fafed96c607494"
version = "v1.0.0"
pruneopts = "UT"
revision = "9b3b1e0f5f99ae461456d768e7d301a7acdaa2d8"
version = "v1.1.0"
[[projects]]
digest = "1:cd9864c6366515827a759931746738ede6079faa08df9c584596370d6add135c"
name = "github.com/googleapis/gax-go"
packages = ["."]
revision = "317e0006254c44a0ac427cc52a0e083ff0b9622f"
version = "v2.0.0"
packages = [
".",
"v2",
]
pruneopts = "UT"
revision = "c8a15bac9b9fe955bd9f900272f9a306465d28cf"
version = "v2.0.3"
[[projects]]
digest = "1:d867dfa6751c8d7a435821ad3b736310c2ed68945d05b50fb9d23aee0540c8cc"
digest = "1:0a69a1c0db3591fcefb47f115b224592c8dfa4368b7ba9fae509d5e16cdc95c8"
name = "github.com/konsorten/go-windows-terminal-sequences"
packages = ["."]
pruneopts = "UT"
revision = "5c8c8bd35d3832f5d134ae1e1e375b69a4d25242"
version = "v1.0.1"
[[projects]]
digest = "1:87c2e02fb01c27060ccc5ba7c5a407cc91147726f8f40b70cceeedbc52b1f3a8"
name = "github.com/sirupsen/logrus"
packages = ["."]
pruneopts = "UT"
revision = "3e01752db0189b9157070a0e1668a620f9a85da2"
version = "v1.0.6"
revision = "e1e72e9de974bd926e5c56f83753fba2df402ce5"
version = "v1.3.0"
[[projects]]
digest = "1:a5154dfd6b37bef5a3eab759e13296348e639dc8c7604f538368167782b08ccd"
name = "go.opencensus.io"
packages = [
".",
"exporter/jaeger",
"exporter/jaeger/internal/gen-go/jaeger",
"internal",
"internal/tagencoding",
"plugin/ocgrpc",
@ -80,21 +123,23 @@
"trace",
"trace/internal",
"trace/propagation",
"trace/tracestate"
"trace/tracestate",
]
pruneopts = "UT"
revision = "b11f239c032624b045c4c2bfd3d1287b4012ce89"
version = "v0.16.0"
[[projects]]
branch = "master"
digest = "1:3f3a05ae0b95893d90b9b3b5afdb79a9b3d96e4e36e099d841ae602e4aca0da8"
digest = "1:38f553aff0273ad6f367cb0a0f8b6eecbaef8dc6cb8b50e57b6a81c1d5b1e332"
name = "golang.org/x/crypto"
packages = ["ssh/terminal"]
pruneopts = "UT"
revision = "0e37d006457bf46f9e6692014ba72ef82c33022c"
revision = "ff983b9c42bc9fbf91556e191cc8efb585c16908"
[[projects]]
branch = "master"
digest = "1:8ecb828bb550a8c6b7d75b8261a42c369461311616ebe5451966d067f5f993bf"
name = "golang.org/x/net"
packages = [
"context",
@ -104,35 +149,46 @@
"http2/hpack",
"idna",
"internal/timeseries",
"trace"
"trace",
]
revision = "26e67e76b6c3f6ce91f7c52def5af501b4e0f3a2"
pruneopts = "UT"
revision = "1e06a53dbb7e2ed46e91183f219db23c6943c532"
[[projects]]
branch = "master"
digest = "1:23443edff0740e348959763085df98400dcfd85528d7771bb0ce9f5f2754ff4a"
name = "golang.org/x/oauth2"
packages = [
".",
"google",
"internal",
"jws",
"jwt"
"jwt",
]
revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9"
pruneopts = "UT"
revision = "d668ce993890a79bda886613ee587a69dd5da7a6"
[[projects]]
branch = "master"
digest = "1:75515eedc0dc2cb0b40372008b616fa2841d831c63eedd403285ff286c593295"
name = "golang.org/x/sync"
packages = ["semaphore"]
revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca"
pruneopts = "UT"
revision = "37e7f081c4d4c64e13b10787722085407fe5d15f"
[[projects]]
branch = "master"
digest = "1:12ef3ef293a3a3930a82e5f38a3c45a1b03a9ed72dedc192d90e89d59b1f13a5"
name = "golang.org/x/sys"
packages = ["unix"]
revision = "1561086e645b2809fb9f8a1e2a38160bf8d53bf4"
packages = [
"unix",
"windows",
]
pruneopts = "UT"
revision = "7fbe1cd0fcc20051e1fcb87fbabec4a1bacaaeba"
[[projects]]
digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18"
name = "golang.org/x/text"
packages = [
"collate",
@ -148,13 +204,15 @@
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable"
"unicode/rangetable",
]
pruneopts = "UT"
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0"
[[projects]]
branch = "master"
digest = "1:b74a0ae8b7755bf9cdadead4dea674d76517cd2fea7bd482a6a46bb6b3ce085b"
name = "google.golang.org/api"
packages = [
"googleapi/transport",
@ -164,11 +222,14 @@
"support/bundler",
"transport",
"transport/grpc",
"transport/http"
"transport/http",
"transport/http/internal/propagation",
]
revision = "19ff8768a5c0b8e46ea281065664787eefc24121"
pruneopts = "UT"
revision = "032faecc3e7e2c445ec37a1b1ec4e5a3016d96f2"
[[projects]]
digest = "1:c4eaa5f79d36f76ef4bd0c4f96e36bc1b7b5a359528d1267f0cb7a5d58b7b5bb"
name = "google.golang.org/appengine"
packages = [
".",
@ -182,13 +243,15 @@
"internal/socket",
"internal/urlfetch",
"socket",
"urlfetch"
"urlfetch",
]
revision = "ae0ab99deb4dc413a2b4bd6c8bdd0eb67f1e4d06"
version = "v1.2.0"
pruneopts = "UT"
revision = "e9657d882bb81064595ca3b56cbe2546bbabf7b1"
version = "v1.4.0"
[[projects]]
branch = "master"
digest = "1:3552e7267a98c605e6cbfe6b03c34589265ab72e6078b95fb2e10e0cb44f5cc8"
name = "google.golang.org/genproto"
packages = [
"googleapis/api/annotations",
@ -201,11 +264,13 @@
"googleapis/monitoring/v3",
"googleapis/rpc/errdetails",
"googleapis/rpc/status",
"protobuf/field_mask"
"protobuf/field_mask",
]
revision = "c3f76f3b92d1ffa4c58a9ff842a58b8877655e0f"
pruneopts = "UT"
revision = "ae2f86662275e140f395167f1dab7081a5bd5fa8"
[[projects]]
digest = "1:6497ab07ec89179db8d5a563d33635be04ceffaa29007a3ae74b9f15f4d3068e"
name = "google.golang.org/grpc"
packages = [
".",
@ -235,14 +300,32 @@
"resolver/passthrough",
"stats",
"status",
"tap"
"tap",
]
pruneopts = "UT"
revision = "32fb0ac620c32ba40a4626ddf94d90d12cce3455"
version = "v1.14.0"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "0c103e5e32d8ecdd70048b6d91e02b910e30bad54f06b230a9664f585433a669"
input-imports = [
"cloud.google.com/go/profiler",
"contrib.go.opencensus.io/exporter/stackdriver",
"github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto",
"github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money",
"github.com/golang/protobuf/proto",
"github.com/google/uuid",
"github.com/sirupsen/logrus",
"go.opencensus.io/exporter/jaeger",
"go.opencensus.io/plugin/ocgrpc",
"go.opencensus.io/stats/view",
"go.opencensus.io/trace",
"golang.org/x/net/context",
"google.golang.org/grpc",
"google.golang.org/grpc/codes",
"google.golang.org/grpc/health/grpc_health_v1",
"google.golang.org/grpc/status",
]
solver-name = "gps-cdcl"
solver-version = 1

View file

@ -25,6 +25,7 @@ import (
"contrib.go.opencensus.io/exporter/stackdriver"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
"go.opencensus.io/exporter/jaeger"
"go.opencensus.io/plugin/ocgrpc"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
@ -98,6 +99,28 @@ func main() {
log.Fatal(err)
}
func initJaegerTracing() {
svcAddr := os.Getenv("JAEGER_SERVICE_ADDR")
if svcAddr == "" {
log.Info("jaeger initialization disabled.")
return
}
// Register the Jaeger exporter to be able to retrieve
// the collected spans.
exporter, err := jaeger.NewExporter(jaeger.Options{
Endpoint: fmt.Sprintf("http://%s", svcAddr),
Process: jaeger.Process{
ServiceName: "checkoutservice",
},
})
if err != nil {
log.Fatal(err)
}
trace.RegisterExporter(exporter)
log.Info("jaeger initialization completed.")
}
func initStats(exporter *stackdriver.Exporter) {
view.SetReportingPeriod(60 * time.Second)
view.RegisterExporter(exporter)
@ -108,7 +131,7 @@ func initStats(exporter *stackdriver.Exporter) {
}
}
func initTracing() {
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++ {
@ -117,7 +140,6 @@ func initTracing() {
log.Infof("failed to initialize stackdriver exporter: %+v", err)
} else {
trace.RegisterExporter(exporter)
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
log.Info("registered stackdriver tracing")
// Register the views to collect server stats.
@ -131,6 +153,11 @@ func initTracing() {
log.Warn("could not initialize stackdriver exporter after retrying, giving up")
}
func initTracing() {
initJaegerTracing()
initStackDriverTracing()
}
func initProfiling(service, version string) {
// TODO(ahmetb) this method is duplicated in other microservices using Go
// since they are not sharing packages.