Skip to content

Commit 6047dbf

Browse files
committed
fix: review comments
1 parent dbb2288 commit 6047dbf

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/cmd/traces.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getErrorMessage } from 'src/operator/utils'
99
import { env } from 'src/common/envalid'
1010

1111
const cmdName = getFilename(__filename)
12-
const { COLLECTION_INTERVAL_SECONDS, COLLECTION_DURATION_SECONDS } = env
12+
const { COLLECTION_INTERVAL_SECONDS, COLLECTION_DURATION_SECONDS, APL_OPERATOR_NAMESPACE, TRACES_REPORT_NAME } = env
1313
const COLLECTION_INTERVAL_MS = COLLECTION_INTERVAL_SECONDS * 1000
1414
const COLLECTION_DURATION_MS = COLLECTION_DURATION_SECONDS * 1000
1515
interface ResourceReport {
@@ -414,17 +414,15 @@ export async function collectTraces(): Promise<void> {
414414
...(collectionErrors.length > 0 && { errors: collectionErrors }),
415415
}
416416

417-
// Store in ConfigMap
418-
const configMapName = 'apl-traces-report'
419-
const targetNamespace = 'apl-operator'
420-
421417
if (failedResources.length === 0) {
422418
d.info('No failing resources found. Your APL instance seems to be healthy.')
423419
}
424420

425421
// Always write the report to ConfigMap (even when healthy, for timestamp visibility)
426-
await writeReportToConfigMap(configMapName, targetNamespace, report)
427-
d.info(`Trace report stored in ConfigMap ${targetNamespace}/${configMapName} (${failedResources.length} issues)`)
422+
await writeReportToConfigMap(TRACES_REPORT_NAME, APL_OPERATOR_NAMESPACE, report)
423+
d.info(
424+
`Trace report stored in ConfigMap ${APL_OPERATOR_NAMESPACE}/${TRACES_REPORT_NAME} (${failedResources.length} issues)`,
425+
)
428426
} catch (error) {
429427
d.error('Failed to collect traces:', error)
430428
throw error
@@ -450,11 +448,8 @@ async function getCollectionStartTime(name: string, namespace: string): Promise<
450448

451449
export async function runTraceCollectionLoop(): Promise<void> {
452450
const d = terminal('cmd:traces:runTraceCollectionLoop')
453-
const configMapName = 'apl-traces-report'
454-
const namespace = 'apl-operator'
455-
456451
// Get collection start time from ConfigMap creation timestamp
457-
const startTime = await getCollectionStartTime(configMapName, namespace)
452+
const startTime = await getCollectionStartTime(TRACES_REPORT_NAME, APL_OPERATOR_NAMESPACE)
458453
const endTime = startTime + COLLECTION_DURATION_MS
459454
const now = Date.now()
460455

@@ -474,11 +469,8 @@ export async function runTraceCollectionLoop(): Promise<void> {
474469
d.warn('Failed to collect traces:', getErrorMessage(error))
475470
}
476471

477-
const remainingTime = endTime - Date.now()
478-
if (remainingTime > 0) {
479-
const waitTime = Math.min(COLLECTION_INTERVAL_MS, remainingTime)
480-
await new Promise((resolve) => setTimeout(resolve, waitTime))
481-
}
472+
// Wait 5 minutes before next collection
473+
await new Promise((resolve) => setTimeout(resolve, COLLECTION_INTERVAL_MS))
482474
}
483475

484476
d.info('Trace collection loop completed')

src/common/envalid.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ export const cliEnvSpec = {
5757
}),
5858
COLLECTION_DURATION_SECONDS: num({ desc: 'Traces collection duration (default 30 min)', default: 1800 }),
5959
COLLECTION_INTERVAL_SECONDS: num({ desc: 'Traces collection interval (default 5 min)', default: 300 }),
60+
APL_OPERATOR_NAMESPACE: str({
61+
desc: 'Kubernetes namespace where the APL Operator is installed',
62+
default: 'apl-operator',
63+
}),
64+
TRACES_REPORT_NAME: str({
65+
desc: 'Kubernetes config map name for reporting traces',
66+
default: 'apl-traces-report',
67+
}),
6068
}
6169

6270
export function cleanEnv<T>(spec: { [K in keyof T]: ValidatorSpec<T[K]> }, options?: CleanOptions<T>) {

0 commit comments

Comments
 (0)