An introduction to monitoring Go Application with OpenCensus

73e67f6da1838e3498c00f33cb0309e3?s=47 Yuichi Saito
July 26, 2018
710

An introduction to monitoring Go Application with OpenCensus

73e67f6da1838e3498c00f33cb0309e3?s=128

Yuichi Saito

July 26, 2018
Tweet

Transcript

  1. 8.

    Applica'on metrics ͷॏཁੑ Կނ Applica(on metrics Λऔಘ͢Δ͜ͱ͕ॏཁͳͷ͔ʁ • ύϑΥʔϚϯε͕αʔϏεʹ༩͑ΔΠϯύΫτ •

    αʔϏεͷ੒௕ͱػೳ௥Ճʹର͢ΔજࡏతͳϦεΫ • ϚΠΫϩαʔϏεʹΑΔύϑΥʔϚϯε෼ੳͷࠔ೉Խ
  2. 9.

    ύϑΥʔϚϯε͕αʔϏεʹ༩͑ΔΠϯύΫτ ΞϓϦέʔγϣϯͷύϑΥʔϚϯε͕ CVR ΍ϦςϯγϣϯʹӨڹ Λ༩͑Δ͜ͱ͕Ұൠతʹ஌ΒΕ͍ͯΔ 1 Our experiments demonstrate that

    slowing down the search results page by 100 to 400 milliseconds has a measurable impact on the number of searches per user of -0.2% to -0.6% (averaged over four or six weeks depending on the experiment). That's 0.2% to 0.6% fewer searches for changes under half a second! 1 Speed Ma)ers h)ps:/ /ai.googleblog.com/2009/06/speed-ma)ers.html
  3. 13.

    APM ͷݱঢ় APM ͸େ͖͘2ͭͷ༻్͕͋ΓɺͦΕʹԠͨ͡αʔϏεͷΫϥΠ ΞϯτΛར༻͍ͯ͠Δ • ΞϓϦέʔγϣϯݻ༗ͷϝτϦΫεͷՄࢹԽɾ؂ࢹ • Datadog /

    CloudWatch / Mackerel / Prometheus • ϚΠΫϩαʔϏεͷαʔϏεؒ௨৴ͷՄࢹԽ (෼ࢄτϨʔγϯ ά) • Datadog APM / Stackdriver Trace / Amazon X-Ray / Zipkin
  4. 18.

    Ecosystem Design ొ৔ਓ෺ • ϝτϦΫεΛѻ͏ͨΊͷ OpenCensus Library • ্هΛར༻ͯ͠ Web

    Framework ͳͲͰࣗಈతʹϝτϦΫεΛ ऩू͢ΔͨΊͷ Library • औಘͨ͠ϝτϦΫεΛ֎෦αʔϏεʹఏڙ͢ΔͨΊͷ Client Library (Exporter)
  5. 21.

    Components Request local ʹϝτϦΫεΛऔΓѻ͏ͨΊͷ Context ͷ࣮૷ͱɺ ͦΕΛར༻ͨ͠ϝτϦΫεͷͨΊͷίϯϙʔωϯτ • Trace API

    • ෼ࢄτϨʔγϯάΛ࣮ݱ͢ΔͨΊͷίϯϙʔωϯτ • Tags API (Stats API) • ΞϓϦέʔγϣϯݻ༗ͷϝτϦΫεΛऔΓѻ͏ͨΊͷίϯ ϙʔωϯτ
  6. 24.

    Go ͷ OpenCensus Library ͷ࣮૷ঢ়گ Go ͸ http ͱ google.golang.org/grpc

    ͰϝτϦΫεΛऔΓ ѻ͏ͨΊ࣮૷͕ OpenCensus Library ʹؚ·Ε͍ͯΔ • Request local ͳίϯςΩετٴͼ࣍ͷαʔόʹ఻ൖͤ͞ΔͨΊ ͷ࣮૷ • ͲͷΑ͏ͳσʔλߏ଄Ͱ఻ൖͤ͞Δ͔ͷ࢓༷͸ W3C ͷ Working Group ͰܾΊΒΕ͍ͯΔ • RPC ʹඥͮ͘ϝτϦΫεΛཪͰऔಘ͢ΔͨΊͷ࣮૷
  7. 25.

    Go ͷ OpenCensus Library ͷ࣮૷ঢ়گ Exporter ʹҎԼͷ࣮૷͕͋Δ • Prometheus •

    Stackdriver • Amazon X-Ray • DataDog • and more...
  8. 26.

    OpenCensus + Stackdriver ʹΑΔࢀߟ࣮૷ Stackdriver ༻ͷ Exporter ͷ ini1alize exporter,

    err := stackdriver.NewExporter(stackdriver.Options{ ProjectID: projectID, }) if err != nil { log.Fatal(err) }
  9. 27.

    OpenCensus + Stackdriver ʹΑΔࢀߟ࣮૷ http.Handler ʹର͢ΔϝτϦΫε (Stats) Λऔಘɾ؅ཧ͢Δ View ͷઃఆͱɺExporter

    ͷొ࿥ view.RegisterExporter(exporter) if err := view.Register( ochttp.DefaultServerViews..., ); err != nil { log.Fatal(err) }
  10. 29.

    OpenCensus + Stackdriver ʹΑΔࢀߟ࣮૷ Handler ͷઃఆ http.HandleFunc("/a", func(w http.ResponseWriter, req

    *http.Request) { client := &http.Client{Transport: &ochttp.Transport{ Propagation: &tracecontext.HTTPFormat{}, }} ctx, span := trace.StartSpan(req.Context(), "in a") defer span.End() r, _ := http.NewRequest("GET", "http://localhost:50030/b", nil) resp, err := client.Do(r.WithContext(ctx)) if err != nil { log.Println(err) } _ = resp fmt.Fprintf(w, "I am /a") }) http.HandleFunc("/b", func(w http.ResponseWriter, req *http.Request) { _, span := trace.StartSpan(req.Context(), "in b") defer span.End() fmt.Fprintf(w, "I am /b") }) log.Fatal(http.ListenAndServe(":50030", &ochttp.Handler{ Propagation: &tracecontext.HTTPFormat{}, }))