maxDepth 인자를 createNextRoutesUrlGroup 함수에 추가합니다.#11
maxDepth 인자를 createNextRoutesUrlGroup 함수에 추가합니다.#11pcfulife wants to merge 13 commits intoNaverPayDev:mainfrom
Conversation
…hen using `normalizeNextRoutesPath`
…namic routes when using `normalizeNextRoutesPath`
|
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 Koa와 Hono 쪽에 파라미터를 추가하는것이 누락되어서 새 커밋 추가하였습니다! |
| KoaPrometheusExporterOptions, | ||
| 'nextjs' | 'bypass' | 'normalizePath' | 'formatStatusCode' | 'maxDepth' | 'trimDynamic' | ||
| >): Middleware { | ||
| const normalizeNextRoutesPath = nextjs ? createNextRoutesUrlGroup(maxDepth, trimDynamic) : undefined |
There was a problem hiding this comment.
nextjs: false 이면 normalizeNextRoutesPath 기능이 동작하지 않는건데, 기본적으로 maxDepth 가 적용되면 좋겠습니다.
packages/core/src/next/utils.ts
Outdated
| ? it.page | ||
| : `/${it.page | ||
| .split('/') | ||
| .slice(1, maxDepth + 1) |
There was a problem hiding this comment.
maxDepth가 없는 경우에는 Number.MAX_SAFE_INTEGER + 1을 하려고 할텐데,
Number.MAX_SAFE_INTEGER 로 기본값 세팅하는 것보다는 maxDepth 유무에 따라 분기처리하는게 안전해 보입니당.
packages/core/src/next/utils.ts
Outdated
| return page | ||
| for (const it of routes) { | ||
| if (it.regex.test(withoutBasePathUrl)) { | ||
| return dynamicRoutes.includes(it) && !trimDynamic |
packages/core/src/next/utils.ts
Outdated
| if (regex.test(withoutBasePathUrl)) { | ||
| return page | ||
| for (const it of routes) { | ||
| if (it.regex.test(withoutBasePathUrl)) { |
There was a problem hiding this comment.
maxDepth 옵션이 dynamicRoute가 아닐때도 적용 되어야 하지 않을까요?
…trims dynamic routes when using `normalizeNextRoutesPath`" This reverts commit da104a1.
packages/core/src/metrics/util.ts
Outdated
|
|
||
| export const trimUrl = (url: string, maxDepth?: number) => { | ||
| const withStartingSlashUrl = url.startsWith('/') ? url : '/' + url | ||
| return typeof maxDepth === 'number' ? withStartingSlashUrl.split('/', maxDepth + 1).join('/') : withStartingSlashUrl |
There was a problem hiding this comment.
이 typeof 는 undefined 걸러내기위해서 쓰신건가요?
0일때는 빈문자열이 반환됩니다.
그리고, maxDepth 가 3이면 지금 로직으로는 '/foo/bar/baz' -> '/foo/bar' 와 같이 2 depth 까지만 trim 되는것 같습니다.
There was a problem hiding this comment.
@boxersb maxDepth가 0인것은 사실 고려하지 않았습니다. /로 반환하는게 좋을까요?
There was a problem hiding this comment.
저는 로직이 정상 동작하는 것으로 보이는데.. 혹시 어떤 부분이 문제일까요?
There was a problem hiding this comment.
아 + 1 이 있었군요~ 그건 제가 잘못 봤습니다.
maxDepth 가 0일때 아무 액션도 취하지 않으려면 로직을 좀 수정하는게 좋을것 같네요~
There was a problem hiding this comment.
@boxersb 0 이하면 에러를 던지고 undefined 일 때 작업을 하지 않으려고 합니다.
packages/core/src/types.ts
Outdated
| /** Whether to collect default Node.js metrics */ | ||
| collectDefaultMetrics?: boolean | ||
| /** Max number to trim path */ | ||
| maxDepth?: number |
There was a problem hiding this comment.
core 입장에서의 maxDepth 가 어디의 depth 인지 인지하기 어렵습니다.
maxDepthOfPath 나 maxNormalizeDepth 가 가까울것 같은 느낌인데 좀 안이쁘긴 해요;
There was a problem hiding this comment.
@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) |
There was a problem hiding this comment.
nextjs 일때는 옵션으로 넘기는 normalizePath 나 trimUrl 이 전혀 동작하지 않을텐데요, nextjs 더라도 nextjs 의 manifest 에 없는 uri 도 분석하게 할 수 없을까요?
그리고, 옵션 설계가 지금처럼 nextjs 여부에 따르지 않고, normalizePath 여부에 따라 분기되어야 하는건 아닐지요?
const normalizeRouePath = normalizePath || nextjs ? createNextRoutesUrlGroup(maxDepth) : trimUrl
...
return normalizeRoutePath(url, maxDepth)cc) @2-one-week
There was a problem hiding this comment.
@boxersb createNextRoutesUrlGroup 함수 내부에서 manifest에 없는 URL에도 trimUrl을 적용하고 있습니다.
There was a problem hiding this comment.
옵션 설계를 수정하는 것은 일종의 Breaking changes라서 cc 해주신 것처럼 메인 컨트리뷰터분들 의견도 필요할 것 같습니다.
There was a problem hiding this comment.
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.
packages/core/src/metrics/util.ts
Outdated
| for (const token of url.split('/')) { | ||
| urlTokens.push(token) | ||
| if (token) { | ||
| nonEmptyUrlTokenCount = nonEmptyUrlTokenCount + 1 | ||
| } | ||
| if (nonEmptyUrlTokenCount === maxDepth) { | ||
| break | ||
| } | ||
| } |
There was a problem hiding this comment.
첫번째 토큰은 무조건 빈문자열이니까 maxDepth 가 0일때 빈문자열을 리턴하게 되는거군요..
로직은 고치기 전것이 더 좋았는데, 좀 헷갈리네요.
혹시 maxDepth 가 0 일때는 undefined 때랑 동일하게 전체 url을 리턴하게 하면 어떤가요?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
이거 이름을 normalizeUrlWithTrimming 이걸로 바꾸신것 같은데 반영이 안되었습니다.

Related Issue
Describe your changes
Request