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

Node v18.20.4 nsolid v5.3.4 release #190

Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/commit-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
get_mergeable_prs:
permissions:
pull-requests: read
if: github.repository == 'nodejs/node'
if: github.repository == 'nodesource/nsolid'
runs-on: ubuntu-latest
outputs:
numbers: ${{ steps.get_mergeable_prs.outputs.numbers }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Lint JavaScript files
run: NODE=$(command -v node) make lint-js
- name: Get release version numbers
if: ${{ github.event.pull_request && github.event.pull_request.base.ref == github.event.pull_request.base.repo.default_branch }}
if: ${{ github.event.pull_request && github.event.pull_request.base.ref == github.event.pull_request.base.repo.default_branch && false }}
id: get-released-versions
run: ./tools/lint-md/list-released-versions-from-changelogs.mjs >> $GITHUB_OUTPUT
- name: Lint markdown files
Expand Down
55 changes: 50 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ as follows:
| v20.x.x | v5.x.x |
| v22.x.x | v5.x.x |

[^*]: Significant breaking changes or the introduction of substantial features
will drive the MAJOR version increments in N|Solid. Pre v5.0.0 versions of
N|Solid are proprietary, and there will be no further enhancements to these
closed versions.

When there is a Node.js release, there will always be an associated N|Solid
release. This typically is made within 24 hours of the upstream Node.js release.
See the next section for more details on how the versions work and the
Expand Down Expand Up @@ -139,6 +134,18 @@ releases addressing crucial issues in N|Solid. N|Solid strives to align its
feature releases as closely as possible with the Node.js release schedule,
promoting harmony and predictability in the release cycles.

### Landing approved Pull Requests

Currently, N|Solid don't use the `commit-queue` label for landing PRs
on _default_ branch. Once the PR is mergeable a maintainer can land it using
`node-core-utils` to include the expected metadata.

```console
$ ncu-config set readme $(PWD)/CONTRIBUTING.md
$ ncu-config set branch node-v20.x-nsolid-v5.x
$ git node land https://github.com/nodesource/nsolid/pull/X
```

## Technical Priorities

The N|Solid project aims to extend Node.js functionality to provide a unified
Expand Down Expand Up @@ -219,6 +226,39 @@ versions of Node.js with safe Buffer allocation.
This type of change has a lot of potential, but also faces the biggest uphill
battle towards becoming a part of the project.

<a id="current-project-team-members"></a>

## Current project team members

<!-- #### TSC voting members -->

<!-- #### TSC regular members -->

<!-- #### TSC emeriti members -->

<!--lint disable prohibited-strings-->

### Collaborators

<!-- node-core-utils and find-inactive-tsc.mjs depend on the format of the TSC
list. If the format changes, those utilities need to be tested and
updated. -->

* [edsadr](https://github.com/edsadr) -
**Adrian Estrada** <<[email protected]>> (he/him)
* [juanarbol](https://github.com/juanarbol) -
**Juan José Arboleda** <<[email protected]>> (he/him)
* [RafaelGSS](https://github.com/RafaelGSS) -
**Rafael Gonzaga** <<[email protected]>> (he/him)
* [santigimeno](https://github.com/santigimeno) -
**Santiago Gimeno** <<[email protected]>> (he/him)
* [trevnorris](https://github.com/trevnorris) -
**Trevor Norris** <<[email protected]>>> - (he/him)
* [UlisesGascon](https://github.com/UlisesGascon) -
**Ulises Gascón** <<[email protected]>> (he/him)

<!-- #### Collaborator emeriti -->

<a id="developers-certificate-of-origin"></a>

## Developer's Certificate of Origin 1.1
Expand Down Expand Up @@ -248,3 +288,8 @@ By making a contribution to this project, I certify that:
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
</pre>

[^*]: Significant breaking changes or the introduction of substantial features
will drive the MAJOR version increments in N|Solid. Pre v5.0.0 versions of
N|Solid are proprietary, and there will be no further enhancements to these
closed versions.
60 changes: 60 additions & 0 deletions agents/otlp/src/otlp_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <chrono>
// NOLINTNEXTLINE(build/c++11)
#include <mutex>
#include <unordered_map>
#include "asserts-cpp/asserts.h"
#include "env-inl.h"
#include "nlohmann/json.hpp"
Expand Down Expand Up @@ -114,6 +115,28 @@ static void add_gauge(std::vector<MetricData>& metrics,
metrics.push_back(metric_data);
}

// NOLINTNEXTLINE(runtime/references)
static void add_summary(std::vector<MetricData>& metrics,
const time_point& start,
const time_point& end,
const char* name,
const char* unit,
InstrumentValueType type,
std::unordered_map<double, ValueType>&& values,
PointAttributes attrs = {}) {
opentelemetry::sdk::metrics::SummaryPointData summary_point_data{};
summary_point_data.quantile_values_ = std::move(values);
MetricData metric_data{
InstrumentDescriptor{
name, "", unit, InstrumentType::kSummary, type },
AggregationTemporality::kUnspecified,
SystemTimestamp{ start },
SystemTimestamp{ end },
std::vector<PointDataAttributes>{{ attrs, summary_point_data }}
};
metrics.push_back(metric_data);
}

InstrumentationScope* GetScope() {
static std::unique_ptr<InstrumentationScope> scope =
InstrumentationScope::Create("nsolid", NODE_VERSION "+ns" NSOLID_VERSION);
Expand Down Expand Up @@ -265,6 +288,43 @@ void fill_env_metrics(std::vector<MetricData>& metrics,
}
NSOLID_ENV_METRICS_NUMBERS(V)
#undef V

// Add the summary metrics separately.
add_summary(metrics,
process_start(),
end,
"gc_dur",
kNSUSecs,
InstrumentValueType::kDouble,
{{ 0.5, stor.gc_dur_us_median },
{ 0.99, stor.gc_dur_us99_ptile }},
attrs);
add_summary(metrics,
process_start(),
end,
"dns",
kNSMSecs,
InstrumentValueType::kDouble,
{{ 0.5, stor.dns_median }, { 0.99, stor.dns99_ptile }},
attrs);
add_summary(metrics,
process_start(),
end,
"http_client",
kNSMSecs,
InstrumentValueType::kDouble,
{{ 0.5, stor.http_client99_ptile },
{ 0.99, stor.http_client_median }},
attrs);
add_summary(metrics,
process_start(),
end,
"http_server",
kNSMSecs,
InstrumentValueType::kDouble,
{{ 0.5, stor.http_server_median },
{ 0.99, stor.http_server99_ptile }},
attrs);
}

void fill_log_recordable(LogsRecordable* recordable,
Expand Down
83 changes: 83 additions & 0 deletions agents/src/profile_collector.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "profile_collector.h"
#include "asserts-cpp/asserts.h"

namespace node {
namespace nsolid {

ProfileCollector::~ProfileCollector() {
profile_msg_->close_and_delete();
}

int ProfileCollector::StartCPUProfile(const CPUProfileOptions& options) {
return CpuProfiler::TakeProfile(GetEnvInst(options.thread_id),
options.duration,
profile_cb,
kCpu,
options,
weak_from_this());
}

int ProfileCollector::StartHeapProfile(const HeapProfileOptions& options) {
return Snapshot::StartTrackingHeapObjects(GetEnvInst(options.thread_id),
options.redacted,
options.track_allocations,
options.duration,
profile_cb,
kHeapProf,
options,
weak_from_this());
}

int ProfileCollector::StartHeapSampling(const HeapSamplingOptions& options) {
return Snapshot::StartSampling(GetEnvInst(options.thread_id),
options.sample_interval,
options.stack_depth,
options.flags,
options.duration,
profile_cb,
kHeapSampl,
options,
weak_from_this());
}

/*static*/
void ProfileCollector::profile_cb(int status,
std::string profile,
ProfileType type,
ProfileOptions options,
WeakProfileCollector collector_wp) {
SharedProfileCollector collector = collector_wp.lock();
if (collector == nullptr) {
return;
}

ProfileQStor qstor = {status, profile, type, std::move(options)};
if (collector->profile_msg_q_.enqueue(std::move(qstor)) == 1) {
ASSERT_EQ(0, collector->profile_msg_->send());
}
}

void ProfileCollector::initialize() {
int er = profile_msg_->init(
loop_,
+[](nsuv::ns_async*, WeakProfileCollector collector_wp) {
SharedProfileCollector collector = collector_wp.lock();
if (collector == nullptr) {
return;
}

collector->process_profiles();
},
weak_from_this());
ASSERT_EQ(0, er);
}

void ProfileCollector::process_profiles() {
ProfileQStor qstor;
while (profile_msg_q_.dequeue(qstor)) {
callback_(std::move(qstor));
}
}

} // namespace nsolid
} // namespace node
98 changes: 98 additions & 0 deletions agents/src/profile_collector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#ifndef AGENTS_SRC_PROFILE_COLLECTOR_H_
#define AGENTS_SRC_PROFILE_COLLECTOR_H_

#include <nsolid.h>
#include <nsolid/thread_safe.h>
#include "nlohmann/json.hpp"
#include "nsuv-inl.h"
#include <variant>
#include <vector>

namespace node {
namespace nsolid {

class ProfileCollector;

using SharedProfileCollector = std::shared_ptr<ProfileCollector>;
using WeakProfileCollector = std::weak_ptr<ProfileCollector>;

enum ProfileType {
kCpu = 0,
kHeapProf,
kHeapSampl,
kNumberOfProfileTypes
};

struct ProfileOptionsBase {
uint64_t thread_id;
uint64_t duration;
nlohmann::json metadata;
};

using CPUProfileOptions = ProfileOptionsBase;

struct HeapProfileOptions: public ProfileOptionsBase {
bool track_allocations = false;
bool redacted = false;
};

struct HeapSamplingOptions: public ProfileOptionsBase {
uint64_t sample_interval = 0;
int stack_depth = 0;
v8::HeapProfiler::SamplingFlags flags = v8::HeapProfiler::kSamplingNoFlags;
};

using ProfileOptions = std::variant<CPUProfileOptions,
HeapProfileOptions,
HeapSamplingOptions>;


/*
* ProfileCollector is a class that allows to start collecting profiles and
* report them to a callback function running in a specific uv_loop_t thread.
*/
class ProfileCollector: public std::enable_shared_from_this<ProfileCollector> {
public:
struct ProfileQStor {
int status;
std::string profile;
ProfileType type;
ProfileOptions options;
};

template <typename Cb, typename... Data>
explicit ProfileCollector(uv_loop_t* loop, Cb&& cb, Data&&... data):
loop_(loop),
profile_msg_(new nsuv::ns_async()) {
// Store the callback and data
callback_ = std::bind(std::forward<Cb>(cb),
std::placeholders::_1,
std::forward<Data>(data)...);
}
~ProfileCollector();

void initialize();

int StartCPUProfile(const CPUProfileOptions& options);
int StartHeapProfile(const HeapProfileOptions& options);
int StartHeapSampling(const HeapSamplingOptions& options);

private:
static void profile_cb(int status,
std::string profile,
ProfileType type,
ProfileOptions options,
WeakProfileCollector collector_wp);
void do_setup();
void process_profiles();

uv_loop_t* loop_;
nsuv::ns_async* profile_msg_;
TSQueue<ProfileQStor> profile_msg_q_;
std::function<void(ProfileQStor&&)> callback_ = nullptr;
};

} // namespace nsolid
} // namespace node

#endif // AGENTS_SRC_PROFILE_COLLECTOR_H_
Loading
Loading