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

[v22.x backport] src: add cli option to exclude env vars on dr #56055

Merged
merged 3 commits into from
Dec 10, 2024
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
21 changes: 21 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,26 @@ changes:

Location at which the report will be generated.

### `--report-exclude-env`

<!-- YAML
added: REPLACEME
-->

When `--report-exclude-env` is passed the diagnostic report generated will not
contain the `environmentVariables` data.

### `--report-exclude-network`

<!-- YAML
added:
- v22.0.0
- v20.13.0
-->

Exclude `header.networkInterfaces` from the diagnostic report. By default
this is not set and the network interfaces are included.

### `--report-filename=filename`

<!-- YAML
Expand Down Expand Up @@ -3136,6 +3156,7 @@ one is included in the list below.
* `--redirect-warnings`
* `--report-compact`
* `--report-dir`, `--report-directory`
* `--report-exclude-env`
* `--report-exclude-network`
* `--report-filename`
* `--report-on-fatalerror`
Expand Down
10 changes: 10 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -3478,6 +3478,16 @@ const { report } = require('node:process');
console.log(`Report on exception: ${report.reportOnUncaughtException}`);
```

### `process.report.excludeEnv`

<!-- YAML
added: REPLACEME
-->

* {boolean}

If `true`, a diagnostic report is generated without the environment variables.

### `process.report.signal`

<!-- YAML
Expand Down
137 changes: 115 additions & 22 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/55697

Check warning on line 14 in doc/api/report.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Added `--report-exclude-env` option for excluding environment variables from report generation.
- version: v22.0.0
pr-url: https://github.com/nodejs/node/pull/51645
description: Added `--report-exclude-network` option for excluding networking operations that can slow down report generation in some cases.
Expand Down Expand Up @@ -342,28 +345,6 @@
"writeQueueSize": 0,
"readable": true,
"writable": true
},
{
"type": "tcp",
"is_active": true,
"is_referenced": true,
"address": "0x000055e70fcd68c8",
"localEndpoint": {
"host": "ip6-localhost",
"ip6": "::1",
"port": 52266
},
"remoteEndpoint": {
"host": "ip6-localhost",
"ip6": "::1",
"port": 38573
},
"sendBufferSize": 2626560,
"recvBufferSize": 131072,
"fd": 25,
"writeQueueSize": 0,
"readable": false,
"writable": false
}
],
"workers": [],
Expand Down Expand Up @@ -507,6 +488,10 @@
in `libuv.*.(remote|local)Endpoint.host` from the diagnostic report.
By default this is not set and the network interfaces are included.

* `--report-exclude-env` Exclude `environmentVariables` from the
diagnostic report. By default this is not set and the environment
variables are included.

A report can also be triggered via an API call from a JavaScript application:

```js
Expand Down Expand Up @@ -592,11 +577,119 @@
in associating the report dump with the runtime state if generated multiple
times for the same Node.js process.

## Report Version

Diagnostic report has an associated single-digit version number (`report.header.reportVersion`),
uniquely representing the report format. The version number is bumped
when new key is added or removed, or the data type of a value is changed.
Report version definitions are consistent across LTS releases.

### Version history

#### Version 4

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/55697

Check warning on line 594 in doc/api/report.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Added `--report-exclude-env` option for excluding environment variables from report generation.
-->

New fields `ipv4` and `ipv6` are added to `tcp` and `udp` libuv handles endpoints. Examples:

```json
{
"libuv": [
{
"type": "tcp",
"is_active": true,
"is_referenced": true,
"address": "0x000055e70fcb85d8",
"localEndpoint": {
"host": "localhost",
"ip4": "127.0.0.1", // new key
"port": 48986
},
"remoteEndpoint": {
"host": "localhost",
"ip4": "127.0.0.1", // new key
"port": 38573
},
"sendBufferSize": 2626560,
"recvBufferSize": 131072,
"fd": 24,
"writeQueueSize": 0,
"readable": true,
"writable": true
},
{
"type": "tcp",
"is_active": true,
"is_referenced": true,
"address": "0x000055e70fcd68c8",
"localEndpoint": {
"host": "ip6-localhost",
"ip6": "::1", // new key
"port": 52266
},
"remoteEndpoint": {
"host": "ip6-localhost",
"ip6": "::1", // new key
"port": 38573
},
"sendBufferSize": 2626560,
"recvBufferSize": 131072,
"fd": 25,
"writeQueueSize": 0,
"readable": false,
"writable": false
}
]
}
```

#### Version 3

<!-- YAML
changes:
- version:
- v19.1.0
- v18.13.0
pr-url: https://github.com/nodejs/node/pull/45254

Check warning on line 658 in doc/api/report.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Add more memory info.
-->

The following memory usage keys are added to the `resourceUsage` section.

```json
{
"resourceUsage": {
"rss": "35766272",
"free_memory": "1598337024",
"total_memory": "17179869184",
"available_memory": "1598337024",
"constrained_memory": "36624662528"
}
}
```

#### Version 2

<!-- YAML
changes:
- version:
- v13.9.0
- v12.16.2
pr-url: https://github.com/nodejs/node/pull/31386

Check warning on line 683 in doc/api/report.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Workers are now included in the report.
-->

Added [`Worker`][] support. Refer to [Interaction with workers](#interaction-with-workers) section for more details.

#### Version 1

This is the first version of the diagnostic report.

## Configuration

Additional runtime configuration of report generation is available via
Expand Down
7 changes: 7 additions & 0 deletions lib/internal/process/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ const report = {

nr.setReportOnUncaughtException(trigger);
},
get excludeEnv() {
return nr.getExcludeEnv();
},
set excludeEnv(b) {
validateBoolean(b, 'excludeEnv');
nr.setExcludeEnv(b);
},
};

function addSignalHandler(sig) {
Expand Down
4 changes: 4 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,10 @@ inline bool Environment::is_in_heapsnapshot_heap_limit_callback() const {
return is_in_heapsnapshot_heap_limit_callback_;
}

inline bool Environment::report_exclude_env() const {
return options_->report_exclude_env;
}

inline void Environment::AddHeapSnapshotNearHeapLimitCallback() {
DCHECK(!heapsnapshot_near_heap_limit_callback_added_);
heapsnapshot_near_heap_limit_callback_added_ = true;
Expand Down
2 changes: 2 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,8 @@ class Environment final : public MemoryRetainer {
inline void set_heap_snapshot_near_heap_limit(uint32_t limit);
inline bool is_in_heapsnapshot_heap_limit_callback() const;

inline bool report_exclude_env() const;

inline void AddHeapSnapshotNearHeapLimitCallback();

inline void RemoveHeapSnapshotNearHeapLimitCallback(size_t heap_limit);
Expand Down
5 changes: 5 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
&EnvironmentOptions::tls_max_v1_3,
kAllowedInEnvvar);

AddOption("--report-exclude-env",
"Exclude environment variables when generating report"
" (default: false)",
&EnvironmentOptions::report_exclude_env,
kAllowedInEnvvar);
AddOption("--report-exclude-network",
"exclude network interface diagnostics."
" (default: false)",
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class EnvironmentOptions : public Options {

std::vector<std::string> user_argv;

bool report_exclude_env = false;
bool report_exclude_network = false;

inline DebugOptions* get_debug_options() { return &debug_options_; }
Expand Down
Loading
Loading