Skip to content

Commit 16b6242

Browse files
committed
change enableDetailedStats config type
1 parent 9d78202 commit 16b6242

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/config.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@ const index = {
2626
if (v === 'true' || v === 'false' || v === '') return
2727
if (v.includes('-')) {
2828
v.split('-').forEach(n => {
29-
if (isNaN(parseInt(n)) || !isFinite(parseInt(n))) throw new Error(`Invalid index: ${n}`)
29+
if (isNaN(parseInt(n)) || !isFinite(parseInt(n))) throw new Error(`Invalid string index: ${n}`)
3030
})
3131
return
3232
}
3333
if (v.includes(',')) {
3434
v.split(',').forEach(n => {
35-
if (isNaN(parseInt(n)) || !isFinite(parseInt(n))) throw new Error(`Invalid index: ${n}`)
35+
if (isNaN(parseInt(n)) || !isFinite(parseInt(n))) throw new Error(`Invalid string index: ${n}`)
3636
})
3737
return
3838
}
39-
if (isNaN(parseInt(v)) || !isFinite(parseInt(v))) throw new Error(`Invalid index: ${v}`)
39+
if (isNaN(parseInt(v)) || !isFinite(parseInt(v))) throw new Error(`Invalid string index: ${v}`)
40+
return
4041
} else if (typeof v === 'number' || typeof v === 'boolean') {
4142
return
4243
}
43-
throw new Error(`Invalid index: ${v}`)
44+
throw new Error(`Invalid index: "${v}" (type: ${typeof v})`)
4445
},
4546
}
4647

@@ -324,9 +325,10 @@ calculated using \`Date.now()\``,
324325
arg: 'start-timestamp',
325326
},
326327
enableDetailedStats: {
327-
doc: `If \`true\`, each individual participant stats values will be reported.`,
328-
format: 'Boolean',
329-
default: false,
328+
doc: `If detailed participant metrics values should be collected.`,
329+
format: 'index',
330+
default: '',
331+
nullable: true,
330332
env: 'ENABLE_DETAILED_STATS',
331333
arg: 'enable-detailed-stats',
332334
},

src/stats.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as zlib from 'zlib'
1414

1515
import { PageStatsNames, RtcStatsMetricNames, parseRtStatKey } from './rtcstats'
1616
import { Session } from './session'
17-
import { Scheduler, hideAuth, logger, toPrecision } from './utils'
17+
import { Scheduler, enabledForSession, hideAuth, logger, toPrecision } from './utils'
1818

1919
export { FastStats }
2020

@@ -321,7 +321,7 @@ export class Stats extends events.EventEmitter {
321321
readonly rtcStatsTimeout: number
322322
readonly customMetrics: Record<string, { labels?: string[] }> = {}
323323
readonly startTimestamp: number
324-
readonly enableDetailedStats: boolean
324+
readonly enableDetailedStats: boolean | string | number
325325
private readonly startTimestampString: string
326326

327327
readonly sessions = new Map<number, Session>()
@@ -443,7 +443,7 @@ export class Stats extends events.EventEmitter {
443443
serverSecret: string
444444
startSessionId: number
445445
startTimestamp: number
446-
enableDetailedStats: boolean
446+
enableDetailedStats: boolean | string | number
447447
customMetricsLabels?: string
448448
}) {
449449
super()
@@ -715,7 +715,7 @@ export class Stats extends events.EventEmitter {
715715
alertRules: {},
716716
}
717717

718-
if (this.enableDetailedStats) {
718+
if (this.enableDetailedStats !== false) {
719719
this.metrics[name].value = promCreateGauge(register, name, '', [
720720
'participantName',
721721
'trackId',
@@ -801,7 +801,7 @@ export class Stats extends events.EventEmitter {
801801
Object.values(stats.byCodec).forEach(s => s.reset())
802802
stats.byParticipantAndTrack = {}
803803
})
804-
for (const session of this.sessions.values()) {
804+
for (const [sessionId, session] of this.sessions.entries()) {
805805
this.collectedStatsConfig.url = `${hideAuth(session.url)}?${session.urlQuery}`
806806
this.collectedStatsConfig.pages += session.pages.size || 0
807807
const sessionStats = await session.updateStats()
@@ -827,7 +827,7 @@ export class Stats extends events.EventEmitter {
827827
}
828828
stats.push(value)
829829
// Push participant and track values.
830-
if (this.enableDetailedStats && participantName) {
830+
if (enabledForSession(sessionId, this.enableDetailedStats) && participantName) {
831831
collectedStats.byParticipantAndTrack[`${participantName}:${trackId || ''}`] = value
832832
}
833833
} else if (typeof value === 'string') {

0 commit comments

Comments
 (0)