-
Notifications
You must be signed in to change notification settings - Fork 16
HTTP Latency Histogram Metrics with Route Attribution #431
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
base: node-v24.x-nsolid-v6.x
Are you sure you want to change the base?
Changes from all commits
a430112
c77abf7
0740ccb
057a615
de43c62
b9bef78
59a7809
ced572b
0f3265d
a0bd220
3ed97d4
7ef9610
40ca725
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,7 @@ namespace node { | |
| namespace nsolid { | ||
| namespace grpc { | ||
|
|
||
| using ThreadMetricsMap = std::map<uint64_t, ThreadMetrics::MetricsStor>; | ||
| using CachedThreadMetricsMap = std::map<uint64_t, CachedThreadMetrics>; | ||
|
|
||
| constexpr uint64_t span_timer_interval = 1000; | ||
| constexpr size_t span_msg_q_min_size = 1000; | ||
|
|
@@ -250,7 +250,7 @@ void PopulateInfoEvent(grpcagent::InfoEvent* info_event, | |
|
|
||
| void PopulateMetricsEvent(grpcagent::MetricsEvent* metrics_event, | ||
| const ProcessMetrics::MetricsStor& proc_metrics, | ||
| const ThreadMetricsMap& env_metrics, | ||
| const CachedThreadMetricsMap& env_metrics, | ||
| const char* req_id) { | ||
| // Fill in the fields of the MetricsResponse. | ||
| PopulateCommon(metrics_event->mutable_common(), "metrics", req_id); | ||
|
|
@@ -261,8 +261,18 @@ void PopulateMetricsEvent(grpcagent::MetricsEvent* metrics_event, | |
|
|
||
| // As this is the cached we're sending, we pass the same value for prev_stor. | ||
| otlp::fill_proc_metrics(metrics, proc_metrics, proc_metrics, false); | ||
| for (const auto& [env_id, env_metrics_stor] : env_metrics) { | ||
| for (const auto& [env_id, cached_metrics] : env_metrics) { | ||
| const auto& env_metrics_stor = cached_metrics.stor; | ||
|
|
||
| otlp::fill_env_metrics(metrics, env_metrics_stor, false); | ||
| // Add exponential histogram metrics for HTTP latency. | ||
| otlp::fill_http_histograms( | ||
| metrics, | ||
| env_metrics_stor, | ||
| cached_metrics.http_client_points, | ||
| cached_metrics.http_server_points, | ||
| false, | ||
| cached_metrics.hist_start_ts_ms); | ||
| } | ||
|
|
||
| data.scope_metric_data_ = | ||
|
|
@@ -865,14 +875,17 @@ void GrpcAgent::env_deletion_cb_(SharedEnvInst envinst, | |
| EnvInst::Scope scp(envinst); | ||
| if (scp.Success()) { | ||
| bool creation = std::get<1>(tup); | ||
| uint64_t thread_id = GetThreadId(envinst); | ||
| if (creation) { | ||
| auto pair = agent->env_metrics_map_.emplace( | ||
| std::piecewise_construct, | ||
| std::forward_as_tuple(GetThreadId(envinst)), | ||
| std::forward_as_tuple(thread_id), | ||
| std::forward_as_tuple(envinst)); | ||
| ASSERT(pair.second); | ||
| } else { | ||
| agent->env_metrics_map_.erase(GetThreadId(envinst)); | ||
| agent->env_metrics_map_.erase(thread_id); | ||
| agent->thr_metrics_hist_prev_end_ts_ms_.erase(thread_id); | ||
| agent->thr_metrics_cache_.erase(thread_id); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -939,10 +952,35 @@ void GrpcAgent::env_deletion_cb_(SharedEnvInst envinst, | |
| data.resource_ = otlp::GetResource(); | ||
| std::vector<MetricData> metrics; | ||
|
|
||
| ThreadMetricsStor stor; | ||
| while (agent->thr_metrics_msg_q_.dequeue(stor)) { | ||
| ExtMetricsStor ext_stor; | ||
| while (agent->thr_metrics_msg_q_.dequeue(ext_stor)) { | ||
| auto& stor = ext_stor.stor; | ||
| otlp::fill_env_metrics(metrics, stor, false); | ||
| agent->thr_metrics_cache_.insert_or_assign(stor.thread_id, std::move(stor)); | ||
| uint64_t thread_id = stor.thread_id; | ||
| uint64_t start_ts_ms = 0; | ||
| auto prev_it = agent->thr_metrics_hist_prev_end_ts_ms_.find(thread_id); | ||
| if (prev_it != agent->thr_metrics_hist_prev_end_ts_ms_.end()) { | ||
| start_ts_ms = prev_it->second; | ||
| } | ||
| // Add exponential histogram metrics for HTTP latency. | ||
| otlp::fill_http_histograms( | ||
| metrics, | ||
| stor, | ||
| ext_stor.http_client_points, | ||
| ext_stor.http_server_points, | ||
| false, | ||
| start_ts_ms); | ||
| agent->thr_metrics_hist_prev_end_ts_ms_.insert_or_assign( | ||
| thread_id, | ||
| stor.timestamp); | ||
| agent->thr_metrics_cache_.insert_or_assign( | ||
| thread_id, | ||
| CachedThreadMetrics{ | ||
| std::move(stor), | ||
| start_ts_ms, | ||
| ext_stor.http_client_points, | ||
| ext_stor.http_server_points | ||
| }); | ||
|
Comment on lines
+955
to
+983
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop queued samples for threads that are already gone.
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| data.scope_metric_data_ = | ||
|
|
@@ -991,8 +1029,18 @@ void GrpcAgent::env_deletion_cb_(SharedEnvInst envinst, | |
| return; | ||
| } | ||
|
|
||
| if (agent->thr_metrics_msg_q_.enqueue(metrics->Get()) == 1) { | ||
| ASSERT_EQ(0, uv_async_send(&agent->metrics_msg_)); | ||
| uint64_t thread_id = metrics->thread_id(); | ||
| auto envinst_sp = EnvInst::GetInst(thread_id); | ||
| if (envinst_sp != nullptr) { | ||
| ExtMetricsStor ext_stor{ | ||
| metrics->Get(), | ||
| envinst_sp->http_client_histogram_points(), | ||
| envinst_sp->http_server_histogram_points() | ||
| }; | ||
|
|
||
| if (agent->thr_metrics_msg_q_.enqueue(std::move(ext_stor)) == 1) { | ||
| ASSERT_EQ(0, uv_async_send(&agent->metrics_msg_)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2080,6 +2128,7 @@ void GrpcAgent::setup_blocked_loop_hooks() { | |
|
|
||
| int GrpcAgent::setup_metrics_timer(uint64_t period) { | ||
| if (period == 0) { | ||
| thr_metrics_hist_prev_end_ts_ms_.clear(); | ||
| return metrics_timer_.stop(); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.