title | emoji | type | topics | published | publication_name | ||
---|---|---|---|---|---|---|---|
Postman Monitor のリージョンをCloudflare Worker で調べる |
😺 |
tech |
|
true |
ftd_tech_blog |
:::message この記事は、Postman Advent Calendar 2023 25日目の記事です。 :::
@card
https://zenn.dev/ftd_tech_blog/articles/ftd-cloudflare-2023-12-17
リージョンを指定して、APIの速度が測れる環境を作るか悩んでた時に、Postman Monitor で測れることが分かったので、 そちらを試してみました。
:::message リージョンがどこの都市とか細かい情報がないんです。 :::
速度測りたいのに、どこからのリクエストかわからないんじゃ測り用がない。 ってことでどこから来ているのか調べました。
@card
@card
こちらにアップしてあります。 @card
app.get("/", async (c) => {
console.log("country:", c.req.raw.cf.country);
console.log("city:", c.req.raw.cf.city);
return new Response(
JSON.stringify({
version: "0.0.1",
country: c.req.raw.cf.country,
city: c.req.raw.cf.city,
continent: c.req.raw.cf?.continent,
}),
);
});
- Honoで書いてます
- Cloudflare Worker は cf にcountry, cityが入っている。これはデータセンターの位置を表してます。
こちらにデプロイしてあるので、手元で叩いてみても良いです。 https://momento-cache-worker.future-techno-developers.workers.dev/
:::message Cloudflare Worker のセットアップ方法は割愛します。 :::
結果は wrangler コマンドを使います。これは記事読者には権限ないですが、プロジェクトコピーしてデプロイしてみるなどで試してみてください。
wrangler tail --format=pretty momento-cache-worker -c config/wrangler.dev.toml
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:25 PM
(log) country: US
(log) city: Boardman
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:25 PM
(log) country: US
(log) city: Boardman
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:25 PM
(log) country: CA
(log) city: Montreal
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:25 PM
(log) country: US
(log) city: Ashburn
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:25 PM
(log) country: GB
(log) city: London
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:25 PM
(log) country: US
(log) city: Ashburn
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:25 PM
(log) country: SG
(log) city: Singapore
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:26 PM
(log) country: DE
(log) city: Frankfurt am Main
GET https://momento-cache-worker.future-techno-developers.workers.dev/ - Ok @ 12/23/2023, 3:56:26 PM
(log) country: BR
(log) city: São Paulo
リージョン | Country | City |
---|---|---|
US(West) | US | Boardman |
Canada(Central) | CA | Montreal |
US(East) | US | Ashburn |
United Kingdom | GB | London |
Asian Pacific | SG | Singapore |
Europe(Central) | DE | Frankfurt am Main |
South America | BR | São Paulo |
:::message BoardmanとAshburn は同じUSで出ましたが、東海岸と西海岸の都市なので、そうだろうということで記載してます。 :::
https://twitter.com/xiombatsg/status/1734241175161430023 https://twitter.com/xiombatsg/status/1734527547658932684
Asian Pacificがシンガポールって出た時に思わず呟くほどの衝撃でした。Postman 日本法人が立ち上がった今!是非東京リージョンを作って欲しいです。
ちなみ、ブラウザとアプリでもリージョンが異なります。 遅いなって思ったら気にしてみても良いとは思います。
:::message 大多数のケースではアプリで利用した方が良いと思います。 :::
{"version":"0.0.1","country":"US","city":"Ashburn","continent":"NA"}
{"version":"0.0.1","country":"JP","city":"Tokyo","continent":"AS"}
:::message VS Code は試していませんが、おそらくアプリと同じ挙動をすると思います。 :::
@card
Postman Monitor でどのリージョンでFailed したのかぱっと見わからないです。いつもRegionを切り替える作業が発生して、俯瞰性がちょっと悪いんで、 リージョン別に結果を出して欲しいです。
2 failed tests, 0 errors, across 9 regions12:00 AM, 25 Dec 2023
@card
の 12/25 12AM を見て貰えばわかりますが、 2failed している。US(east)がデフォルトなのでどこがエラーしたかわからない
- Asia Pacific
- South America