Spring Boot Adminことはじめ / Introduction of Spring Boot Admin

Spring Boot Adminことはじめ / Introduction of Spring Boot Admin

53850955f15249a1a9dc49df6113e400?s=128

LINE Developers

March 25, 2019
Tweet

Transcript

  1. Spring Boot Admin
 ͜ͱ͸͡Ί Kazuhiro OSAWA, LINE Corporation.
 2019/03/25 JSUGษڧձ

    2019ͦͷ3 LINEʹ͓͚ΔSpringͷ׆༻
  2. @yappo https://github.com/yappo ࣗݾ঺հ େ୔࿨޺ LINEגࣜձࣾ ։ൃ3ηϯλʔॴଐ LINE LIVE ։ൃ୲౰ͳͲ

  3. • ಋೖͷ͖͔͚ͬ • ಋೖͯ͠ΈΔ • Tips • ಋೖͯ͠ΈͯΘ͔ͬͨ͜ͱ Agenda

  4. • LINE LIVE ͱ͍͏αʔϏεͰ Spring Boot Admin Λಋೖͨ͠ܦݧΛݩʹ࿩͠·͢ • ಋೖ͔ͯ͠Β1ϲ݄ܦͬͯͳ͍͘Β͍Ͱ͢

    • Ωϟϓνϟը૾ͷॴʑʹमਖ਼ೖΕͯ·͢ લఏ
  5. ಋೖͷ͖͔͚ͬ

  6. ଟ਺ͷΞϓϦέʔγϣϯίϯϙʔωϯτ ※·ͩະಋೖͷ ίϯϙʔωϯτ͸ଟ਺͋Δ

  7. ֤ίϯϙʔωϯτ΋छྨ͝ͱʹ ٕज़ελοΫ΋ҧ͍ͬͯͨ ϦϦʔε౰ॳ WAF Ҡߦޙ core Avans Spring Boot 2.1.3

    ؅ཧը໘ Spring 4.3.x Spring Boot 2.2.x (༧ఆ) chat Spring Boot 1.4.x Spring Boot 2.2.x (༧ఆ) for LINE Bot Spring Boot 1.5.x Spring Boot 2.1.3 ։ൃνʔϜ͕एׯ෼͔Ε͍ͯͨɺͱ͔͍͏Α͋͘Δཧ༝ɻ
  8. Spring Boot ՔಇΠϯελϯε 200Πϯελϯεڧ

  9. • γεςϜϝτϦΫε • Grafana • Kibana • Ξϥʔτ௨஌ • IMON

    (https://www.slideshare.net/linecorp/observability-at-line) • Prometheus • ϩά؂ࢹ • IMON • Kibana • ϓϩϑΝΠϦϯά • VisualVM, Java Flight Recorder, jstack, etc ֤छπʔϧ
  10. Ξϥʔτड৴ εϨουμϯϓऔಘ VisualVM ηοτΞοϓ Login ͯ͠ jstack ো֐ൃੜ ϓϩϑΝΠϦϯά࡞ۀͷखؒ ෳ਺୆ಉ࣌ଟൃతʹΞϥʔτ͕ඈΜͩΓ͢Δͱɺख͕ؒͳ͔ͳ͔͔͔Δɻɻɻ

  11. VisualVM ΋ো֐ରԠͰ׆༂த͕ͩɺͦΕ͸ͦΕ https://www.slideshare.net/linecorp/update-of-line-live-over-the-past-year

  12. • ద੾ͳόʔδϣϯͷΞϓϦέʔγϣϯ͕σϓϩΠ͞ΕͯΔ͔஌Γ͍ͨ • JVM ͕ద੾ʹՔಇ͍ͯ͠Δ͔ΛϦΞϧλΠϜʹݟ͍ͨ • ద੾ͳઃఆͰΞϓϦέʔγϣϯ͕Քಇ͍ͯ͠Δ͔Λݟ͍ͨ • CPU/Memory αϯϓϦϯά

    (Spring Boot Admin Ͱ͸ݱঢ়Ͱ͖ͳ͍) • αʔό਺ଟΊͳͷͰɺઃఆϑϦʔͩͱେ׻ܴ • ίετͷ͜ͱΛߟ͑ΔͱɺαʔόΛݮΒͨ࣌͠΋ָ͍ͨ͠ • ͜ΕΒͷ৘ใΛαʔϏεʹར༻͍ͯ͠ΔαʔόΠϯελϯεશͯͰҰݩ؅ཧͰ͖ ΔμογϡϘʔυతͳ΋ͷ ཉ͔ͬͨ͠΋ͷ
  13. ಋೖͯ͠ΈΔ

  14. • ಋೖ͕؆୯ • Actuator ͰऔಘͰ͖Δ৘ใΛ Web UI Ͱදࣔ͢Δ • Πϯελϯεͷ

    Up/Down ͷΠϕϯτൃੜ࣌ʹ Slack ͳͲͰ௨஌͢Δ͜ͱ͕Մೳ • ࣗલͷ௨஌खஈ΋࣮૷ʹΑΓՄೳ • ೝূͷ࢓૊Έ͸ͳ͍͕ Spring Boot Security Λར༻͢ΔͳͲͯ͠ಋೖՄೳ • Hazelcast Λར༻ͨ͠ΫϥελϦϯά • ಋೖͷࢀߟʹͳΔαϯϓϧ͕๛෋ Spring Boot Admin ͷಛ௃
  15. Spring Boot Admin શମߏ੒ Application With SBA Client Spring Boot

    Admin Server Web Browser Application With SBA Client Application With SBA Client Registration Show Instances Fetch Actuators Fetch Actuators (Proxy)
  16. Spring Boot Admin Server ͷ࢓૊Έ Application With SBA Client •

    @EnableAdminServer ΞϊςʔγϣϯΛ͚ͭΔ͜ͱͰ AdminServerMarkerConfiguration.Marker (ҎԼ Marker) ͕ Bean ొ࿥͞ΕΔ • ݁Ռతʹ AdminServerAutoConfiguration ͕༗ޮ͔͞Ε SBA ͷΞϓϦέʔγϣϯ ͕࣮ߦ͞ΕΔ • Client ͔Βͷొ࿥Λ /instances ʹ POST ͞ΕΔ͜ͱͰड͚෇͚Δ • ड͚෇͚ͨσʔλΛ InMemory ͔ Hazelcast ʹอଘ • Event Journal ͰҰཡදࣔͯ͠Δ • Web UI ͕ /instances/{instanceId}/actuator/** ͷϦΫΤετΛड͚ͨΒɺԼهͷΑ ͏ʹ proxy ͢Δ Spring Boot Admin Server Web Browser
  17. Spring Boot Admin Client ͷ࢓૊Έ • spring.factories ͷதͰ SpringBootAdminClientAutoConfiguration ΛಡΈࠐΜͰΔ

    • ͦͷதͰ RegistrationApplicationListener ͷ Bean Λ࡞ͬͯ • ThreadPoolTaskScheduler Λ࢖ͬͯఆظతʹ ApplicationRegistrator#register Λ࣮ ߦͯ͠ Server ͷ API Λୟ͍ͯɺΞϓϦέʔγϣϯొ࿥Λߦ͍ͬͯΔ
  18. ࣮ࡍʹ Reference Guide IDEA Λ࢖͍ͳ͕Βઆ໌

  19. ಋೖͯ͠ΈΔ::Tips

  20. git properties ΂ΜΓ pom.xml, build.gradle ʹઃఆ௥Ճ͓ͯ͘͠ͱ git.properties ϑΝΠϧΛੜ੒͠ ͯ͘ΕΔɻ management.info.git.mode

    = full ͱ͔ઃఆʹॻ͍͓ͯ͘ͱ Insights ʹ commit ͷৄࡉ৘ใΛग़ͯ͘͠ΕΔɻ
  21. git properties ΂ΜΓ

  22. • http trace ͸ session ΍ header ͳͲ͸ɺશ෦ OFF ʹ͢Δ

    • ෆඞཁʹ Actuator ͸ղ์͠ͳ͍ management ͷઃఆʹؾΛ࢖͏
  23. • ͦͷ··ͩͱ CSRF ੬ऑੑ͕͋ΔͷͰɺͪΌΜͱ SecurityConfig ౳Λ࣮૷͢Δ • Ͳͷϗετ͔ΒͰ΋Πϯελϯεͷొ࿥Ͱ͖ͨΓ Admin ͷ

    Web Λར༻͢Δͷ΋ ؅ཧ͕Ͱ͖ͳ͘ͳΔͷͰ Spring Boot Security ͳͲͰ࠷௿ݶͷೝূ͔͚Δ • ͜ΕΒ͸ Reference Guide Ͱઆ໌͞ΕͯΔ Security ΋ద੾ʹ͢Δ
  24. • ࣗ෼ͷ৔߹͸ɺؾܰʹ Web ͔Βઃఆม͑ͨΓͰ͖ͳ͍Α͏ʹ͢ΔͨΊ Actuator ͷ PATH ʹ͚ͩ GET ϝιουҎ֎ͷΞΫηεېࢭͷઃఆΛ͔͚ͯݟͨ

    Security ΋ద੾ʹ͢Δ
  25. ಋೖͯ͠Θ͔ͬͨ͜ͱ

  26. Client ͷύϑΥʔϚϯε͸ѱ͘ͳ͍ ͱ͸͍͑ɺಋೖޙͷϝϞϦͷར༻܏޲͕มΘ͕ͬͨଟ෼ Actuator ΋ಉ࣌ʹ Enable ͍ͨͤͩ͠ͱߟ͑ΒΕΔ

  27. Basic ೝূॲཧͷॏ͕͞໨ཱͬͨ Client ͷσϑΥϧτͷ API Call ִ͕ؒ10ඵͳͷͰɺ50୆Λ௒͑ͨ͋ͨΓͰݦஶʹ CPU ෛՙ͕໨ཱͭΑ͏ʹͳ͖ͬͯͯ100୆௒͑ͨ͋ͨΓͰϩʔυΞϕϨʔδ͕ 200ۙ͘·Ͱ௓Ͷ্͕ΔΑ͏ʹͳͬͨ

  28. Basic ೝূॲཧͷѱ͕͞໨ཱͬͨ ઃఆϑΝΠϧʹॻ͍ͨ username/password ͳͷͰ BCrypt ࢖͏͜ͱ͸෋߽͗ͨ͢ ͷͰɺγϯϓϧͳ NoOpPasswordEncoder Λ࢖ͬͨΒෛՙ͕ٸܹʹԼ͕ͬͨ

  29. ࣗࣾͷೝূγεςϜʹ੾Γସ͑Δ Actuator Ͱग़ͯ͠Δଞͷ߲໨ͳͲ΁ͷΞΫηε΋ϑϧղ์͢Δʹ͸ Basic ೝ ূΛ࢖ͬͨ··Ͱ͸ݫ͍͠ͷͰɺࣗࣾͷ LDAP ͳͲͷೝূͱૢ࡞ϩάͷ࢓૊ ΈͳͲΛॆ࣮ͤ͞Δͱྑ͍ɻ ී௨ͷ

    Spring Boot ΞϓϦέʔγϣϯͳͷͰɺͦΕͳΓʹΞΫηε੍ޚ͸࣮ ૷Մೳɻ
  30. Host List ݟਏ͍

  31. • Client ͷ Server ొ࿥༻ͷεϨου໊͕ registrationTask1 ͰΑ͘Θ͔ΒΜॴ • Http Traces

    ͸ɺͦͦ͜͜ͷτϥϑΟοΫ͕͋Δͱϩʔυ଴ͪͰݻ·Δ • MBean ΛΧδϡΞϧʹ Web ͰฤूͰ͖Δ/ Log level ΋ฤूͰ͖Δͷ͸ා͍ͷ Ͱɺ actuator ͷ PATH ʹରͯ͠΋ REMOTE ADDR ͰͷΞΫηε੍ޚ΍ Spring Boot Admin ࣗମͷೝূ΋͔ͬ͠Γ࡞Γࠐ·ͳ͍ͱةݥ • Environment/Configuration Properties ΋σϑΥϧτͰ password/token ͳͲ͸Ϛε Ϋ͞ΕΔ͕ɺ௕͘ӡ༻͍ͯ͠Δͱઈର࿙Ε͕ൃੜͯ͠ϦεΫ্͕ΔͷͰɺ্هͱ ಉ͔ͬ͘͡͠ΓΞΫηε੍ޚ͸࣮૷͠ͳ͍ͱͩΊ • Http Traces ͸ default Ͱ request header ͳͲΛશ෦ग़ྗͪ͠Όͬͯةݥ౓ߴ͍ͷ Ͱલड़ͷΦεεϝઃఆ͸࠷௿ݶೖΕͱ͔ͳ͍ͱةͳ͍ ؾʹͳΔͱ͜Ζ
  32. • Client ͷ Server ొ࿥༻ͷεϨου໊͕ registrationTask1 ͰΑ͘Θ͔ΒΜॴ • Http Traces

    ͸ɺͦͦ͜͜ͷτϥϑΟοΫ͕͋Δͱϩʔυ଴ͪͰݻ·Δ • MBean ΛΧδϡΞϧʹ Web ͰฤूͰ͖Δ/ Log level ΋ฤूͰ͖Δͷ͸ා͍ͷ Ͱɺ actuator ͷ PATH ʹରͯ͠΋ REMOTE ADDR ͰͷΞΫηε੍ޚ΍ Spring Boot Admin ࣗମͷೝূ΋͔ͬ͠Γ࡞Γࠐ·ͳ͍ͱةݥ • Environment/Configuration Properties ΋σϑΥϧτͰ password/token ͳͲ͸Ϛε Ϋ͞ΕΔ͕ɺ௕͘ӡ༻͍ͯ͠Δͱઈର࿙Ε͕ൃੜͯ͠ϦεΫ্͕ΔͷͰɺ্هͱ ಉ͔ͬ͘͡͠ΓΞΫηε੍ޚ͸࣮૷͠ͳ͍ͱͩΊ • Http Traces ͸ default Ͱ request header ͳͲΛશ෦ग़ྗͪ͠Όͬͯةݥ౓ߴ͍ͷ Ͱલड़ͷΦεεϝઃఆ͸࠷௿ݶೖΕͱ͔ͳ͍ͱةͳ͍ ؾʹͳΔͱ͜Ζ Spring Boot Admin ͳΒͰ͸ͷ෦෼͕গͳ͔ͬͨɻɻ
  33. • ΞϓϦέʔγϣϯͷϏϧυόʔδϣϯΛ List View ͰݟΕΔΑ͏ʹ • Πϯελϯε ID ΛΘ͔Γ΍͍ͨ͘͢͠ •

    ଟ෼ࣗલͰ InstanceIdGenerator Λ࣮૷ͨ͠ΒͰ͖ͦ͏? • ֤छϦετͰιʔτॱ͕Ṗ͍ͷͰࣗવʹ͍ͨ͠ • υΩϡϝϯτΛ΋͏গ͠Θ͔Γ΍͘͢ɻɻɻ • ΫϥελϦϯά΍௨஌ઃఆपΓ͕ͱ͖ͬͭʹ͔ͬͨ͘ ͜Εཉ͍͠
  34. • Spring Boot Admin ͷಋೖํ๏΍ɺಋೖͯ͠ಘΒΕͨ஌ݟΛ঺հ͠·ͨ͠ • ࢥͬͯҎ্ʹ؆୯ʹಋೖͰ͖ΔͷͰɺ͓ࢼ͍ͩ͘͠͞ ·ͱΊ