Slide 1

Slide 1 text

Health endpoint pattern as application monitoring #mackerelio Mackerel Meetup #13 Kazuki Higashiguchi (@hgsgtk) 1

Slide 2

Slide 2 text

Health endpoint pattern = 外形監視 2

Slide 3

Slide 3 text

@hgsgtk Kazuki Higashiguchi job is … Software Engineer lang is ... PHP, Go ...etc belongs to ... BASE BANK株式会社 (BASE株式会社の100%子会社) worked with … Mackerel, Docker, AWS(ECS/Fargate) 3

Slide 4

Slide 4 text

= 4 BASE BANK Mission 「銀行をかんたんにし、全ての人が挑戦できる世の中に」 即座に資金調達ができる金融サービス「YELL BANK(エールバンク)」 https://thebase.in/yellbank

Slide 5

Slide 5 text

Reference 入門 監視 ――モダンなモニタリングのための デザインパターン Mike Julian 著、松浦 隼人 訳 7.3 Health check endpoint pattern 5 https://www.oreilly.co.jp/books/9784873118642/

Slide 6

Slide 6 text

= ● like “canary endpoint”, “status endpoint” ● アプリケーション内のHTTPエンドポイント ● アプリケーションの健全性を伝える(外形監視) ● デプロイバージョン・依存性のステータスなど基本情報を含む場合もある 6 Health endpoint pattern

Slide 7

Slide 7 text

= Status Code ● ヘルスチェック成功時は、200 (OK) ● ヘルスチェック失敗時は、503 (Service Unavaialbe) HTTP Response ● ステータス・依存している連携サービスの状態などの状態情報 ● JSON形式など構造化したデータ形式で返却 7 Health endpoint pattern Implementation

Slide 8

Slide 8 text

= 8 Go言語での実装例 https://github.com/hgsgtk/health-endpoint

Slide 9

Slide 9 text

Simple pattern Statusのみを返却する 9 ステータスコード: 200を返すだけのエンドポイント

Slide 10

Slide 10 text

Simple pattern Statusのみを返却する 10 依存しているMySQLサーバへのコネクションも確認する

Slide 11

Slide 11 text

Simple pattern Statusのみを返却する 11 ヘルスチェック失敗の場合は、503 (Service Unavailable)

Slide 12

Slide 12 text

Usage エンドポイントの使い方 12 ● Mackerelなど監視SaaSからの外形監視 ● ALBなどロードバランサのヘルスチェック ● アプリケーション起動確認のデバッグ ○ 「health endpointは200を返してる?」

Slide 13

Slide 13 text

= ● コンテナベースアプリケーションにおける、Health endpoint pattern ● Principles of container-based application design(Redhat) ○ https://www.redhat.com/en/resources/cloud-native-container-design-whitepaper ● HIGH OBSERVABILITY PRINCIPLE (HOP) 高観測可能性の原則 ○ 活動状況や準備状況など、様々な状態チェックに対して APIを提供する ● HOP観点でも、HTTPエンドポイントを用意するこのパターンは有益 13 閑話休題:コンテナベースアプリケーションとの親和性

Slide 14

Slide 14 text

= 14 See also... https://speakerdeck.com/hgsgtk/container-based-application-design-reference-and-practice-number-do ckertokyo

Slide 15

Slide 15 text

= ● Health Check Response Format for HTTP APIs (IETF) ○ https://tools.ietf.org/id/draft-inadarei-api-health-check-02.html ● ヘルスチェックのためのJSONレスポンスの共通フォーマットの議論 ○ “This document proposes a service health check response format for HTTP APIs.” ● 進行中のIssues ○ https://github.com/inadarei/rfc-healthcheck/issues 15 Health Check Response Format for HTTP APIs

Slide 16

Slide 16 text

= ● API Health Response ○ https://tools.ietf.org/id/draft-inadarei-api-health-check-02.html#api-health-response ● format ○ status ○ version (optional) ○ releaseId (optional) ○ notes (optional) ○ output (optional) ○ details (optional) - The Details Object ○ links (optional) ○ serviceId (optional) ○ description (optional) - human readable 16 API Health Response Format (draft)

Slide 17

Slide 17 text

formal example https://tools.ietf.org/id/draft-inadarei- api-health-check-02.html#example-out put 17

Slide 18

Slide 18 text

= 次のどれかの値を設定する ● “pass”: ○ healthy (acceptable aliases: “ok” to support Node’s Terminius and “up” for Java’s SpringBoot) ● “fail”: ○ unhealthy (acceptable aliases: “error” to support Node’s Terminius and “down” for Java’s SpringBoot) ● “warn”: ○ healthy, with some concerns. 18 抜粋:Status

Slide 19

Slide 19 text

= ● アプリケーションの状態監視としてのHealth endpoint pattern ● 議論が進行中の ”Health Check Response Format for HTTP APIs” ● 「こういう情報はどう扱うのがいいんだろう?」という迷いが出たら参考にしてみ ると良さそう。 ● 運用を意識したアプリケーション設計のためにも、監視のパターンは知っておく と良い。 ● 「入門 監視」は最高。 19 Summary