コード例 #1
0
        /// <summary>
        /// Return true if plugin needs to be disabled
        /// </summary>
        private bool DisablePlugin(IAgentLogPluginContext context)
        {
            // do we want to log that the plugin is disabled due to x reason here?
            if (context.Variables.TryGetValue("Agent.ForceEnable.TestFilePublisherLogPlugin", out var forceEnable) &&
                string.Equals("true", forceEnable.Value, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Enable only for build
            if (!context.Variables.TryGetValue("system.hosttype", out var hostType) ||
                !string.Equals("Build", hostType.Value, StringComparison.OrdinalIgnoreCase))
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", hostType?.Value);
                return(true);
            }

            // Disable for on-prem
            if (!context.Variables.TryGetValue("system.servertype", out var serverType) ||
                !string.Equals("Hosted", serverType.Value, StringComparison.OrdinalIgnoreCase))
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", serverType?.Value);
                return(true);
            }

            // check for PTR task or some other tasks to enable/disable
            if (context.Steps == null)
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", "NoSteps");
                return(true);
            }

            if (context.Steps.Any(x => x.Id.Equals(new Guid("0B0F01ED-7DDE-43FF-9CBB-E48954DAF9B1")) ||
                                  x.Id.Equals(new Guid("AC4EE482-65DA-4485-A532-7B085873E532")) ||
                                  x.Id.Equals(new Guid("8D8EEBD8-2B94-4C97-85AF-839254CC6DA4"))))
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", "ExplicitPublishTaskPresent");
                return(true);
            }

            if (PipelineConfig.BuildId == 0)
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", "BuildIdZero");
                return(true);
            }

            if (!PipelineConfig.Patterns.Any())
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", "PatternIsEmpty");
                return(true);
            }

            if (!PipelineConfig.SearchFolders.Any())
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", "SearchFolderIsEmpty");
                return(true);
            }

            return(false);
        }
コード例 #2
0
        private async Task PopulatePipelineConfig(IAgentLogPluginContext context)
        {
            var props = new Dictionary <string, Object>();

            if (context.Variables.TryGetValue("system.teamProjectId", out var projectGuid))
            {
                _pipelineConfig.Project = new Guid(projectGuid.Value);
                _telemetry.AddOrUpdate("ProjectId", _pipelineConfig.Project);
                props.Add("ProjectId", _pipelineConfig.Project);
            }

            if (context.Variables.TryGetValue("build.buildId", out var buildIdVar) && int.TryParse(buildIdVar.Value, out var buildId))
            {
                _pipelineConfig.BuildId = buildId;
                _telemetry.AddOrUpdate("BuildId", buildId);
                props.Add("BuildId", buildId);
            }

            if (context.Variables.TryGetValue("system.definitionid", out var buildDefinitionId))
            {
                _telemetry.AddOrUpdate("BuildDefinitionId", buildDefinitionId.Value);
            }

            // Publish the initial telemetry event in case we are not able to fire the cumulative one for whatever reason
            await _telemetry.PublishTelemetryAsync("TestResultParserInitialize", props);
        }
コード例 #3
0
        /// <inheritdoc />
        public async Task <bool> InitializeAsync(IAgentLogPluginContext context)
        {
            try
            {
                _logger        = new TraceLogger(context);
                _clientFactory = new ClientFactory(context.VssConnection);

                PopulatePipelineConfig(context);

                if (CheckForPluginDisable(context))
                {
                    return(false); // disable the plugin
                }

                await InputDataParser.InitializeAsync(_clientFactory, _pipelineConfig, _logger);
            }
            catch (Exception ex)
            {
                _logger.Warning($"Unable to initialize {FriendlyName}");
                context.Trace(ex.ToString());
                return(false);
            }

            return(true);
        }
コード例 #4
0
ファイル: LogPlugin.cs プロジェクト: shellayers/Texas-Giant
        private async Task ProcessOutputQueue(IAgentLogPluginContext context, IAgentLogPlugin plugin, List <string> errors)
        {
            string typeName = plugin.GetType().FullName;

            while (!_shortCircuited[typeName].Task.IsCompleted && _outputQueue[typeName].TryDequeue(out string line))
            {
                try
                {
                    var id              = line.Substring(0, line.IndexOf(":"));
                    var message         = line.Substring(line.IndexOf(":") + 1);
                    var processLineTask = plugin.ProcessLineAsync(context, _steps[id], message);
                    var completedTask   = await Task.WhenAny(_shortCircuited[typeName].Task, processLineTask);

                    if (completedTask == processLineTask)
                    {
                        await processLineTask;
                    }
                }
                catch (Exception ex)
                {
                    // ignore exception
                    // only trace the first 10 errors.
                    if (errors.Count < 10)
                    {
                        errors.Add($"{ex} '(line)'");
                    }
                }
            }
        }
コード例 #5
0
        private void PopulateSearchPatterns(IAgentLogPluginContext context, string searchPattern)
        {
            var patterns = searchPattern.Split(",");

            foreach (var pattern in patterns)
            {
                PipelineConfig.Patterns.Add(pattern);
            }
        }
コード例 #6
0
        public TraceLogger(IAgentLogPluginContext context)
        {
            _context = context;

            _context.Variables.TryGetValue("system.debug", out var systemDebug);
            if (string.Equals(systemDebug?.Value, "true", System.StringComparison.OrdinalIgnoreCase))
            {
                _debug = true;
            }
        }
コード例 #7
0
        /// <inheritdoc />
        public async Task FinalizeAsync(IAgentLogPluginContext context)
        {
            using (var timer = new SimpleTimer("Finalize", _logger,
                                               new TelemetryDataWrapper(_telemetry, TelemetryConstants.FinalizeAsync),
                                               TimeSpan.FromMilliseconds(Int32.MaxValue)))
            {
                await _inputDataParser.CompleteAsync();
            }

            await _telemetry.PublishCumulativeTelemetryAsync();
        }
コード例 #8
0
 public Task <bool> InitializeAsync(IAgentLogPluginContext context)
 {
     if (context.Variables.ContainsKey("throw_initialize"))
     {
         throw new NotSupportedException();
     }
     else
     {
         return(Task.FromResult(true));
     }
 }
コード例 #9
0
 public Task FinalizeAsync(IAgentLogPluginContext context)
 {
     if (context.Variables.ContainsKey("throw_finalize"))
     {
         throw new NotSupportedException();
     }
     else
     {
         context.Output("Done");
         return(Task.CompletedTask);
     }
 }
コード例 #10
0
 public Task ProcessLineAsync(IAgentLogPluginContext context, Pipelines.TaskStepDefinitionReference step, string line)
 {
     if (context.Variables.ContainsKey("throw_process"))
     {
         throw new NotSupportedException();
     }
     else
     {
         context.Output(line);
         return(Task.CompletedTask);
     }
 }
コード例 #11
0
        private void PopulatePipelineConfig(IAgentLogPluginContext context)
        {
            if (context.Variables.TryGetValue("system.teamProjectId", out var projectGuid))
            {
                _pipelineConfig.Project = new Guid(projectGuid.Value);
            }

            if (context.Variables.TryGetValue("build.buildId", out var buildId))
            {
                _pipelineConfig.BuildId = int.Parse(buildId.Value);
            }
        }
コード例 #12
0
 public async Task ProcessLineAsync(IAgentLogPluginContext context, Pipelines.TaskStepDefinitionReference step, string line)
 {
     if (_counter++ < 1)
     {
         context.Output("SLOW");
         await Task.Delay(400);
     }
     else
     {
         context.Output(line);
     }
 }
コード例 #13
0
        private void PopulateSearchFolders(IAgentLogPluginContext context, string searchFolders)
        {
            var folderVariables = searchFolders.Split(",");

            foreach (var folderVar in folderVariables)
            {
                if (context.Variables.TryGetValue(folderVar, out var folderValue))
                {
                    PipelineConfig.SearchFolders.Add(folderValue.Value);
                }
            }
        }
コード例 #14
0
        private async Task PopulatePipelineConfig(IAgentLogPluginContext context)
        {
            var props = new Dictionary <string, Object>();

            if (context.Variables.TryGetValue("system.teamProject", out var projectName))
            {
                PipelineConfig.ProjectName = projectName.Value;
                _telemetry.AddOrUpdate("ProjectName", PipelineConfig.ProjectName);
                props.Add("ProjectName", PipelineConfig.ProjectName);
            }

            if (context.Variables.TryGetValue("build.buildId", out var buildIdVar) && int.TryParse(buildIdVar.Value, out var buildId))
            {
                PipelineConfig.BuildId = buildId;
                _telemetry.AddOrUpdate("BuildId", PipelineConfig.BuildId);
                props.Add("BuildId", PipelineConfig.BuildId);
            }

            if (context.Variables.TryGetValue("system.definitionid", out var buildDefinitionId))
            {
                _telemetry.AddOrUpdate("BuildDefinitionId", buildDefinitionId.Value);
                props.Add("BuildDefinitionId", buildDefinitionId.Value);
            }

            if (context.Variables.TryGetValue("build.Repository.name", out var repositoryName))
            {
                _telemetry.AddOrUpdate("RepositoryName", repositoryName.Value);
            }

            if (context.Variables.TryGetValue("agent.version", out var agentVersion))
            {
                _telemetry.AddOrUpdate("AgentVersion", agentVersion.Value);
            }

            if (context.Variables.TryGetValue("agent.testfilepublisher.pattern", out var pattern) &&
                !string.IsNullOrWhiteSpace(pattern.Value))
            {
                PopulateSearchPatterns(context, pattern.Value);
                props.Add("SearchPatterns", string.Join(",", PipelineConfig.Patterns));
            }

            if (context.Variables.TryGetValue("agent.testfilepublisher.searchfolders", out var searchFolders) &&
                !string.IsNullOrWhiteSpace(searchFolders.Value))
            {
                PopulateSearchFolders(context, searchFolders.Value);
                props.Add("SearchFolders", string.Join(",", PipelineConfig.SearchFolders));
            }

            // Publish the initial telemetry event in case we are not able to fire the cumulative one for whatever reason
            await _telemetry.PublishTelemetryAsync("TestFilePublisherInitialize", props);
        }
コード例 #15
0
        /// <inheritdoc />
        public async Task <bool> InitializeAsync(IAgentLogPluginContext context)
        {
            try
            {
                _logger    = _logger ?? new TraceLogger(context);
                _telemetry = _telemetry ?? new TelemetryDataCollector(new ClientFactory(context.VssConnection), _logger);

                await PopulatePipelineConfig(context);

                if (DisablePlugin(context))
                {
                    _telemetry.AddOrUpdate(TelemetryConstants.PluginDisabled, true);
                    await _telemetry.PublishCumulativeTelemetryAsync();

                    return(false); // disable the plugin
                }

                _testFilePublisher = _testFilePublisher ??
                                     new TestFilePublisher(context.VssConnection, PipelineConfig, new TestFileTraceListener(context), _logger, _telemetry);
                await _testFilePublisher.InitializeAsync();

                _telemetry.AddOrUpdate(TelemetryConstants.PluginInitialized, true);
            }
            catch (SocketException ex)
            {
                ExceptionsUtil.HandleSocketException(ex, context.VssConnection.Uri.ToString(), _logger.Warning);

                if (_telemetry != null)
                {
                    _telemetry.AddOrUpdate(TelemetryConstants.PluginDisabled, true);
                    _telemetry.AddOrUpdate(TelemetryConstants.InitializeFailed, ex);
                    await _telemetry.PublishCumulativeTelemetryAsync();
                }
                return(false);
            }
            catch (Exception ex)
            {
                context.Trace(ex.ToString());
                _logger?.Warning($"Unable to initialize {FriendlyName}.");
                if (_telemetry != null)
                {
                    _telemetry.AddOrUpdate(TelemetryConstants.PluginDisabled, true);
                    _telemetry.AddOrUpdate(TelemetryConstants.InitializeFailed, ex);
                    await _telemetry.PublishCumulativeTelemetryAsync();
                }
                return(false);
            }

            return(true);
        }
コード例 #16
0
        /// <summary>
        /// Return true if plugin needs to be disabled
        /// </summary>
        private bool DisablePlugin(IAgentLogPluginContext context)
        {
            // do we want to log that the plugin is disabled due to x reason here?
            if (context.Variables.TryGetValue("Agent.ForceEnable.TestResultLogPlugin", out var forceEnableTestResultParsers) &&
                string.Equals("true", forceEnableTestResultParsers.Value, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Enable only for build
            if (!context.Variables.TryGetValue("system.hosttype", out var hostType) ||
                !string.Equals("Build", hostType.Value, StringComparison.OrdinalIgnoreCase))
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", hostType?.Value);
                return(true);
            }

            // Disable for on-prem
            if (!context.Variables.TryGetValue("system.servertype", out var serverType) ||
                !string.Equals("Hosted", serverType.Value, StringComparison.OrdinalIgnoreCase))
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", serverType?.Value);
                return(true);
            }

            // check for PTR task or some other tasks to enable/disable
            if (context.Steps == null)
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", "NoSteps");
                return(true);
            }

            if (context.Steps.Any(x => x.Id.Equals(new Guid("0B0F01ED-7DDE-43FF-9CBB-E48954DAF9B1"))))
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", "ExplicitPublishTaskPresent");
                return(true);
            }

            if (_pipelineConfig.BuildId == 0)
            {
                _telemetry.AddOrUpdate("PluginDisabledReason", "BuildIdZero");
                return(true);
            }

            return(false);
        }
コード例 #17
0
        /// <inheritdoc />
        public async Task FinalizeAsync(IAgentLogPluginContext context)
        {
            using (var timer = new SimpleTimer("Finalize", _logger, TimeSpan.FromMinutes(2),
                                               new TelemetryDataWrapper(_telemetry, TelemetryConstants.FinalizeAsync)))
            {
                try
                {
                    await _testFilePublisher.PublishAsync();
                }
                catch (Exception ex)
                {
                    _logger.Info($"Error: {ex}");
                    _telemetry.AddOrUpdate("FailedToPublishTestRuns", ex);
                }
            }

            await _telemetry.PublishCumulativeTelemetryAsync();
        }
コード例 #18
0
        private bool CheckForPluginDisable(IAgentLogPluginContext context)
        {
            // Enable only for build
            if (context.Variables.TryGetValue("system.hosttype", out var hostType) &&
                !string.Equals("Build", hostType.Value, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Disable for on-prem
            if (context.Variables.TryGetValue("system.servertype", out var serverType) &&
                !string.Equals("Hosted", serverType.Value, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // check for PTR task or some other tasks to enable/disable
            return(context.Steps == null ||
                   context.Steps.Any(x => x.Id.Equals(new Guid("0B0F01ED-7DDE-43FF-9CBB-E48954DAF9B1"))) ||
                   _pipelineConfig.BuildId == 0);
        }
コード例 #19
0
        /// <inheritdoc />
        public async Task <bool> InitializeAsync(IAgentLogPluginContext context)
        {
            try
            {
                _logger        = _logger ?? new TraceLogger(context);
                _clientFactory = new ClientFactory(context.VssConnection);
                _telemetry     = _telemetry ?? new TelemetryDataCollector(_clientFactory, _logger);

                await PopulatePipelineConfig(context);

                if (DisablePlugin(context))
                {
                    _telemetry.AddOrUpdate(TelemetryConstants.PluginDisabled, true);
                    await _telemetry.PublishCumulativeTelemetryAsync();

                    return(false); // disable the plugin
                }

                await _inputDataParser.InitializeAsync(_clientFactory, _pipelineConfig, _logger, _telemetry);

                _telemetry.AddOrUpdate(TelemetryConstants.PluginInitialized, true);
            }
            catch (Exception ex)
            {
                context.Trace(ex.ToString());
                _logger?.Warning($"Unable to initialize {FriendlyName}.");
                if (_telemetry != null)
                {
                    _telemetry?.AddOrUpdate(TelemetryConstants.InitialzieFailed, ex);
                    await _telemetry.PublishCumulativeTelemetryAsync();
                }
                return(false);
            }

            return(true);
        }
コード例 #20
0
 public TraceLogger(IAgentLogPluginContext context)
 {
     _context = context;
 }
コード例 #21
0
        private async Task PopulatePipelineConfig(IAgentLogPluginContext context)
        {
            var props = new Dictionary <string, Object>();

            if (context.Variables.TryGetValue("system.teamProjectId", out var projectGuid))
            {
                _pipelineConfig.Project = new Guid(projectGuid.Value);
                _telemetry.AddOrUpdate("ProjectId", _pipelineConfig.Project);
                props.Add("ProjectId", _pipelineConfig.Project);
            }

            if (context.Variables.TryGetValue("build.buildId", out var buildIdVar) && int.TryParse(buildIdVar.Value, out var buildId))
            {
                _pipelineConfig.BuildId = buildId;
                _telemetry.AddOrUpdate("BuildId", buildId);
                props.Add("BuildId", buildId);
            }

            if (context.Variables.TryGetValue("system.stageName", out var stageName))
            {
                _pipelineConfig.StageName = stageName.Value;
                _telemetry.AddOrUpdate("StageName", stageName.Value);
                props.Add("StageName", stageName.Value);
            }

            if (context.Variables.TryGetValue("system.stageAttempt", out var stageAttemptVar) && int.TryParse(stageAttemptVar.Value, out var stageAttempt))
            {
                _pipelineConfig.StageAttempt = stageAttempt;
                _telemetry.AddOrUpdate("StageAttempt", stageAttempt);
                props.Add("StageAttempt", stageAttempt);
            }

            if (context.Variables.TryGetValue("system.phaseName", out var phaseName))
            {
                _pipelineConfig.PhaseName = phaseName.Value;
                _telemetry.AddOrUpdate("PhaseName", phaseName.Value);
                props.Add("PhaseName", phaseName.Value);
            }

            if (context.Variables.TryGetValue("system.phaseAttempt", out var phaseAttemptVar) && int.TryParse(phaseAttemptVar.Value, out var phaseAttempt))
            {
                _pipelineConfig.PhaseAttempt = phaseAttempt;
                _telemetry.AddOrUpdate("PhaseAttempt", phaseAttempt);
                props.Add("PhaseAttempt", phaseAttempt);
            }

            if (context.Variables.TryGetValue("system.jobName", out var jobName))
            {
                _pipelineConfig.JobName = jobName.Value;
                _telemetry.AddOrUpdate("JobName", jobName.Value);
                props.Add("JobName", jobName.Value);
            }

            if (context.Variables.TryGetValue("system.jobAttempt", out var jobAttemptVar) && int.TryParse(jobAttemptVar.Value, out var jobAttempt))
            {
                _pipelineConfig.JobAttempt = jobAttempt;
                _telemetry.AddOrUpdate("JobAttempt", jobAttempt);
                props.Add("JobAttempt", jobAttempt);
            }

            if (context.Variables.TryGetValue("system.definitionid", out var buildDefinitionId))
            {
                _telemetry.AddOrUpdate("BuildDefinitionId", buildDefinitionId.Value);
                props.Add("BuildDefinitionId", buildDefinitionId.Value);
            }

            if (context.Variables.TryGetValue("build.Repository.name", out var repositoryName))
            {
                _telemetry.AddOrUpdate("RepositoryName", repositoryName.Value);
                props.Add("RepositoryName", repositoryName.Value);
            }

            if (context.Variables.TryGetValue("agent.version", out var agentVersion))
            {
                _telemetry.AddOrUpdate("AgentVersion", agentVersion.Value);
                props.Add("AgentVersion", agentVersion.Value);
            }

            // Publish the initial telemetry event in case we are not able to fire the cumulative one for whatever reason
            await _telemetry.PublishTelemetryAsync("TestResultParserInitialize", props);
        }
コード例 #22
0
 /// <inheritdoc />
 public async Task ProcessLineAsync(IAgentLogPluginContext context, Pipelines.TaskStepDefinitionReference step, string line)
 {
     await _inputDataParser.ProcessDataAsync(line);
 }
コード例 #23
0
 public Task <bool> InitializeAsync(IAgentLogPluginContext context)
 {
     return(Task.FromResult(true));
 }
コード例 #24
0
 /// <inheritdoc />
 public async Task FinalizeAsync(IAgentLogPluginContext context)
 {
     await InputDataParser.CompleteAsync();
 }
コード例 #25
0
 public Task FinalizeAsync(IAgentLogPluginContext context)
 {
     context.Output("Done");
     return(Task.CompletedTask);
 }
コード例 #26
0
 public Task ProcessLineAsync(IAgentLogPluginContext context, Pipelines.TaskStepDefinitionReference step, string line)
 {
     context.Output(line);
     return(Task.CompletedTask);
 }
コード例 #27
0
 /// <inheritdoc />
 public async Task ProcessLineAsync(IAgentLogPluginContext context, Pipelines.TaskStepDefinitionReference step, string line)
 {
     await Task.CompletedTask;
 }
コード例 #28
0
 public TestFileTraceListener(IAgentLogPluginContext context)
 {
     _context = context;
 }
コード例 #29
0
 public async Task ProcessLineAsync(IAgentLogPluginContext context, Pipelines.TaskStepDefinitionReference step, string line)
 {
     context.Output("BLOCK");
     await Task.Delay(TimeSpan.FromMilliseconds(-1));
 }