😺

Postman Monitor のリージョンをCloudflare Worker で調べる

2023/12/23に公開

Postman Monitor のリージョンをCloudflare Worker で調べる

こちらの記事の派生です。

https://zenn.dev/ftd_tech_blog/articles/ftd-cloudflare-2023-12-17

リージョンを指定して、APIの速度が測れる環境を作るか悩んでた時に、Postman Monitor で測れることが分かったので、 そちらを試してみました。

ただ

image

速度測りたいのに、どこからのリクエストかわからないんじゃ測り用がない。
ってことでどこから来ているのか調べました。

用意したもの

Collection

Monitor

プログラム

こちらにアップしてあります。

index.ts
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/

結果

結果は 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

お気持ち

https://twitter.com/xiombatsg/status/1734241175161430023
https://twitter.com/xiombatsg/status/1734527547658932684

最後に

Asian Pacificがシンガポールって出た時に思わず呟くほどの衝撃でした。Postman 日本法人が立ち上がった今!是非東京リージョンを作って欲しいです。

番外編

ちなみ、ブラウザとアプリでもリージョンが異なります。
遅いなって思ったら気にしてみても良いとは思います。

ブラウザは US, アプリは近いところから(私の手元では JP,Tokyo)

ブラウザ

image

{"version":"0.0.1","country":"US","city":"Ashburn","continent":"NA"}

アプリ

image

{"version":"0.0.1","country":"JP","city":"Tokyo","continent":"AS"}

参考

おまけというかPostmanさんに要望(12.25追記)

Postman Monitor でどのリージョンでFailed したのかぱっと見わからないです。いつもRegionを切り替える作業が発生して、俯瞰性がちょっと悪いんで、
リージョン別に結果を出して欲しいです。

2 failed tests, 0 errors, across 9 regions12:00 AM, 25 Dec 2023

image

参考

の 12/25 12AM を見て貰えばわかりますが、 2failed している。US(east)がデフォルトなのでどこがエラーしたかわからない

  • Asia Pacific
  • South America
GitHubで編集を提案

Discussion