Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Goのアプリケーションをトレース して劇的に改善した話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
saicologic
July 07, 2022
Technology
290
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Goのアプリケーションをトレース して劇的に改善した話
saicologic
July 07, 2022
More Decks by saicologic
See All by saicologic
[Go Conference 2022 Spring] GoとLambdaを使用した高パフォーマンスでサーバレスな マイクロサービスの開発と運用
saicologic
0
1k
Other Decks in Technology
See All in Technology
国際カードブランドルール変更に伴うクレジットカード決済取引仕様変更について
k1style
0
250
ビジネス部門からPOを迎えての半年間の進歩と課題
zozotech
PRO
0
160
AI駆動開発における開発環境のセキュリティの考え方
yamahiro
2
660
2026-10-24 JAWS JAWS-UG 茨城 #18 IAM Policy Autopilotってなにさ。terraform planからIAM Policyつくれるの? / What's IAM Policy Autopilot
masasuzu
0
180
AI駆動開発におけるハーネスエンジニアリングの勘所
tsukuboshi
1
840
Claude for Google Workspaces ポン出し/claude-for-google-workspace-slide-conversion
emiki
0
13k
視野はAIに、視座は人に / ai-for-breadth-humans-for-perspective
nkzn
2
970
これだけは抑えておきたい!後悔しない re:Invent の過ごし方 / AWS re:Invent 2026 prestudy
kinunori
2
530
E2Eってつらくないですか?E2Eの管理コストを下げる手段とその実践
akaboshinit
5
2.6k
Adversary Infrastructure Hunting101
disconinja
0
170
kintoneで在庫管理システムを作るときの要件定義・設計ポイント
kai0707
0
140
Don't write the architecture only in the prompt.
neohsu
0
220
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
430
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
460
Making the Leap to Tech Lead
cromwellryan
135
10k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.8k
Accessibility Awareness
sabderemane
1
260
Designing Experiences People Love
moore
143
24k
The untapped power of vector embeddings
frankvandijk
2
2k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
310
The Pragmatic Product Professional
lauravandoore
37
7.5k
Navigating Team Friction
lara
192
16k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
310
Transcript
Goのアプリケーションをトレース して劇的に改善した話 〜一行に隠された秘密を解く〜 三上 悟
©2021 Voicy, Inc. 自己紹介 三上 悟 Tech Lead at Voicy
(元EM) @saicologic 2020年1月入社 6社目 専門はバックエンドエンジニア 17年目 Goの開発は2021年〜 PHP => Ruby => Node.js => Python => Go 趣味:ゲーム、自転車
©2021 Voicy, Inc. 今日の話 Datadog APM(Application Perfomance Monitoring)
©2021 Voicy, Inc. aはFirebase Authです。
©2021 Voicy, Inc. Firebaseもたまにタイムアウトする APIはユーザー認証が必要なため、Firebaseに問い合わせしている? リトライすればいい?
©2021 Voicy, Inc.
©2021 Voicy, Inc. 認証 if a.needCheckRevoked { idToken, err =
a.VerifyIDTokenAndCheckRevoked(ctx, bearerToken) } else { idToken, err = a.VerifyIDToken(ctx, bearerToken) } 認証の実装見ると、needCheckRevokedはFirebaseに問い合わせするが、 VerifyIDTokenは、Firebaseへの問い合せをおこないません
©2021 Voicy, Inc. 補足:認証 HTTP Header { "Authorization": "Bearer xxxxxx"
} xxxxxxは、JWT(JSON Web Token) JWT=bearerTokenの中身です。
©2021 Voicy, Inc. 補足:JWT https://jwt.io/
©2021 Voicy, Inc. 認証ではないとしたら、 accounts:lookupは一体どこで呼ばれているのだろうか?
©2021 Voicy, Inc. InfoログにUserIDを付与したかった。誰のリクエストが調査できるようにするため。 Firebaseの呼び出しはログのミドルウェアで呼ばれていた。 InjectFirebaseAuthenticator.GetUserFromの中でFirebaseに問い合わせしていました。 修正されていない初期のコードで作った人がいません。普通に動くから見直しが行われなかった。
©2021 Voicy, Inc. 修正点 1. 認証ミドルウェアでContextにUserIDを付与した a. あらかじめユーザー登録するときに、 CustomClaims情報を付与しておくと、 JWTの中にUserID情
報が入れられます。 VerifyIDTokenするとUserID取得できるので、ContextにいれてUserIDを引き 回せます。 2. ログのミドルウェアでContextからUserIDを取得して使う 呼び出し順番 ・UnaryServerInterceptor(auth.Authenticate) ・LoggerUnaryServerInterceptor(logger)
©2021 Voicy, Inc. 改善結果 Firebaseの問い合わせが不要になり、全体で 200ms早くなった
©2021 Voicy, Inc. 学び ・JWTの仕組みを知ればFirebaseに問い合わせなくても、必要な情報が取得できる ・Datadog APMを入れると、どこでどれくらいの時間がかかったかわかる ・GoのContextを使えば値を引き回せる。例えばログに情報を付与する用途に使える ・ミドルウェアの処理は全てのAPIに影響するので不要な処理がないか見直そう その他
・JWT検証はアプリ側より、API Gateway側で行うほうが良い (例:Amazon API GatewayのJWT オーソライザー)
ご清聴ありがとうございました。