private async Task ActionListExecutor_SecondActionFail(bool waitForCompletion) { await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => { rootOptions.CreateCollectionRule(DefaultRuleName) .AddExecuteActionAppAction(waitForCompletion, new string[] { ActionTestsConstants.ZeroExitCode }) .AddExecuteActionAppAction(waitForCompletion, new string[] { ActionTestsConstants.NonzeroExitCode }) .SetStartupTrigger(); }, async host => { ActionListExecutor executor = host.Services.GetService <ActionListExecutor>(); using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(DefaultTimeout); CollectionRuleOptions ruleOptions = host.Services.GetRequiredService <IOptionsMonitor <CollectionRuleOptions> >().Get(DefaultRuleName); ILogger <CollectionRuleService> logger = host.Services.GetRequiredService <ILogger <CollectionRuleService> >(); ISystemClock clock = host.Services.GetRequiredService <ISystemClock>(); CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, clock); int callbackCount = 0; Action startCallback = () => callbackCount++; CollectionRuleActionExecutionException actionExecutionException = await Assert.ThrowsAsync <CollectionRuleActionExecutionException>( () => executor.ExecuteActions(context, startCallback, cancellationTokenSource.Token)); Assert.Equal(1, actionExecutionException.ActionIndex); Assert.Equal(string.Format(Strings.ErrorMessage_NonzeroExitCode, "1"), actionExecutionException.Message); VerifyStartCallbackCount(waitForCompletion, callbackCount); }); }
public async Task InvalidTokenReferenceTest() { string a2input1 = "$(Actions. badly formed"; string a2input2 = "$(Actions.a15.MissingAction)"; string a2input3 = "$(Actions.a1.MissingResult)"; LogRecord record = new LogRecord(); PassThroughOptions settings = null; await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => { CollectionRuleOptions options = rootOptions.CreateCollectionRule(DefaultRuleName) .AddPassThroughAction("a1", "a1input1", "a1input2", "a1input3") .AddPassThroughAction("a2", a2input1, a2input2, a2input3) .SetStartupTrigger(); settings = (PassThroughOptions)options.Actions.Last().Settings; }, host => { using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeoutMs); CollectionRuleOptions ruleOptions = host.Services.GetRequiredService <IOptionsMonitor <CollectionRuleOptions> >().Get(DefaultRuleName); ILogger <CollectionRuleService> logger = host.Services.GetRequiredService <ILogger <CollectionRuleService> >(); ISystemClock clock = host.Services.GetRequiredService <ISystemClock>(); CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, clock); ActionOptionsDependencyAnalyzer analyzer = ActionOptionsDependencyAnalyzer.Create(context); analyzer.GetActionDependencies(1); analyzer.SubstituteOptionValues(new Dictionary <string, CollectionRuleActionResult>(), 1, settings); Assert.Equal(3, record.Events.Count); Assert.Equal(LoggingEventIds.InvalidActionReferenceToken.Id(), record.Events[0].EventId.Id); Assert.Equal(LoggingEventIds.InvalidActionReference.Id(), record.Events[1].EventId.Id); Assert.Equal(LoggingEventIds.InvalidActionResultReference.Id(), record.Events[2].EventId.Id); }, serviceCollection =>
public async Task ActionListExecutor_AllActionsSucceed() { await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => { rootOptions.CreateCollectionRule(DefaultRuleName) .AddExecuteActionAppAction(new string[] { ActionTestsConstants.ZeroExitCode }) .AddExecuteActionAppAction(new string[] { ActionTestsConstants.ZeroExitCode }) .SetStartupTrigger(); }, async host => { ActionListExecutor executor = host.Services.GetService <ActionListExecutor>(); using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(DefaultTimeout); CollectionRuleOptions ruleOptions = host.Services.GetRequiredService <IOptionsMonitor <CollectionRuleOptions> >().Get(DefaultRuleName); ILogger <CollectionRuleService> logger = host.Services.GetRequiredService <ILogger <CollectionRuleService> >(); ISystemClock clock = host.Services.GetRequiredService <ISystemClock>(); CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, clock); int callbackCount = 0; Action startCallback = () => callbackCount++; await executor.ExecuteActions(context, startCallback, cancellationTokenSource.Token); VerifyStartCallbackCount(waitForCompletion: false, callbackCount); }); }
public async Task ActionListExecutor_Dependencies() { const string Output1 = nameof(Output1); const string Output2 = nameof(Output2); const string Output3 = nameof(Output3); string a2input1 = FormattableString.Invariant($"$(Actions.a1.{Output1}) with $(Actions.a1.{Output2})T"); string a2input2 = FormattableString.Invariant($"$(Actions.a1.{Output2})"); string a2input3 = FormattableString.Invariant($"Output $(Actions.a1.{Output3}) trail"); PassThroughOptions a2Settings = null; await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => { CollectionRuleOptions options = rootOptions.CreateCollectionRule(DefaultRuleName) .AddPassThroughAction("a1", "a1input1", "a1input2", "a1input3") .AddPassThroughAction("a2", a2input1, a2input2, a2input3) .SetStartupTrigger(); a2Settings = (PassThroughOptions)options.Actions.Last().Settings; }, async host => { ActionListExecutor executor = host.Services.GetService <ActionListExecutor>(); using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(DefaultTimeout); CollectionRuleOptions ruleOptions = host.Services.GetRequiredService <IOptionsMonitor <CollectionRuleOptions> >().Get(DefaultRuleName); ILogger <CollectionRuleService> logger = host.Services.GetRequiredService <ILogger <CollectionRuleService> >(); ISystemClock clock = host.Services.GetRequiredService <ISystemClock>(); CollectionRuleContext context = new(DefaultRuleName, ruleOptions, null, logger, clock); int callbackCount = 0; Action startCallback = () => callbackCount++; IDictionary <string, CollectionRuleActionResult> results = await executor.ExecuteActions(context, startCallback, cancellationTokenSource.Token); //Verify that the original settings were not altered during execution. Assert.Equal(a2input1, a2Settings.Input1); Assert.Equal(a2input2, a2Settings.Input2); Assert.Equal(a2input3, a2Settings.Input3); Assert.Equal(1, callbackCount); Assert.Equal(2, results.Count); Assert.True(results.TryGetValue("a2", out CollectionRuleActionResult a2result)); Assert.Equal(3, a2result.OutputValues.Count); Assert.True(a2result.OutputValues.TryGetValue(Output1, out string a2output1)); Assert.Equal("a1input1 with a1input2T", a2output1); Assert.True(a2result.OutputValues.TryGetValue(Output2, out string a2output2)); Assert.Equal("a1input2", a2output2); Assert.True(a2result.OutputValues.TryGetValue(Output3, out string a2output3)); Assert.Equal("Output a1input3 trail", a2output3); }, serviceCollection => { serviceCollection.RegisterCollectionRuleAction <PassThroughActionFactory, PassThroughOptions>(nameof(PassThroughAction)); }); }
public static CollectionRuleOptions AddProcessNameFilter(this CollectionRuleOptions options, string name) { options.Filters.Add(new ProcessFilterDescriptor() { Key = ProcessFilterKey.ProcessName, Value = name, MatchType = ProcessFilterType.Exact }); return(options); }
public static CollectionRuleOptions AddCommandLineFilter(this CollectionRuleOptions options, string value, ProcessFilterType matchType = ProcessFilterType.Contains) { options.Filters.Add(new ProcessFilterDescriptor() { Key = ProcessFilterKey.CommandLine, Value = value, MatchType = matchType }); return(options); }
public static CollectionRuleOptions AddLoadProfilerAction(this CollectionRuleOptions options, Action <LoadProfilerOptions> configureOptions) { return(options.AddAction( KnownCollectionRuleActions.LoadProfiler, callback: actionOptions => { LoadProfilerOptions loadProfilerOptions = new(); configureOptions?.Invoke(loadProfilerOptions); actionOptions.Settings = loadProfilerOptions; })); }
public static CollectionRuleOptions AddCollectGCDumpAction(this CollectionRuleOptions options, string egress) { return(options.AddAction( KnownCollectionRuleActions.CollectGCDump, actionOptions => { CollectGCDumpOptions collectGCDumpOptions = new(); collectGCDumpOptions.Egress = egress; actionOptions.Settings = collectGCDumpOptions; })); }
public static CollectionRuleOptions AddAction(this CollectionRuleOptions options, string type, Action <CollectionRuleActionOptions> callback = null) { CollectionRuleActionOptions actionOptions = new(); actionOptions.Type = type; callback?.Invoke(actionOptions); options.Actions.Add(actionOptions); return(options); }
public static CollectionRuleOptions AddSetEnvironmentVariableAction(this CollectionRuleOptions options, string name, string value = null) { return(options.AddAction( KnownCollectionRuleActions.SetEnvironmentVariable, callback: actionOptions => { SetEnvironmentVariableOptions setEnvOpts = new() { Name = name, Value = value, }; actionOptions.Settings = setEnvOpts; }));
public static CollectionRuleOptions AddCollectDumpAction(this CollectionRuleOptions options, string egress, DumpType?type = null) { return(options.AddAction( KnownCollectionRuleActions.CollectDump, actionOptions => { CollectDumpOptions collectDumpOptions = new(); collectDumpOptions.Egress = egress; collectDumpOptions.Type = type; actionOptions.Settings = collectDumpOptions; })); }
public CollectionRuleContext(string name, CollectionRuleOptions options, IEndpointInfo endpointInfo, ILogger logger, ISystemClock clock, Action throttledCallback = null) { // TODO: Allow null endpointInfo to allow tests to pass, but this should be provided by // tests since it will be required by all aspects in the future. For example, the ActionListExecutor // (which uses null in tests) will require this when needing to get process information for // the actions property bag used for token replacement. //EndpointInfo = endpointInfo ?? throw new ArgumentNullException(nameof(endpointInfo)); EndpointInfo = endpointInfo; Logger = logger ?? throw new ArgumentNullException(nameof(logger)); Options = options ?? throw new ArgumentNullException(nameof(options)); Name = name ?? throw new ArgumentNullException(nameof(name)); Clock = clock ?? throw new ArgumentNullException(nameof(clock)); ThrottledCallback = throttledCallback; }
public static CollectionRuleOptions AddCollectLogsAction(this CollectionRuleOptions options, string egress, Action <CollectLogsOptions> callback = null) { return(options.AddAction( KnownCollectionRuleActions.CollectLogs, actionOptions => { CollectLogsOptions collectLogsOptions = new(); collectLogsOptions.Egress = egress; callback?.Invoke(collectLogsOptions); actionOptions.Settings = collectLogsOptions; })); }
public static CollectionRuleOptions AddExecuteAction(this CollectionRuleOptions options, string path, string arguments = null, bool?waitForCompletion = null) { return(options.AddAction( KnownCollectionRuleActions.Execute, actionOptions => { ExecuteOptions executeOptions = new(); executeOptions.Arguments = arguments; executeOptions.Path = path; actionOptions.Settings = executeOptions; actionOptions.WaitForCompletion = waitForCompletion; })); }
public static CollectionRuleOptions AddCollectTraceAction(this CollectionRuleOptions options, IEnumerable <EventPipeProvider> providers, string egress, Action <CollectTraceOptions> callback = null) { return(options.AddAction( KnownCollectionRuleActions.CollectTrace, actionOptions => { CollectTraceOptions collectTraceOptions = new(); collectTraceOptions.Providers = new List <EventPipeProvider>(providers); collectTraceOptions.Egress = egress; callback?.Invoke(collectTraceOptions); actionOptions.Settings = collectTraceOptions; })); }
public static CollectionRuleOptions AddPassThroughAction(this CollectionRuleOptions options, string name, string input1, string input2, string input3) { return(options.AddAction( nameof(PassThroughAction), actionOptions => { PassThroughOptions settings = new PassThroughOptions() { Input1 = input1, Input2 = input2, Input3 = input3 }; actionOptions.Name = name; actionOptions.Settings = settings; })); }
public async Task DuplicateActionNamesTest() { await TestHostHelper.CreateCollectionRulesHost(_outputHelper, rootOptions => { CollectionRuleOptions options = rootOptions.CreateCollectionRule(DefaultRuleName) .AddPassThroughAction("a1", "a1input1", "a1input2", "a1input3") .AddPassThroughAction("a2", "a1input1", "a1input2", "a1input3") .AddPassThroughAction("a1", "a1input1", "a1input2", "a1input3") .SetStartupTrigger(); }, host => { //Expecting duplicate action name Assert.Throws <OptionsValidationException>(() => host.Services.GetRequiredService <IOptionsMonitor <CollectionRuleOptions> >().Get(DefaultRuleName)); }, serviceCollection => { serviceCollection.RegisterCollectionRuleAction <PassThroughActionFactory, PassThroughOptions>(nameof(PassThroughAction)); }); }
public static CollectionRuleOptions AddExecuteActionAppAction(this CollectionRuleOptions options, bool waitForCompletion, params string[] args) { options.AddExecuteAction(DotNetHost.HostExePath, ExecuteActionTestHelper.GenerateArgumentsString(args), waitForCompletion); return(options); }
public static CollectionRuleOptions SetManualTrigger(this CollectionRuleOptions options) { return(SetTrigger(options, ManualTrigger.TriggerName)); }