chore: reflect observability updates in release 83
This commit is contained in:
1 parent
ab721873f3
commit
d2fc126fed
13 files changed
+636
-33
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
resolveAuctionErrorMessage,
|
||||
resolveAuctionRejectionMessage,
|
||||
} from './auctionRejectionMessages';
|
||||
import { addNewRelicPageAction } from '../lib/observability/new-relic';
|
||||
|
||||
type ConnectionStatus =
|
||||
| 'idle'
|
||||
@@ -180,9 +181,36 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
resolveCurrentBidPointAmount(nextAuction);
|
||||
}
|
||||
|
||||
function commitAuctionState(nextAuction: ApiAuction): boolean {
|
||||
function commitAuctionState(
|
||||
nextAuction: ApiAuction,
|
||||
source = 'socket-state',
|
||||
): boolean {
|
||||
const currentAuction = latestAuctionRef.current;
|
||||
if (!shouldApplyIncomingAuctionState(currentAuction, nextAuction)) {
|
||||
const applied = shouldApplyIncomingAuctionState(currentAuction, nextAuction);
|
||||
const currentRevision =
|
||||
typeof currentAuction?.revision === 'number'
|
||||
? currentAuction.revision
|
||||
: -1;
|
||||
const incomingRevision =
|
||||
typeof nextAuction?.revision === 'number' ? nextAuction.revision : -1;
|
||||
// 단조성을 깨고 적용되는 경우(=revision이 같거나 뒤로 가는데도 반영됨).
|
||||
// force-resync/lifecycle 교체로만 발생하며, "2~3 버전 롤백"의 직접 증거가 된다.
|
||||
const isBackwardApply =
|
||||
applied &&
|
||||
currentRevision >= 0 &&
|
||||
incomingRevision >= 0 &&
|
||||
incomingRevision <= currentRevision;
|
||||
addNewRelicPageAction('AuctionClientStateApply', {
|
||||
matchId: matchId ?? 'none',
|
||||
source,
|
||||
applied,
|
||||
isBackwardApply,
|
||||
revisionDelta: incomingRevision - currentRevision,
|
||||
...describeAuctionForTelemetry('current', currentAuction),
|
||||
...describeAuctionForTelemetry('incoming', nextAuction),
|
||||
});
|
||||
|
||||
if (!applied) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -361,7 +389,7 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
});
|
||||
|
||||
socket.on('state', (nextAuction: ApiAuction) => {
|
||||
const didApplyState = commitAuctionState(nextAuction);
|
||||
const didApplyState = commitAuctionState(nextAuction, 'socket-state');
|
||||
if (didApplyState) {
|
||||
clearPendingActionRequests();
|
||||
}
|
||||
@@ -384,7 +412,24 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
|
||||
socket.on('bid', (payload: BidDeltaPayload) => {
|
||||
applyFallbackServerTimestamp(payload?.currentServerTimestampMS);
|
||||
const beforeBid = latestAuctionRef.current;
|
||||
const didApplyBidDelta = commitBidDelta(payload);
|
||||
addNewRelicPageAction('AuctionClientBidDelta', {
|
||||
matchId: matchId ?? 'none',
|
||||
applied: didApplyBidDelta,
|
||||
deltaRevision:
|
||||
typeof payload?.revision === 'number' ? payload.revision : -1,
|
||||
deltaBidAmount: Number(payload?.currentHighestBidPointAmount ?? -1),
|
||||
deltaBidderTeamIndex: Number(
|
||||
payload?.currentHighestBidderTeamIndex ?? -1,
|
||||
),
|
||||
beforeRevision:
|
||||
typeof beforeBid?.revision === 'number' ? beforeBid.revision : -1,
|
||||
beforeBidAmount: beforeBid
|
||||
? resolveCurrentBidPointAmount(beforeBid)
|
||||
: -1,
|
||||
beforePlayerUserId: beforeBid?.currentBidRoundPlayerUserId ?? 'none',
|
||||
});
|
||||
if (payload?.bidRequestId) {
|
||||
if (
|
||||
didApplyBidDelta ||
|
||||
@@ -429,6 +474,12 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
};
|
||||
latestAuctionRef.current = nextAuction;
|
||||
setAuction(nextAuction);
|
||||
addNewRelicPageAction('AuctionClientSideEffect', {
|
||||
matchId: matchId ?? 'none',
|
||||
matchSideEffectStatus: matchSideEffectStatus ?? 'unknown',
|
||||
matchSideEffectRevision,
|
||||
...describeAuctionForTelemetry('current', currentAuction),
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('reset', (payload: ResetPayload) => {
|
||||
@@ -574,6 +625,23 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
clearPendingActionRequest(auctionActionRequestId);
|
||||
setError('경매 진행 응답이 지연되어 최신 상태를 다시 확인해주세요.');
|
||||
}, 10_000);
|
||||
addNewRelicPageAction('AuctionClientActionSent', {
|
||||
matchId: matchId ?? 'none',
|
||||
action: eventName,
|
||||
retryAttempt,
|
||||
sentRevision:
|
||||
typeof payload.clientObservedRevision === 'number'
|
||||
? payload.clientObservedRevision
|
||||
: -1,
|
||||
sentOrderIndex:
|
||||
typeof payload.clientObservedCurrentAuctionPlayerOrderIndex === 'number'
|
||||
? payload.clientObservedCurrentAuctionPlayerOrderIndex
|
||||
: -1,
|
||||
sentPlayerUserId:
|
||||
payload.clientObservedCurrentBidRoundPlayerUserId ?? 'none',
|
||||
sentPhase: payload.clientObservedPhase ?? 'none',
|
||||
...describeAuctionForTelemetry('observed', latestAuctionRef.current),
|
||||
});
|
||||
socket.emit(
|
||||
eventName,
|
||||
actionPayload,
|
||||
@@ -590,14 +658,6 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
clearPendingActionRequest(
|
||||
ack?.auctionActionRequestId ?? auctionActionRequestId,
|
||||
);
|
||||
// 1) rebaseline: 서버가 동봉한 최신 state를 즉시 반영(없으면 join으로 재요청).
|
||||
// commitAuctionState는 latestAuctionRef를 동기로 갱신하므로, 이후
|
||||
// buildAuctionActionPayload는 최신 관측값(revision/phase/선수)을 읽는다.
|
||||
if (ack.state) {
|
||||
commitAuctionState(ack.state);
|
||||
} else if (isAuctionResyncRecommended(ack)) {
|
||||
resyncAuctionState();
|
||||
}
|
||||
// 2) 자동 재시도: "낡은 화면 때문에 거부"였고 동기 rebaseline 소스(state)가
|
||||
// 있을 때만 1회. assignedPosition 등 원래 payload는 유지하고 관측값/요청
|
||||
// id만 새로 만든다. 재시도 시에는 중간 에러 문구를 띄우지 않는다(무음 복구).
|
||||
@@ -605,6 +665,41 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
Boolean(ack.state) &&
|
||||
isAuctionResyncRecommended(ack) &&
|
||||
retryAttempt < 1;
|
||||
// 거부 시 "클라가 보낸 관측 revision"과 "서버가 동봉한 진짜 state"를 함께
|
||||
// 기록한다. observedRevision < serverRevision 이면 stale-client CONFLICT 확정.
|
||||
addNewRelicPageAction('AuctionClientActionRejected', {
|
||||
matchId: matchId ?? 'none',
|
||||
action: eventName,
|
||||
retryAttempt,
|
||||
rejectionReason:
|
||||
ack?.auctionRejectionReason ?? ack?.code ?? 'unknown',
|
||||
rejectionCode: ack?.code ?? 'none',
|
||||
resyncRecommended: isAuctionResyncRecommended(ack),
|
||||
hasAckState: Boolean(ack?.state),
|
||||
willAutoRetry: canAutoRetry,
|
||||
sentRevision:
|
||||
typeof payload.clientObservedRevision === 'number'
|
||||
? payload.clientObservedRevision
|
||||
: -1,
|
||||
sentOrderIndex:
|
||||
typeof payload.clientObservedCurrentAuctionPlayerOrderIndex ===
|
||||
'number'
|
||||
? payload.clientObservedCurrentAuctionPlayerOrderIndex
|
||||
: -1,
|
||||
sentPlayerUserId:
|
||||
payload.clientObservedCurrentBidRoundPlayerUserId ?? 'none',
|
||||
sentPhase: payload.clientObservedPhase ?? 'none',
|
||||
...describeAuctionForTelemetry('observed', latestAuctionRef.current),
|
||||
...describeAuctionForTelemetry('server', ack?.state ?? null),
|
||||
});
|
||||
// 1) rebaseline: 서버가 동봉한 최신 state를 즉시 반영(없으면 join으로 재요청).
|
||||
// commitAuctionState는 latestAuctionRef를 동기로 갱신하므로, 이후
|
||||
// buildAuctionActionPayload는 최신 관측값(revision/phase/선수)을 읽는다.
|
||||
if (ack.state) {
|
||||
commitAuctionState(ack.state, 'action-reject-rebaseline');
|
||||
} else if (isAuctionResyncRecommended(ack)) {
|
||||
resyncAuctionState();
|
||||
}
|
||||
if (canAutoRetry) {
|
||||
emitAuctionAction(
|
||||
eventName,
|
||||
@@ -621,7 +716,17 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
clearPendingActionRequest(
|
||||
ack.auctionActionRequestId ?? auctionActionRequestId,
|
||||
);
|
||||
commitAuctionState(ackState);
|
||||
addNewRelicPageAction('AuctionClientActionAck', {
|
||||
matchId: matchId ?? 'none',
|
||||
action: eventName,
|
||||
retryAttempt,
|
||||
sentRevision:
|
||||
typeof payload.clientObservedRevision === 'number'
|
||||
? payload.clientObservedRevision
|
||||
: -1,
|
||||
...describeAuctionForTelemetry('server', ackState),
|
||||
});
|
||||
commitAuctionState(ackState, 'action-ack');
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -754,6 +859,58 @@ function resolveCurrentBidPointAmount(auction: ApiAuction): number {
|
||||
return Number.isFinite(bidPointAmount) ? bidPointAmount : 0;
|
||||
}
|
||||
|
||||
type AuctionTelemetryAttributes = Record<string, string | number | boolean | null>;
|
||||
|
||||
function readAuctionHistorySequence(auction: ApiAuction | null | undefined) {
|
||||
const value = (auction as { currentAuctionHistorySequence?: unknown } | null)
|
||||
?.currentAuctionHistorySequence;
|
||||
return typeof value === 'number' ? value : -1;
|
||||
}
|
||||
|
||||
function summarizeAuctionTeams(auction: ApiAuction | null | undefined) {
|
||||
const teams = Array.isArray(auction?.auctionTeams) ? auction.auctionTeams : [];
|
||||
let assignedMemberCount = 0;
|
||||
for (const team of teams) {
|
||||
const members = (team as { members?: unknown[] }).members;
|
||||
if (Array.isArray(members)) assignedMemberCount += members.length;
|
||||
}
|
||||
return { teamCount: teams.length, assignedMemberCount };
|
||||
}
|
||||
|
||||
// New Relic로 보내기 위해 경매 상태를 평탄한 속성 집합으로 요약한다.
|
||||
// prefix로 두 상태(예: 현재 vs 수신)를 한 이벤트에 같이 실어 revision 어긋남을
|
||||
// 한눈에 비교할 수 있게 한다.
|
||||
function describeAuctionForTelemetry(
|
||||
prefix: string,
|
||||
auction: ApiAuction | null | undefined,
|
||||
): AuctionTelemetryAttributes {
|
||||
const teamSummary = summarizeAuctionTeams(auction);
|
||||
return {
|
||||
[`${prefix}Revision`]:
|
||||
typeof auction?.revision === 'number' ? auction.revision : -1,
|
||||
[`${prefix}HistorySequence`]: readAuctionHistorySequence(auction),
|
||||
[`${prefix}Phase`]: auction?.phase ?? 'unknown',
|
||||
[`${prefix}LifecycleId`]: auction?.auctionLifecycleId ?? 'none',
|
||||
[`${prefix}OrderIndex`]:
|
||||
typeof auction?.currentAuctionPlayerOrderIndex === 'number'
|
||||
? auction.currentAuctionPlayerOrderIndex
|
||||
: -1,
|
||||
[`${prefix}PlayerUserId`]: auction?.currentBidRoundPlayerUserId ?? 'none',
|
||||
[`${prefix}BidAmount`]: auction
|
||||
? resolveCurrentBidPointAmount(auction)
|
||||
: -1,
|
||||
[`${prefix}BidderTeamIndex`]:
|
||||
typeof auction?.currentHighestBidderTeamIndex === 'number'
|
||||
? auction.currentHighestBidderTeamIndex
|
||||
: typeof auction?.currentBidderTeamIndex === 'number'
|
||||
? auction.currentBidderTeamIndex
|
||||
: -1,
|
||||
[`${prefix}TeamCount`]: teamSummary.teamCount,
|
||||
[`${prefix}AssignedMemberCount`]: teamSummary.assignedMemberCount,
|
||||
[`${prefix}ForceResync`]: Boolean(auction?.shouldForceAuctionStateResync),
|
||||
};
|
||||
}
|
||||
|
||||
function shouldApplyIncomingAuctionState(
|
||||
current: ApiAuction | null,
|
||||
incoming: ApiAuction,
|
||||
|
||||
Reference in new issue
Block a user