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
280
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
ai_cording_with_k8s_knowledge.pdf
mochizuki875
1
310
【データ横丁主催】AI Agentがコンテキストを使って仕事をした後、何が残るのか― 組織の経験を次の判断に引き継ぐ「Agent Memory」
shisyu_gaku
2
340
全社共通データ基盤をつくる。ソニーのDatabricks活用とデータガバナンス設計の裏側
sony
0
430
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
510
生成AIを使って「人が」考える技術 ― AI時代の人機共想と実践ノウハウ|UNITT AC2026
ishiirikie
0
560
私の推しは「聞いてから進む」AIです -AI-DLCに一人でアプリを作らせた話
yama3133
1
180
スキルを作る、その前に!複数人で使われるスキルを 作るためのプロセス
junkifurukawa
2
350
Execution in the Kingdom of Agents: Reflections on Abstraction and Complexity
bcantrill
0
870
Deep Data Security 機能解説
oracle4engineer
PRO
2
720
Claude Code本は、どのように執筆チームで書かれたか
oikon48
0
310
Snowflake Horizon Catalog と Apache Iceberg で作る オープンなデータ基盤
kitagawaz
0
460
ミイダス株式会社 テックチームのご紹介 / MIIDAS Tech Team
miidas
0
170
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
290
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
320
Building AI with AI
inesmontani
PRO
1
1.3k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Skip the Path - Find Your Career Trail
mkilby
1
240
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
ラッコキーワード サービス紹介資料
rakko
1
5.2M
Un-Boring Meetings
codingconduct
0
440
sira's awesome portfolio website redesign presentation
elsirapls
0
440
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 オーソライザー)
ご清聴ありがとうございました。