1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using Microsoft . AspNetCore . Builder ;
4
5
using Microsoft . AspNetCore . Http ;
5
6
using Microsoft . AspNetCore . Mvc ;
7
+ using Microsoft . AspNetCore . Routing ;
6
8
using Microsoft . Diagnostics . Monitoring . EventPipe ;
9
+ using Microsoft . Extensions . Logging ;
7
10
using System ;
8
11
using System . ComponentModel ;
9
12
using System . ComponentModel . DataAnnotations ;
@@ -13,32 +16,73 @@ namespace Microsoft.Diagnostics.Monitoring.WebApi.Controllers
13
16
{
14
17
partial class DiagController
15
18
{
16
- [ EndpointSummary ( "Capture metrics for a process." ) ]
17
- [ HttpGet ( "livemetrics" , Name = nameof ( CaptureMetrics ) ) ]
18
- [ ProducesWithProblemDetails ]
19
- [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status429TooManyRequests ) ]
20
- [ ProducesResponseType ( typeof ( string ) , StatusCodes . Status200OK , ContentTypes . ApplicationJsonSequence ) ]
21
- [ ProducesResponseType ( typeof ( void ) , StatusCodes . Status202Accepted ) ]
22
- [ EgressValidation ]
23
- public Task < ActionResult > CaptureMetrics (
24
- [ FromQuery ]
25
- [ Description ( "Process ID used to identify the target process." ) ]
26
- int ? pid = null ,
27
- [ FromQuery ]
28
- [ Description ( "The Runtime instance cookie used to identify the target process." ) ]
29
- Guid ? uid = null ,
30
- [ FromQuery ]
31
- [ Description ( "Process name used to identify the target process." ) ]
32
- string ? name = null ,
33
- [ FromQuery ] [ Range ( - 1 , int . MaxValue ) ]
34
- [ Description ( "The duration of the metrics session (in seconds)." ) ]
35
- int durationSeconds = 30 ,
36
- [ FromQuery ]
37
- [ Description ( "The egress provider to which the metrics are saved." ) ]
38
- string ? egressProvider = null ,
39
- [ FromQuery ]
40
- [ Description ( "An optional set of comma-separated identifiers users can include to make an operation easier to identify." ) ]
41
- string ? tags = null )
19
+ public static void MapMetricsActionMethods ( IEndpointRouteBuilder builder )
20
+ {
21
+ // CaptureMetrics
22
+ builder . MapGet ( "livemetrics" ,
23
+ [ EndpointSummary ( "Capture metrics for a process." ) ] (
24
+ HttpContext context ,
25
+ ILogger < DiagController > logger ,
26
+ [ Description ( "Process ID used to identify the target process." ) ]
27
+ int ? pid ,
28
+ [ Description ( "The Runtime instance cookie used to identify the target process." ) ]
29
+ Guid ? uid ,
30
+ [ Description ( "Process name used to identify the target process." ) ]
31
+ string ? name ,
32
+ [ Range ( - 1 , int . MaxValue ) ]
33
+ [ Description ( "The duration of the metrics session (in seconds)." ) ]
34
+ int durationSeconds = 30 ,
35
+ [ Description ( "The egress provider to which the metrics are saved." ) ]
36
+ string ? egressProvider = null ,
37
+ [ Description ( "An optional set of comma-separated identifiers users can include to make an operation easier to identify." ) ]
38
+ string ? tags = null ) =>
39
+ new DiagController ( context , logger ) . CaptureMetrics ( pid , uid , name , durationSeconds , egressProvider , tags ) )
40
+ . WithName ( nameof ( CaptureMetrics ) )
41
+ . RequireDiagControllerCommon ( )
42
+ . Produces < ProblemDetails > ( StatusCodes . Status429TooManyRequests )
43
+ . Produces < string > ( StatusCodes . Status200OK , ContentTypes . ApplicationJsonSequence )
44
+ . Produces ( StatusCodes . Status202Accepted )
45
+ . RequireEgressValidation ( ) ;
46
+
47
+ // CaptureMetricsCustom
48
+ builder . MapPost ( "livemetrics" ,
49
+ [ EndpointSummary ( "Capture metrics for a process." ) ] (
50
+ HttpContext context ,
51
+ ILogger < DiagController > logger ,
52
+ [ FromBody ]
53
+ [ Required ]
54
+ [ Description ( "The metrics configuration describing which metrics to capture." ) ]
55
+ Models . EventMetricsConfiguration configuration ,
56
+ [ Description ( "Process ID used to identify the target process." ) ]
57
+ int ? pid ,
58
+ [ Description ( "The Runtime instance cookie used to identify the target process." ) ]
59
+ Guid ? uid ,
60
+ [ Description ( "Process name used to identify the target process." ) ]
61
+ string ? name ,
62
+ [ Range ( - 1 , int . MaxValue ) ]
63
+ [ Description ( "The duration of the metrics session (in seconds)." ) ]
64
+ int durationSeconds = 30 ,
65
+ [ Description ( "The egress provider to which the metrics are saved." ) ]
66
+ string ? egressProvider = null ,
67
+ [ Description ( "An optional set of comma-separated identifiers users can include to make an operation easier to identify." ) ]
68
+ string ? tags = null ) =>
69
+ new DiagController ( context , logger ) . CaptureMetricsCustom ( configuration , pid , uid , name , durationSeconds , egressProvider , tags ) )
70
+ . WithName ( nameof ( CaptureMetricsCustom ) )
71
+ . RequireDiagControllerCommon ( )
72
+ . Produces < ProblemDetails > ( StatusCodes . Status429TooManyRequests )
73
+ . Produces < string > ( StatusCodes . Status200OK , ContentTypes . ApplicationJsonSequence )
74
+ . Produces ( StatusCodes . Status202Accepted )
75
+ . Accepts < Models . EventMetricsConfiguration > ( ContentTypes . ApplicationJson , ContentTypes . TextJson , ContentTypes . ApplicationAnyJson )
76
+ . RequireEgressValidation ( ) ;
77
+ }
78
+
79
+ public Task < IResult > CaptureMetrics (
80
+ int ? pid ,
81
+ Guid ? uid ,
82
+ string ? name ,
83
+ int durationSeconds ,
84
+ string ? egressProvider ,
85
+ string ? tags )
42
86
{
43
87
ProcessKey ? processKey = Utilities . GetProcessKey ( pid , uid , name ) ;
44
88
@@ -58,35 +102,14 @@ public Task<ActionResult> CaptureMetrics(
58
102
Utilities . ArtifactType_Metrics ) ;
59
103
}
60
104
61
- [ EndpointSummary ( "Capture metrics for a process." ) ]
62
- [ HttpPost ( "livemetrics" , Name = nameof ( CaptureMetricsCustom ) ) ]
63
- [ ProducesWithProblemDetails ]
64
- [ ProducesResponseType ( typeof ( ProblemDetails ) , StatusCodes . Status429TooManyRequests ) ]
65
- [ ProducesResponseType ( typeof ( string ) , StatusCodes . Status200OK , ContentTypes . ApplicationJsonSequence ) ]
66
- [ ProducesResponseType ( typeof ( void ) , StatusCodes . Status202Accepted ) ]
67
- [ EgressValidation ]
68
- public Task < ActionResult > CaptureMetricsCustom (
69
- [ FromBody ] [ Required ]
70
- [ Description ( "The metrics configuration describing which metrics to capture." ) ]
105
+ public Task < IResult > CaptureMetricsCustom (
71
106
Models . EventMetricsConfiguration configuration ,
72
- [ FromQuery ]
73
- [ Description ( "Process ID used to identify the target process." ) ]
74
- int ? pid = null ,
75
- [ FromQuery ]
76
- [ Description ( "The Runtime instance cookie used to identify the target process." ) ]
77
- Guid ? uid = null ,
78
- [ FromQuery ]
79
- [ Description ( "Process name used to identify the target process." ) ]
80
- string ? name = null ,
81
- [ FromQuery ] [ Range ( - 1 , int . MaxValue ) ]
82
- [ Description ( "The duration of the metrics session (in seconds)." ) ]
83
- int durationSeconds = 30 ,
84
- [ FromQuery ]
85
- [ Description ( "The egress provider to which the metrics are saved." ) ]
86
- string ? egressProvider = null ,
87
- [ FromQuery ]
88
- [ Description ( "An optional set of comma-separated identifiers users can include to make an operation easier to identify." ) ]
89
- string ? tags = null )
107
+ int ? pid ,
108
+ Guid ? uid ,
109
+ string ? name ,
110
+ int durationSeconds ,
111
+ string ? egressProvider ,
112
+ string ? tags )
90
113
{
91
114
ProcessKey ? processKey = Utilities . GetProcessKey ( pid , uid , name ) ;
92
115
0 commit comments