Skip to content

maxDepth 인자를 createNextRoutesUrlGroup 함수에 추가합니다.#11

Open
pcfulife wants to merge 13 commits intoNaverPayDev:mainfrom
pcfulife:repo/10
Open

maxDepth 인자를 createNextRoutesUrlGroup 함수에 추가합니다.#11
pcfulife wants to merge 13 commits intoNaverPayDev:mainfrom
pcfulife:repo/10

Conversation

@pcfulife
Copy link
Copy Markdown

Related Issue

Describe your changes

  • maxDepth: URL의 최대 깊이 설정 (기본값 Number.MAX_SAFE_INTEGER)
    • 예: maxDepth가 3일 때, /naver/pay/front/end => /naver/pay/frond로 Trim
  • trimDynamic: Dynamic 라우트도 trim 하도록 설정 (기본값 false)
    • 예: trimDynamic이 false면 /naver/pay/article/10 => /naver/pay/article/[id]로 Trim되지 않음

Request

…namic routes when using `normalizeNextRoutesPath`
@claude
Copy link
Copy Markdown

claude bot commented Mar 16, 2026

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.

Once credits are available, push a new commit or reopen this pull request to trigger a review.

2-one-week
2-one-week previously approved these changes Mar 16, 2026
Copy link
Copy Markdown
Member

@2-one-week 2-one-week left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 잘봤습니다! 감사합니다~

@pcfulife
Copy link
Copy Markdown
Author

@2-one-week Koa와 Hono 쪽에 파라미터를 추가하는것이 누락되어서 새 커밋 추가하였습니다!

2-one-week
2-one-week previously approved these changes Mar 16, 2026
Copy link
Copy Markdown
Member

@2-one-week 2-one-week left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다

