Пример #1
0
        public Task <ActionResult> CaptureTraceCustom(
            [FromBody][Required]
            Models.EventPipeConfiguration configuration,
            [FromQuery]
            int?pid = null,
            [FromQuery]
            Guid?uid = null,
            [FromQuery]
            string name = null,
            [FromQuery][Range(-1, int.MaxValue)]
            int durationSeconds = 30,
            [FromQuery]
            string egressProvider = null)
        {
            ProcessKey?processKey = GetProcessKey(pid, uid, name);

            return(InvokeForProcess(processInfo =>
            {
                foreach (Models.EventPipeProvider provider in configuration.Providers)
                {
                    if (!CounterValidator.ValidateProvider(_counterOptions.CurrentValue,
                                                           provider, out string errorMessage))
                    {
                        throw new ValidationException(errorMessage);
                    }
                }

                TimeSpan duration = Utilities.ConvertSecondsToTimeSpan(durationSeconds);

                var traceConfiguration = TraceUtilities.GetTraceConfiguration(configuration.Providers, configuration.RequestRundown, configuration.BufferSizeInMB);

                return StartTrace(processInfo, traceConfiguration, duration, egressProvider);
            }, processKey, Utilities.ArtifactType_Trace));
        }
Пример #2
0
        IEnumerable <ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
        {
            List <ValidationResult> results = new();

            bool hasProfile   = Profile.HasValue;
            bool hasProviders = null != Providers && Providers.Any();

            if (hasProfile)
            {
                if (hasProviders)
                {
                    // Both Profile and Providers cannot be specified at the same time, otherwise
                    // cannot determine whether to use providers from the profile or the custom
                    // specified providers.
                    results.Add(new ValidationResult(
                                    string.Format(
                                        CultureInfo.InvariantCulture,
                                        Strings.ErrorMessage_TwoFieldsCannotBeSpecified,
                                        nameof(Profile),
                                        nameof(Providers))));
                }
            }
            else if (hasProviders)
            {
                // Validate that each provider is valid.
                int index = 0;
                foreach (EventPipeProvider provider in Providers)
                {
                    ValidationContext providerContext = new(provider, validationContext, validationContext.Items);
                    providerContext.MemberName = nameof(Providers) + "[" + index.ToString(CultureInfo.InvariantCulture) + "]";

                    Validator.TryValidateObject(provider, providerContext, results, validateAllProperties: true);

                    IOptionsMonitor <GlobalCounterOptions> counterOptions = validationContext.GetRequiredService <IOptionsMonitor <GlobalCounterOptions> >();
                    if (!CounterValidator.ValidateProvider(counterOptions.CurrentValue,
                                                           provider, out string errorMessage))
                    {
                        results.Add(new ValidationResult(errorMessage, new[] { nameof(EventPipeProvider.Arguments) }));
                    }

                    index++;
                }
            }
            else
            {
                // Either Profile or Providers must be specified
                results.Add(new ValidationResult(
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    Strings.ErrorMessage_TwoFieldsMissing,
                                    nameof(Profile),
                                    nameof(Providers))));
            }

            return(results);
        }