Skip to content

Commit

Permalink
run: allow profiling to be explicitly started
Browse files Browse the repository at this point in the history
It used to be profiling was only started when StrongOps was started.

This caused problems for metrics and other users of the agent, because
when agent is no started first, it doesn't behave well. In particular,
it doesn't monkey patch anything, causing metrics to be lacking probe
metrics, and agent traces and express records not be available.
  • Loading branch information
sam-github committed Feb 19, 2015
1 parent 7d7acc4 commit 4debc61
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ signalled with SIGHUP, see
### slc run

``` text
usage: slc run [options] [app [app-options...]]
usage: slr [options] [app [app-options...]]
Run an app, allowing it to be profiled (using StrongOps) and supervised.
Expand All @@ -203,14 +202,15 @@ Options:
Disable timestamping of supervisor log messages.
--syslog Send supervisor and collected worker logs to syslog,
unsupported on Windows.
--metrics BACKEND Send metrics to custom backend (default is no custom).
--metrics BACKEND Report metrics to custom backend. Implies `--profile`.
-p,--pid FILE Write supervisor's pid to FILE, failing if FILE already
has a valid pid in it (default is no pid file).
--cluster N Set the cluster size (default is off, but see below).
--no-profile Disable reporting profile data to StrongOps (default is to
profile if registration data is found). Does not affect
local reporting using --metrics option.
-C,--control CTL Listen for local control messages on CTL (default `pmctl),
--profile Start the agent. Report to StrongOps if registration data
is found (this is the default).
--no-profile Do not start the agent, do not report to StrongOps,
do not report metrics.
-C,--control CTL Listen for local control messages on CTL (default `pmctl`),
only supported when clustered.
--no-control Do not listen for local control messages.
Expand Down
45 changes: 36 additions & 9 deletions bin/sl-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,42 @@ process.on('disconnect', function() {
var config = require('../lib/config'); // May exit, depending on argv
var log = config.logger;

if(!config.profile) {
if(config.isMaster) {
log.error('supervisor running without StrongOps (unprofiled)');
}
} else {
require('strong-agent').profile(undefined, undefined, {
quiet: config.isWorker, // Quiet in worker, to avoid repeated log messages
logger: config.logger,
});
var agent = require('../lib/agent');
var agentOptions = {
quiet: config.isWorker, // Quiet in worker, to avoid repeated log messages
logger: config.logger,
};

switch(config.profile) {
case false: // Profiling explicitly disabled.
if(config.isMaster) {
log.error('supervisor running without profiling');
}
break;

case undefined: // No explicit request for profiling or metrics.
// Start with StrongOps if app is registered. This will print warning
// messages to the console if the api key is not found, which is backwards
// compatible.
agent().profile(undefined, undefined, agentOptions);
// Otherwise, just start. This is a no-op if it is already started.
agent().start();
break;

case true: // Profiling or metrics explicitly enabled.
agent().configure(agentOptions);
// Only try to start StrongOps if they have registered, to avoid legacy
// warning messages. If an app is missing a name, profile may still fail
// to start, so drop-through to start(). We must re-supply options.
if (agent().config.key)
agent().profile(undefined, undefined, agentOptions);
// Otherwise, just start. This is a no-op if already started.
agent().start();
break;

default:
assert(false, 'invalid profile value');
break;
}

if((config.clustered && config.isMaster) || config.detach){
Expand Down
11 changes: 6 additions & 5 deletions bin/sl-run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ Options:
Disable timestamping of supervisor log messages.
--syslog Send supervisor and collected worker logs to syslog,
unsupported on Windows.
--metrics BACKEND Send metrics to custom backend (default is no custom).
--metrics BACKEND Report metrics to custom backend. Implies `--profile`.
-p,--pid FILE Write supervisor's pid to FILE, failing if FILE already
has a valid pid in it (default is no pid file).
--cluster N Set the cluster size (default is off, but see below).
--no-profile Disable reporting profile data to StrongOps (default is to
profile if registration data is found). Does not affect
local reporting using --metrics option.
-C,--control CTL Listen for local control messages on CTL (default `pmctl),
--profile Start the agent. Report to StrongOps if registration data
is found (this is the default).
--no-profile Do not start the agent, do not report to StrongOps,
do not report metrics.
-C,--control CTL Listen for local control messages on CTL (default `pmctl`),
only supported when clustered.
--no-control Do not listen for local control messages.

Expand Down
6 changes: 5 additions & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.parse = function parse(argv) {
HELP: exports.HELP,
argv: argv, // process.argv stripped of command...
args: [ '.' ], // app app-options...
profile: true,
profile: process.env.STRONGLOOP_METRICS ? true : undefined,
channel: 'runctl',
log: false,
metrics: null,
Expand Down Expand Up @@ -75,10 +75,12 @@ exports.parse = function parse(argv) {
i++;
options.metrics = options.metrics || []
options.metrics.push(argv[i]);
options.profile = true;
}
else if(/^--metrics=/.test(option)) {
options.metrics = options.metrics || []
options.metrics.push(value(option));
options.profile = true;
}
else if(option === '--pid' || option === '-p') {
i++;
Expand All @@ -92,6 +94,8 @@ exports.parse = function parse(argv) {
}
else if(option === '--no-profile') {
options.profile = false;
options.metrics = null;
delete process.env.STRONGLOOP_METRICS;
}
else if(option === '--cluster') {
i++;
Expand Down

0 comments on commit 4debc61

Please sign in to comment.