KoaPrometheusExporterOptions,
'nextjs' | 'bypass' | 'normalizePath' | 'formatStatusCode' | 'maxDepth' | 'trimDynamic'
>): Middleware {
const normalizeNextRoutesPath = nextjs ? createNextRoutesUrlGroup(maxDepth, trimDynamic) : undefined
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextjs: false 이면 normalizeNextRoutesPath 기능이 동작하지 않는건데, 기본적으로 maxDepth 가 적용되면 좋겠습니다.

? it.page
: `/${it.page
.split('/')
.slice(1, maxDepth + 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxDepth가 없는 경우에는 Number.MAX_SAFE_INTEGER + 1을 하려고 할텐데,
Number.MAX_SAFE_INTEGER 로 기본값 세팅하는 것보다는 maxDepth 유무에 따라 분기처리하는게 안전해 보입니당.

return page
for (const it of routes) {
if (it.regex.test(withoutBasePathUrl)) {
return dynamicRoutes.includes(it) && !trimDynamic
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pcfulife trimDynamic 옵션이 꼭 필요할까요? 대상 라우트가 수백, 수천개 되지 않는 이상에는 솔직히 dynamic 라우트는 카디널리티 측면에서 위험하진 않아 보여서요.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kyungmi 아, 이건 제가 헷갈렸습니다. 기본값이 trim을 하는게 아니었죠.. 제거하겠습니다.

if (regex.test(withoutBasePathUrl)) {
return page
for (const it of routes) {
if (it.regex.test(withoutBasePathUrl)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxDepth 옵션이 dynamicRoute가 아닐때도 적용 되어야 하지 않을까요?

@pcfulife pcfulife changed the title maxDepth와 trimDynamic 인자를 createNextRoutesUrlGroup 함수에 추가합니다. maxDepth와 인자를 createNextRoutesUrlGroup 함수에 추가합니다. Mar 17, 2026
@pcfulife pcfulife changed the title maxDepth와 인자를 createNextRoutesUrlGroup 함수에 추가합니다. maxDepth 인자를 createNextRoutesUrlGroup 함수에 추가합니다. Mar 17, 2026
@pcfulife
Copy link
Copy Markdown
Author

@boxersb @kyungmi 리뷰 반영하였습니다!


export const trimUrl = (url: string, maxDepth?: number) => {
const withStartingSlashUrl = url.startsWith('/') ? url : '/' + url
return typeof maxDepth === 'number' ? withStartingSlashUrl.split('/', maxDepth + 1).join('/') : withStartingSlashUrl
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 typeof 는 undefined 걸러내기위해서 쓰신건가요?
0일때는 빈문자열이 반환됩니다.

그리고, maxDepth 가 3이면 지금 로직으로는 '/foo/bar/baz' -> '/foo/bar' 와 같이 2 depth 까지만 trim 되는것 같습니다.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boxersb maxDepth가 0인것은 사실 고려하지 않았습니다. /로 반환하는게 좋을까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boxersb
image

저는 로직이 정상 동작하는 것으로 보이는데.. 혹시 어떤 부분이 문제일까요?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 + 1 이 있었군요~ 그건 제가 잘못 봤습니다.

maxDepth 가 0일때 아무 액션도 취하지 않으려면 로직을 좀 수정하는게 좋을것 같네요~

Copy link
Copy Markdown
Author

@pcfulife pcfulife Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boxersb 0 이하면 에러를 던지고 undefined 일 때 작업을 하지 않으려고 합니다.

/** Whether to collect default Node.js metrics */
collectDefaultMetrics?: boolean
/** Max number to trim path */
maxDepth?: number
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옵션명에 설명이 좀 부족한 느낌인데 괜찮을까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boxersb 조금 더 보강해보겠습니다!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core 입장에서의 maxDepth 가 어디의 depth 인지 인지하기 어렵습니다.
maxDepthOfPath 나 maxNormalizeDepth 가 가까울것 같은 느낌인데 좀 안이쁘긴 해요;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boxersb 아, 옵션명 이야기였군요..! 위에 주석 이야기인줄 알았습니다. 한번 고민해보겠습니다.

const extendedNormalizePath = (context: Context) => {
const url = new URL(context.req.url)
return normalizeNextRoutesPath?.(url.href) || normalizePath?.(context) || url.pathname
return normalizeNextRoutesPath?.(url.href) || normalizePath?.(context) || trimUrl(url.pathname, maxDepth)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextjs 일때는 옵션으로 넘기는 normalizePath 나 trimUrl 이 전혀 동작하지 않을텐데요, nextjs 더라도 nextjs 의 manifest 에 없는 uri 도 분석하게 할 수 없을까요?

그리고, 옵션 설계가 지금처럼 nextjs 여부에 따르지 않고, normalizePath 여부에 따라 분기되어야 하는건 아닐지요?

const normalizeRouePath = normalizePath || nextjs ? createNextRoutesUrlGroup(maxDepth) : trimUrl

...

return normalizeRoutePath(url, maxDepth)

cc) @2-one-week

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boxersb createNextRoutesUrlGroup 함수 내부에서 manifest에 없는 URL에도 trimUrl을 적용하고 있습니다.

https://github.com/NaverPayDev/prometheus/pull/11/changes#diff-6a2432e163645db1e583ebf4933b5427a8a737aab8eb9101d6b1461f0d384de8R74

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옵션 설계를 수정하는 것은 일종의 Breaking changes라서 cc 해주신 것처럼 메인 컨트리뷰터분들 의견도 필요할 것 같습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boxersb createNextRoutesUrlGroup 함수 내부에서 manifest에 없는 URL에도 trimUrl을 적용하고 있습니다.

https://github.com/NaverPayDev/prometheus/pull/11/changes#diff-6a2432e163645db1e583ebf4933b5427a8a737aab8eb9101d6b1461f0d384de8R74

@pcfulife 아 넵 nextjs manifest 에 없을때도 처리되는것 확인했습니다!

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.

Once credits are available, push a new commit or reopen this pull request to trigger a review.

Comment on lines +61 to +69
for (const token of url.split('/')) {
urlTokens.push(token)
if (token) {
nonEmptyUrlTokenCount = nonEmptyUrlTokenCount + 1
}
if (nonEmptyUrlTokenCount === maxDepth) {
break
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

첫번째 토큰은 무조건 빈문자열이니까 maxDepth 가 0일때 빈문자열을 리턴하게 되는거군요..

로직은 고치기 전것이 더 좋았는데, 좀 헷갈리네요.

혹시 maxDepth 가 0 일때는 undefined 때랑 동일하게 전체 url을 리턴하게 하면 어떤가요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boxersb 반영하였습니다!

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.

Once credits are available, push a new commit or reopen this pull request to trigger a review.

return (
normalizeNextRoutesPath?.(url.href) ||
normalizePath?.(context) ||
trimUrl(url.pathname, maxNormalizedUrlDepth)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 이름을 normalizeUrlWithTrimming 이걸로 바꾸신것 같은데 반영이 안되었습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants