Commit d5fe0e6
authored
admin: add an endpoint to dump spawned Tokio tasks (#595)
## Motivation
When debugging proxy issues, it can be useful to inspect the list of
currently spawned Tokio tasks and their states. This can be used
similarly to the thread or coroutine dumps provided by other languages'
runtimes.
## Solution
This branch adds a new endpoint to the proxy's admin server, `/tasks`,
that returns a dump of all tasks currently spawned on the Tokio runtime,
using the new Tracing instrumentation added in tokio-rs/tokio#2655, and
a work-in-progress [`tokio-trace`] crate that provides Tokio-specific
Tracing layers.
Currently, the `/tasks` admin endpoint records the following information
about each task:
* Whether it is a normal, local, or blocking task (not relevant to us
currently, since Linkerd does not use local or blocking tasks...but
we might eventually!)
* Whether the task is active (currently being polled) or idle (waiting
to be polled)
* The type of the future that was spawned
* The Tracing span context from which the task was spawned
* The total number of times the task has been polled
* Timing statistics about the task, including:
- The time in nanoseconds between when the task was spawned and when
it was first polled (essentially, measuring the Tokio scheduler's
latency)
- The total time in nanoseconds the task has existed
- The task's _busy time_ in nanoseconds (time it was actively being
polled)
- The tasks _idle time_ in nanoseconds (time it was _not_ being
polled)
In the future, Tokio will likely expose additional Tracing information,
which we'll be able to collect as well.
The task dump can be accessed either as an HTML table or as JSON. JSON
is returned if the request has an `Accept: application/json` header, or
whenever the path `/tasks.json` is requested; otherwise, the data is
rendered as an HTML table. Like the `/proxy-log-level` endpoint, access
is denied to requests coming from sources other than localhost, to help
restrict access to authorized users (since a high volume of requests for
task dumps could be used to starve the proxy).
Example JSON output (in Firefox Dev Edition's extremely nice GUI
JSON viewer):

Zoomed in on the timing data for a single task:

And HTML:

Because the task data is generated from Tracing spans emitted by Tokio,
the task spans must be enabled for it to be used. This can be done by
setting a trace filter that enables the `trace` level for the target
`tokio::task`, e.g.:
```
tokio::task=trace
```
or
```
tokio=trace
```
## Notes
* This branch depends on unreleased code from upstream, including a
Tokio change that has merged to master but not been published, and my
unreleased work-in-progress [`tokio-trace`] crate. Therefore, I've
pinned these upstreams to fixed Git SHAs, to guard against
dependencies changing under us unexpectedly.
* I considered requiring a build-time feature flag to enable this
feature, the way we do for the mock SO_ORIG_DST implementation for
testing. However, this would make it harder to use task tracking to
debug issues in proxies not built with the flag. I'm happy to change
this code to be feature flagged if we think that's the right approach.
[`tokio-trace`]: https://github.com/hawkw/tokio-trace
Closes linkerd/linkerd2#3803
Signed-off-by: Eliza Weisman <[email protected]>1 parent c234a92 commit d5fe0e6
File tree
12 files changed
+312
-102
lines changed- linkerd/app
- core
- src
- admin
- integration
- src
- src
12 files changed
+312
-102
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
541 | 541 | | |
542 | 542 | | |
543 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
544 | 553 | | |
545 | 554 | | |
546 | 555 | | |
| |||
752 | 761 | | |
753 | 762 | | |
754 | 763 | | |
| 764 | + | |
755 | 765 | | |
756 | 766 | | |
757 | 767 | | |
| |||
767 | 777 | | |
768 | 778 | | |
769 | 779 | | |
770 | | - | |
| 780 | + | |
771 | 781 | | |
772 | 782 | | |
773 | 783 | | |
| |||
789 | 799 | | |
790 | 800 | | |
791 | 801 | | |
| 802 | + | |
792 | 803 | | |
793 | 804 | | |
794 | 805 | | |
| |||
838 | 849 | | |
839 | 850 | | |
840 | 851 | | |
841 | | - | |
| 852 | + | |
| 853 | + | |
842 | 854 | | |
843 | 855 | | |
844 | 856 | | |
| 857 | + | |
845 | 858 | | |
846 | 859 | | |
847 | 860 | | |
| |||
1456 | 1469 | | |
1457 | 1470 | | |
1458 | 1471 | | |
1459 | | - | |
| 1472 | + | |
1460 | 1473 | | |
1461 | 1474 | | |
1462 | 1475 | | |
| |||
2155 | 2168 | | |
2156 | 2169 | | |
2157 | 2170 | | |
2158 | | - | |
| 2171 | + | |
2159 | 2172 | | |
2160 | | - | |
| 2173 | + | |
2161 | 2174 | | |
2162 | | - | |
| 2175 | + | |
2163 | 2176 | | |
2164 | 2177 | | |
2165 | | - | |
2166 | | - | |
| 2178 | + | |
2167 | 2179 | | |
2168 | 2180 | | |
2169 | 2181 | | |
| |||
2457 | 2469 | | |
2458 | 2470 | | |
2459 | 2471 | | |
2460 | | - | |
| 2472 | + | |
2461 | 2473 | | |
2462 | | - | |
| 2474 | + | |
2463 | 2475 | | |
2464 | 2476 | | |
2465 | | - | |
2466 | 2477 | | |
2467 | 2478 | | |
2468 | 2479 | | |
| |||
2478 | 2489 | | |
2479 | 2490 | | |
2480 | 2491 | | |
2481 | | - | |
| 2492 | + | |
2482 | 2493 | | |
2483 | | - | |
| 2494 | + | |
2484 | 2495 | | |
2485 | 2496 | | |
2486 | 2497 | | |
| |||
2497 | 2508 | | |
2498 | 2509 | | |
2499 | 2510 | | |
| 2511 | + | |
2500 | 2512 | | |
2501 | 2513 | | |
2502 | 2514 | | |
| |||
2586 | 2598 | | |
2587 | 2599 | | |
2588 | 2600 | | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
2589 | 2613 | | |
2590 | 2614 | | |
2591 | 2615 | | |
| |||
2706 | 2730 | | |
2707 | 2731 | | |
2708 | 2732 | | |
2709 | | - | |
| 2733 | + | |
2710 | 2734 | | |
2711 | | - | |
| 2735 | + | |
2712 | 2736 | | |
2713 | 2737 | | |
2714 | 2738 | | |
| |||
2718 | 2742 | | |
2719 | 2743 | | |
2720 | 2744 | | |
2721 | | - | |
| 2745 | + | |
2722 | 2746 | | |
2723 | | - | |
| 2747 | + | |
2724 | 2748 | | |
2725 | 2749 | | |
2726 | 2750 | | |
| |||
2729 | 2753 | | |
2730 | 2754 | | |
2731 | 2755 | | |
2732 | | - | |
| 2756 | + | |
2733 | 2757 | | |
2734 | | - | |
| 2758 | + | |
2735 | 2759 | | |
2736 | 2760 | | |
2737 | 2761 | | |
| |||
2778 | 2802 | | |
2779 | 2803 | | |
2780 | 2804 | | |
2781 | | - | |
| 2805 | + | |
2782 | 2806 | | |
2783 | 2807 | | |
2784 | 2808 | | |
| |||
2867 | 2891 | | |
2868 | 2892 | | |
2869 | 2893 | | |
2870 | | - | |
2871 | | - | |
2872 | | - | |
2873 | | - | |
2874 | | - | |
2875 | | - | |
2876 | | - | |
2877 | | - | |
2878 | | - | |
2879 | 2894 | | |
2880 | 2895 | | |
2881 | 2896 | | |
| |||
2906 | 2921 | | |
2907 | 2922 | | |
2908 | 2923 | | |
2909 | | - | |
2910 | | - | |
| 2924 | + | |
| 2925 | + | |
2911 | 2926 | | |
2912 | | - | |
| 2927 | + | |
2913 | 2928 | | |
2914 | 2929 | | |
2915 | | - | |
2916 | | - | |
| 2930 | + | |
| 2931 | + | |
2917 | 2932 | | |
2918 | | - | |
| 2933 | + | |
2919 | 2934 | | |
2920 | 2935 | | |
2921 | 2936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | 81 | | |
77 | | - | |
| 82 | + | |
78 | 83 | | |
79 | | - | |
| 84 | + | |
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
42 | 51 | | |
43 | 52 | | |
44 | 53 | | |
| 54 | + | |
45 | 55 | | |
46 | 56 | | |
47 | 57 | | |
| |||
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
| 100 | + | |
90 | 101 | | |
91 | 102 | | |
92 | 103 | | |
| |||
130 | 141 | | |
131 | 142 | | |
132 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
133 | 163 | | |
134 | 164 | | |
135 | 165 | | |
| |||
144 | 174 | | |
145 | 175 | | |
146 | 176 | | |
147 | | - | |
| 177 | + | |
148 | 178 | | |
149 | 179 | | |
150 | 180 | | |
| |||
0 commit comments