Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: accept logging path name as a identifier #379

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ class ClinicDoctor extends events.EventEmitter {
sampleInterval = 10,
detectPort = false,
debug = false,
dest = null
dest = null,
name
} = settings

this.collectDelay = collectDelay
this.sampleInterval = sampleInterval
this.detectPort = detectPort
this.debug = debug
this.path = dest
this.name = name

// cannot calculate ELU on these node versions
this.collectLoopUtilization = semver.gt(process.version, 'v14.10.0')
Expand Down Expand Up @@ -85,6 +87,10 @@ class ClinicDoctor extends events.EventEmitter {
customEnv.NODE_CLINIC_DOCTOR_DATA_PATH = this.path
}

if (this.name) {
customEnv.NODE_CLINIC_DOCTOR_NAME = this.name
}

const proc = spawn(args[0], args.slice(1), {
stdio,
env: Object.assign({}, process.env, customEnv)
Expand All @@ -99,7 +105,7 @@ class ClinicDoctor extends events.EventEmitter {
}

// get logging directory structure
const options = { identifier: proc.pid, path: this.path }
const options = { identifier: this.name || proc.pid, path: this.path }
const paths = getLoggingPaths(options)
// relay SIGINT to process
process.once('SIGINT', /* istanbul ignore next: SIGINT is only emitted at Ctrl+C on windows */ () => {
Expand Down
5 changes: 4 additions & 1 deletion injects/sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const getLoggingPaths = require('@clinic/clinic-common').getLoggingPaths('doctor
const ProcessStatEncoder = require('../format/process-stat-encoder.js')

// create encoding files and directory
const paths = getLoggingPaths({ path: process.env.NODE_CLINIC_DOCTOR_DATA_PATH, identifier: process.pid })
const paths = getLoggingPaths({
path: process.env.NODE_CLINIC_DOCTOR_DATA_PATH,
identifier: process.env.NODE_CLINIC_DOCTOR_NAME || process.pid
})

makeDir.sync(paths['/'])

Expand Down