Ejemplo n.º 1
0
        public Task <ActionResult> Trace(
            int?pid,
            [FromQuery] TraceProfile profile = DefaultTraceProfiles,
            [FromQuery][Range(-1, int.MaxValue)] int durationSeconds       = 30,
            [FromQuery][Range(1, int.MaxValue)] int metricsIntervalSeconds = 1)
        {
            TimeSpan duration = ConvertSecondsToTimeSpan(durationSeconds);

            return(this.InvokeService(async() =>
            {
                var configurations = new List <MonitoringSourceConfiguration>();
                if (profile.HasFlag(TraceProfile.Cpu))
                {
                    configurations.Add(new CpuProfileConfiguration());
                }
                if (profile.HasFlag(TraceProfile.Http))
                {
                    configurations.Add(new HttpRequestSourceConfiguration());
                }
                if (profile.HasFlag(TraceProfile.Logs))
                {
                    configurations.Add(new LoggingSourceConfiguration());
                }
                if (profile.HasFlag(TraceProfile.Metrics))
                {
                    configurations.Add(new MetricSourceConfiguration(metricsIntervalSeconds));
                }

                var aggregateConfiguration = new AggregateSourceConfiguration(configurations.ToArray());

                return await StartTrace(pid, aggregateConfiguration, duration);
            }));
        }
Ejemplo n.º 2
0
 private void VerifyEqual(TraceProfile expected, TraceProfileDescriptor actual)
 {
     Assert.Equal(expected.Collectors.Count, actual.Collectors.Count);
     for (int i = 0; i < expected.Collectors.Count; ++i)
     {
         VerifyEqual((dynamic)expected.Collectors[i], (dynamic)actual.Collectors[i]);
     }
 }
Ejemplo n.º 3
0
            protected override async Task <CollectionRuleActionResult> ExecuteCoreAsync(
                TaskCompletionSource <object> startCompletionSource,
                CancellationToken token)
            {
                TimeSpan duration       = Options.Duration.GetValueOrDefault(TimeSpan.Parse(CollectTraceOptionsDefaults.Duration));
                string   egressProvider = Options.Egress;

                MonitoringSourceConfiguration configuration;

                if (Options.Profile.HasValue)
                {
                    TraceProfile profile = Options.Profile.Value;
                    float        metricsIntervalSeconds = _counterOptions.CurrentValue.GetIntervalSeconds();

                    configuration = TraceUtilities.GetTraceConfiguration(profile, metricsIntervalSeconds);
                }
                else
                {
                    EventPipeProvider[] optionsProviders = Options.Providers.ToArray();
                    bool requestRundown      = Options.RequestRundown.GetValueOrDefault(CollectTraceOptionsDefaults.RequestRundown);
                    int  bufferSizeMegabytes = Options.BufferSizeMegabytes.GetValueOrDefault(CollectTraceOptionsDefaults.BufferSizeMegabytes);

                    configuration = TraceUtilities.GetTraceConfiguration(optionsProviders, requestRundown, bufferSizeMegabytes);
                }

                string fileName = TraceUtilities.GenerateTraceFileName(EndpointInfo);

                KeyValueLogScope scope = Utils.CreateArtifactScope(Utils.ArtifactType_Trace, EndpointInfo);

                EgressOperation egressOperation = new EgressOperation(
                    async(outputStream, token) =>
                {
                    using IDisposable operationRegistration = _operationTrackerService.Register(EndpointInfo);
                    await TraceUtilities.CaptureTraceAsync(startCompletionSource, EndpointInfo, configuration, duration, outputStream, token);
                },
                    egressProvider,
                    fileName,
                    EndpointInfo,
                    ContentTypes.ApplicationOctetStream,
                    scope);

                ExecutionResult <EgressResult> result = await egressOperation.ExecuteAsync(_serviceProvider, token);

                string traceFilePath = result.Result.Value;

                return(new CollectionRuleActionResult()
                {
                    OutputValues = new Dictionary <string, string>(StringComparer.Ordinal)
                    {
                        { CollectionRuleActionConstants.EgressPathOutputValueName, traceFilePath }
                    }
                });
            }
Ejemplo n.º 4
0
        public static TraceProfileDescriptor GetDescriptor(this TraceProfile activeProfile)
        {
            var d = new TraceProfileDescriptor();

            foreach (var collector in activeProfile.Collectors)
            {
                if (collector is EventCollector ec)
                {
                    d.Collectors.Add(GetDescriptor(ec));
                }
            }

            return(d);
        }
Ejemplo n.º 5
0
        public Task <ActionResult> Trace(
            int?pid,
            [FromQuery] TraceProfile profile = DefaultTraceProfiles,
            [FromQuery][Range(-1, int.MaxValue)] int durationSeconds       = 30,
            [FromQuery][Range(1, int.MaxValue)] int metricsIntervalSeconds = 1)
        {
            TimeSpan duration = ConvertSecondsToTimeSpan(durationSeconds);

            return(InvokeService(async() =>
            {
                int pidValue = _diagnosticServices.ResolveProcess(pid);
                IStreamWithCleanup result = await _diagnosticServices.StartTrace(pidValue, profile, duration, metricsIntervalSeconds, this.HttpContext.RequestAborted);
                return new StreamWithCleanupResult(result, "application/octet-stream", FormattableString.Invariant($"{Guid.NewGuid()}.nettrace"));
            }));
        }
        public async Task CollectTraceAction_ProfileSuccess(TargetFrameworkMoniker tfm, TraceProfile traceProfile)
        {
            using TemporaryDirectory tempDirectory = new(_outputHelper);

            await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions =>
            {
                rootOptions.AddFileSystemEgress(ActionTestsConstants.ExpectedEgressProvider, tempDirectory.FullName);

                rootOptions.CreateCollectionRule(DefaultRuleName)
                .AddCollectTraceAction(traceProfile, ActionTestsConstants.ExpectedEgressProvider, options =>
                {
                    options.Duration = TimeSpan.FromSeconds(2);
                })
                .SetStartupTrigger();
            }, async host =>
            {
                await PerformTrace(host, tfm);
            });
        }
Ejemplo n.º 7
0
        public void GetDescriptor_TraceProfile(TraceProfile expected)
        {
            var actual = TraceProfileUtils.GetDescriptor(expected);

            VerifyEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public static CollectionRuleOptions AddCollectTraceAction(this CollectionRuleOptions options, TraceProfile profile, string egress, Action <CollectTraceOptions> callback = null)
        {
            return(options.AddAction(
                       KnownCollectionRuleActions.CollectTrace,
                       actionOptions =>
            {
                CollectTraceOptions collectTraceOptions = new();
                collectTraceOptions.Profile = profile;
                collectTraceOptions.Egress = egress;

                callback?.Invoke(collectTraceOptions);

                actionOptions.Settings = collectTraceOptions;
            }));
        }