jubo
tutorials
source: Microservices in Action
source: Microservices in Action
:thinking_face: 其中比較陌生的應該是:平台層負責了什麼?
source: Microservices in Action
:astonished: 啊~ 所以其實「四層架構」,比較像是下圖:
source: Microservices in Action
:name_badge: 缺點
服務間的耦合仍然高。過度使用的情況,會造成調用路徑非常脆弱
source: docs.microsoft.com
在等待下游服務時,上游服務的程式通常是被阻塞的 (blocking)。此時若流量過大,會造成資源耗盡、連鎖故障
:bulb: Solution: Pattern: Circuit Breaker, 後面會再探討實作面怎麼善用 Istio 來完成
:thinking_face: Does gRPC faster than RESTful HTTP?
其實 gRPC 很多效能上的優勢是利基於 HTTP/2 的結果。所以許多文章比較的 gRPC 與 RESTful HTTP,反而是在比較 HTTP/1.1 與 HTTP/2,不太公平。
故若我們不探討執行效率的問題,採用 gRPC 還能帶來什麼益處?
我覺得是「開發體驗」的提升,尤其當業務持續發展,內部越來越多服務的時候,能夠保持較良好的開發與團隊內的溝通效率。
我認為關鍵有二:
References:
:thinking_face: 用戶端 (Clients) 與邊界層 (Boundary) 之間也有機會使用 gRPC 嗎?
Of course!有興趣的人可先了解一下,一起逃離文件維護地獄:
source: Microservices in Action
:information_source: 在 Communication in a microservice architecture - docs.microsoft.com 甚至提到:
If possible, never depend on synchronous communication (request/response) between multiple microservices, not even for queries.
且說 sync mode 是 anti-pattern 呢 :thinking_face:
source: Microservices in Action
source: Microservices in Action
source: https://martinfowler.com/articles/microservice-testing/#conclusion-test-pyramid
:bulb: A unit test exercises the smallest piece of testable software in the application to determine whether it behaves as expected.
source: https://martinfowler.com/articles/microservice-testing/#testing-unit-introduction
:information_source: 何謂「一個 unit」?
其實它就像單一職責原則一樣,是一個無法量化並明確界定範圍的概念,範疇取決於你要服務的對象。那麼就表示它可以小到是一個 pure function、或是一個 express/Gin 的 request handling function 的實作。
:information_source: 那些對外部服務的依賴,在你的實作上可採用依賴反轉原則來實作,就能夠在 test cases 中利用依賴注入 (Dependency injection)的方式,用 mock objects 取代,以滿足測試情境的需求。
:older_adult: Kent Beck : “I get paid for code that works, not for tests”
TDD 之父 Kent Beck 於 stackoverflow 上一篇詢問「unit testing 該做得多深入」的問題答到:他傾向不花時間去測試那些不容易犯錯的部分。而是花時間去測試自己與他人容易犯錯的部分、擁有複雜的邏輯的部分。
:bulb: An integration test verifies the communication paths and interactions between components to detect interface defects.
source: https://martinfowler.com/articles/microservice-testing/#testing-integration-introduction
source: https://martinfowler.com/articles/microservice-testing/#testing-integration-diagram
:thinking_face: 有資料庫依賴怎麼辦?
:thinking_face: 有其他微服務依賴怎麼辦?
:thinking_face: 有其他第三方服務依賴怎麼辦?
:bulb: A component test limits the scope of the exercised software to a portion of the system under test, manipulating the system through internal code interfaces and using test doubles to isolate the code under test from other components.
source: https://martinfowler.com/articles/microservice-testing/#testing-component-introduction
:bulb: 以下面的 gRPC contract 為例,元件測試就會測試 rpc SayHello
的行為是否如其運作:
:bulb: An end-to-end test verifies that a system meets external requirements and achieves its goals, testing the entire system, from end to end.
source: https://martinfowler.com/articles/microservice-testing/#testing-end-to-end-introduction
:thinking_face: 有其他替代方案嗎?
其中一種方案:採用 Canary Deployment 的技巧,將特定 users 或一定比例的流量導進新版服務,並透過可觀測性 (observability) 元件的輔助了解系統的狀況。
source: https://harness.io/blog/blue-green-canary-deployment-strategies/
source: https://grafana.com/docs/k6/latest/testing-guides/test-types/
:information_source: 可以先在 k6 的官方介紹中找到更多介紹。未來若有更加明確的 Service Level Agreements (SLAs), Service Level Objectives (SLOs) 或 Service Level Indicators (SLIs) 的需求,也應會直接採用 k6 這套工具
:information_source: 也不是所有的 testing types 都適合做自動化,再看看 k6 如何建議 Automated performance testing
:information_source: Prometheus, Loki, Jaeger, Istio, Grafana 及 Profiler 是我們目前使用的可觀測性技術堆疊 (observability tech stack)
source: Microservices in Action
source: our Grafana Explore
source: our Grafana Dashboard
:information_source: The Four Golden Signals - Google SRE Book
Google SRE 團隊根據他們維運雲端系統的經驗,建議可從以下切角去設計度量指標:
source: https://www.oreilly.com/library/view/distributed-systems-observability/9781492033431/ch04.html
X-Request-ID
in header),tracing system 可以有效掌握一筆 request 流經各個服務所花費的時間X-Request-ID
寫在 logs 裡,完整地整合 logs 與 traces 資訊給後續排錯分析source: our Grafana Explore
:thinking_face: 為何需要 Continuous Profiling?
:information_source: Google Cloud Profilier 支援的 profiles
:information_source: Open Source Continuous Profiling Platform - https://pyroscope.io/
:point_right: Live Demo
:point_right: also has Grafana Plugins