Visitar URL original
feat(metrics): measure sink CPU usage by gwenaskell · Pull Request #27097 · vectordotdev/vector · GitHub
Skip to content

feat(metrics): measure sink CPU usage - #27097

Draft
gwenaskell wants to merge 5 commits into
masterfrom
yoenn.burban/sink-cpu-usage
Draft

gwenaskell wants to merge 5 commits into
masterfrom
yoenn.burban/sink-cpu-usage

Conversation

@gwenaskell

@gwenaskell gwenaskell commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends the per-component component_cpu_usage_ns_total metric (#25317) to sinks, including the tasks they spawn.

Stacked on #27104 (counter inheritance through a thread-local, spawn_timed / spawn_timed_without_span): review that one first.

Most sink CPU does not run in the sink task: encoding and compression happen in ConcurrentMap tasks (request_builder), and TLS encryption and socket writes in hyper's per-connection tasks. Timing only the sink task would miss most of it.

  • Sinks: new measure_cpu_usage option; the sink task is wrapped with cpu_timed and its build() runs under cpu_scoped.
  • Subtasks now attributed:
    • ConcurrentMap (request_builder / concurrent_map)
    • hyper client connections and pool tasks, via vector_http::CpuTimedExecutor on the HttpClient pool and the vector sink's Http2Client
    • server connections spawned by crate::http::serve (used by prometheus_exporter; sources have no counter, so they are unaffected)
    • legacy BatchSink service calls
    • tower Buffer worker of distributed services (Buffer::pair instead of BufferLayer)
    • per-sink background tasks: splunk_hec acks, datadog_traces APM stats, redis sentinel repair, websocket_server, prometheus_exporter server, blackhole reporter

Windows accuracy: the measure_cpu_usage doc of sinks carries the same Windows caveat as transforms (see #27104).

Not covered

  • librdkafka native threads (kafka sink compression and network I/O)
  • tasks spawned internally by the AWS SDK and tonic
  • spawn_blocking: the closure runs on a blocking-pool thread, outside any timed poll. Our own call sites (dns.rs, kafka healthcheck) could be wrapped in a follow-up, but two indirect uses cannot be covered, because the spawn_blocking call happens inside the dependency with no hook:
    • tokio::fs writes in the file sink (the write syscall and buffer copy; compression stays in the sink task and is counted)
    • hyper's default DNS resolver for HTTP sinks (one lookup per new connection)

References

Related: #25317
Depends on: #27104

Vector configuration

sinks:
  out:
    type: http
    inputs: [in]
    uri: https://example.com
    encoding:
      codec: json
    measure_cpu_usage: true

How did you test this PR?

  • New topology test component_cpu_usage_emitted_sink: the mock completion sink burns CPU in a spawn_timed subtask; the existing no-measure test also checks the sink.
  • cargo test on cpu_metrics, topology::test, sinks::util, http, vector-http and the touched sinks/transforms; clippy on the touched feature set.

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

Contributor Guidelines

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Before pushing, follow our pre-push guidance.
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.

@github-actions github-actions Bot added docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. domain:topology Anything related to Vector's topology code domain:transforms Anything related to Vector's transform components domain:sinks Anything related to Vector's sinks domain:external docs Anything related to Vector's external, public documentation labels Nov 7, 2026
@gwenaskell
gwenaskell force-pushed the yoenn.burban/sink-cpu-usage branch from 0c60f93 to 4fea25c Compare November 7, 2026 16:04
The CPU counter of the component task being polled is kept in a
thread-local, and spawn_timed reads it at spawn time instead of taking it
as an argument. Transforms build() runs under a non-measuring scope so that
tasks spawned at build time inherit the counter.

Also document that CPU usage is a rough estimate on Windows.
@gwenaskell
gwenaskell force-pushed the yoenn.burban/sink-cpu-usage branch from b992d72 to d62ed9e Compare November 9, 2026 16:30
@gwenaskell gwenaskell changed the title feat(metrics): measure sink CPU usage, including spawned subtasks feat(metrics): measure sink CPU usage Nov 9, 2026
@gwenaskell
gwenaskell changed the base branch from master to yoenn.burban/cpu-timer-inheritance November 9, 2026 16:30
Add `measure_cpu_usage` to sinks. Sink subtasks (request building, hyper
connections, tower buffer worker, per-sink background tasks) are spawned
with the CPU-timed spawn helpers so that they are attributed to the sink.

Hyper connection tasks are spawned through `vector_http::CpuTimedExecutor`.
@gwenaskell
gwenaskell force-pushed the yoenn.burban/sink-cpu-usage branch from d62ed9e to 77b3478 Compare November 12, 2026 09:37
@github-actions github-actions Bot removed the domain:transforms Anything related to Vector's transform components label Nov 12, 2026
Base automatically changed from yoenn.burban/cpu-timer-inheritance to master November 13, 2026 10:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. domain:external docs Anything related to Vector's external, public documentation domain:sinks Anything related to Vector's sinks domain:topology Anything related to Vector's topology code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant