Skip to content

Commit

Permalink
Merge pull request #100 from monti-apm/feature/jobs
Browse files Browse the repository at this point in the history
Add Job Executor
  • Loading branch information
zodern authored Nov 22, 2024
2 parents 6adb7df + cbbcc25 commit d9b56d3
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 55 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/test-redis-oplog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ jobs:
matrix:
meteorRelease:
- '--release 1.11'
- '--release 1.12.1'
- '--release 2.1.1'
- '--release 2.2'
- '--release 2.3.2'
- '--release 2.4.1'
- '--release 2.5.6'
- '--release 2.6.1'
- '--release 2.7.3'
- '--release 2.8.2'
- '--release 2.9.0'
# Left empty to use latest version
-
- '--release 2.16'
env:
REDIS_OPLOG_SETTINGS: '{"debug":true}'
steps:
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,21 @@ jobs:
- '--release 2.7.3'
- '--release 2.8.2'
- '--release 2.9.0'
# Left empty to use latest version
-
- '--release 2.10.0'
- '--release 2.11.0'
- '--release 2.12'
- '--release 2.13.3'
- '--release 2.14'
- '--release 2.15'
- '--release 2.16'
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
node-version: '22.x'

- name: Install Dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.build*
node_modules/
.npm
.npm/.package-garbage-*
smart.lock
versions.json
.idea
.eslintcache
.envrc
/packages/*
/packages/*
1 change: 1 addition & 0 deletions .npm/package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions .npm/package/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This directory and the files immediately inside it are automatically generated
when you change this package's NPM dependencies. Commit the files in this
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
so that others run the same versions of sub-dependencies.

You should NOT check in the node_modules directory that Meteor automatically
creates; if you are using git, the .gitignore file tells git to ignore it.
198 changes: 198 additions & 0 deletions .npm/package/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ You should use the same method that you used to give the agent the app id and se
| eventStackTrace | EVENT_STACK_TRACE | false | If true, records a stack trace when an event starts. Slightly decreases server performance. |
| disableNtp | OPTIONS_DISABLE_NTP | false | Disable NTP time synchronization used to get the accurate time in case the server or client's clock is wrong |
| stalledTimeout | STALLED_TIMEOUT | 1800000 (30m) | Timeout used to detect when methods and subscriptions might be stalled (have been running for a long time and might never return). The value is in milliseconds, and can be disabled by setting it to 0 |
| proxy | MONTI_OPTIONS_PROXY | none | Allows you to connect to Monti APM using a proxy |
| disableInstrumentation | MONTI_DISABLE_INSTRUMENTATION | false | Disables instrumentation. Useful for disabling without uninstalling the package |
| proxy | OPTIONS_PROXY | none | Allows you to connect to Monti APM using a proxy |
| disableInstrumentation | DISABLE_INSTRUMENTATION | false | Disables recording most metrics and traces. Can be configured using Meteor.settings, or by env variable |


### Traces
Expand Down
53 changes: 29 additions & 24 deletions lib/auto_connect.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { Meteor } from 'meteor/meteor';

Kadira._connectWithEnv = function () {
const options = Kadira._parseEnv(process.env);
if (options.appId && options.appSecret) {
const envOptions = Kadira._parseEnv(process.env);
const montiSettings = Meteor.settings.monti || Meteor.settings.kadira;

Kadira._connectWithEnv = function (env) {
if (env.appId && env.appSecret) {
Kadira.connect(
options.appId,
options.appSecret,
options
env.appId,
env.appSecret,
env
);

Kadira.connect = function () {
throw new Error('Kadira has been already connected using credentials from Environment Variables');
throw new Error('Monti APM: already connected using credentials from Environment Variables');
};
}
};


Kadira._connectWithSettings = function () {
const montiSettings = Meteor.settings.monti || Meteor.settings.kadira;

Kadira._connectWithSettings = function (settings) {
if (
montiSettings &&
montiSettings.appId &&
montiSettings.appSecret
settings &&
settings.appId &&
settings.appSecret
) {
Kadira.connect(
montiSettings.appId,
montiSettings.appSecret,
montiSettings.options || {}
settings.appId,
settings.appSecret,
settings.options || {}
);

Kadira.connect = function () {
throw new Error('Kadira has been already connected using credentials from Meteor.settings');
throw new Error('Monti APM: already connected using credentials from Meteor.settings');
};
}
};
Expand All @@ -40,11 +40,16 @@ Kadira._connectWithSettings = function () {
* We need to instrument this right away, and it's okay
* One reason for this is to call `setLabels()` function
* Otherwise, CPU profile can't see all our custom labeling
*
* Previously there was two log messages (one for instrumentation,
* and another for connection), this way we merged both of them.
*/
Kadira._startInstrumenting(function () {
Kadira._connectWithEnv();
Kadira._connectWithSettings();
});
let settingsOptions = montiSettings && montiSettings.options || {};
if (
envOptions.disableInstrumentation || settingsOptions.disableInstrumentation
) {
// eslint-disable-next-line no-console
console.log('Monti APM: Instrumentation is disabled. Metrics and traces will not be recorded.');
} else {
Kadira._startInstrumenting();
}

Kadira._connectWithEnv(envOptions);
Kadira._connectWithSettings(settingsOptions);
5 changes: 5 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const JobType = {
CPU_PROFILE: 'cpuProfile',
HEAP_SNAPSHOT: 'heapSnapshot',
ALLOCATION_PROFILE: 'allocationProfile'
};
4 changes: 4 additions & 0 deletions lib/environment_variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ Kadira._parseEnv._options = {
name: 'disableNtp',
parser: Kadira._parseEnv.parseBool,
},
MONTI_DISABLE_INSTRUMENTATION: {
name: 'disableInstrumentation',
parser: Kadira._parseEnv.parseBool
}
};
6 changes: 1 addition & 5 deletions lib/hijack/instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ import { hijackDBOps } from './db';
import { wrapRedisOplogObserveDriver } from './redis_oplog';

let instrumented = false;
Kadira._startInstrumenting = function (callback) {
if (Meteor.settings?.monti?.disableInstrumentation || process.env.MONTI_DISABLE_INSTRUMENTATION) {
console.log('Monti APM: Instrumentation is disabled.');
return;
}
Kadira._startInstrumenting = function (callback = () => {}) {
if (instrumented) {
callback();
return;
Expand Down
Loading

0 comments on commit d9b56d3

Please sign in to comment.