Example #1
0
 public static RunSummary SuccessfulRunSummary(
     string runId,
     TimeSpan elapsed,
     ProcessingNotificationsCollector processingNotificationsCollector,
     ProcessLogSetResult processLogSetResult,
     WorkbookGeneratorResults workbookGeneratorResults,
     PublisherResults publisherResults)
 {
     return(new RunSummary(
                runId,
                elapsed,
                processingNotificationsCollector,
                processLogSetResult,
                workbookGeneratorResults,
                publisherResults,
                null,
                ExitReason.CompletedSuccessfully));
 }
Example #2
0
 private RunSummary(
     string runId,
     TimeSpan elapsed,
     ProcessingNotificationsCollector processingNotificationsCollector,
     ProcessLogSetResult processLogSetResult,
     WorkbookGeneratorResults workbookGeneratorResults,
     PublisherResults publisherResults,
     string reasonForFailure,
     ExitReason exitReason)
 {
     RunId      = runId;
     Elapsed    = elapsed;
     ExitReason = exitReason;
     ProcessingNotificationsCollector = processingNotificationsCollector;
     WorkbookGeneratorResults         = workbookGeneratorResults;
     ProcessLogSetResult = processLogSetResult;
     PublisherResults    = publisherResults;
     ReasonForFailure    = reasonForFailure;
 }
Example #3
0
 public static RunSummary FailedRunSummary(
     string runId,
     string errorMessage,
     ExitReason exitReason = ExitReason.UnclassifiedError,
     ProcessingNotificationsCollector processingNotificationsCollector = null,
     TimeSpan?elapsed = null,
     ProcessLogSetResult processLogSetResult           = null,
     WorkbookGeneratorResults workbookGeneratorResults = null,
     PublisherResults publisherResults = null)
 {
     return(new RunSummary(
                runId,
                elapsed ?? TimeSpan.Zero,
                processingNotificationsCollector,
                processLogSetResult,
                workbookGeneratorResults,
                publisherResults,
                errorMessage,
                exitReason));
 }
Example #4
0
        private async Task <RunSummary> ProcessLog(IWriterFactory customWriterFactory)
        {
            _logger.LogInformation("Starting to process Log set {logSetPath}", _config.LogSetLocation);
            var totalElapsedTimer = Stopwatch.StartNew();

            if (_config.OutputDirMaxResultsToKeep != null)
            {
                OutputDirTrimmer.TrimOldResults(_config.OutputDir, _config.OutputDirMaxResultsToKeep.Value, _loggerFactory.CreateLogger(nameof(OutputDirTrimmer)));
            }

            var runId = GetRunId(_config.ForceRunId);

            var fileCheckResult = TableauLogsExtractor.FileCanBeOpened(_config.LogSetLocation, _logger);

            if (!fileCheckResult.FileCanBeOpened)
            {
                var error = $"Path `{_config.LogSetLocation}` does not exist or LogShark cannot open it. Make sure `LogSetLocation` parameter points to the valid zip files with Tableau logs or unzipped copy of it. Exception message was: {fileCheckResult.ErrorMessage ?? "(null)"}";
                _logger.LogInformation(error);
                return(RunSummary.FailedRunSummary(runId, error, ExitReason.BadLogSet, _processingNotificationsCollector, totalElapsedTimer.Elapsed));
            }

            IWriterFactory writerFactory;

            try
            {
                writerFactory = customWriterFactory ?? GetWriterFactory(runId);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Context: 0x86a93465"))
                {
                    _logger.LogError("Microsoft Visual C++ Runtime required to run LogShark. Please download and install it from 'https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads' and rerun application");
                }

                var error = $"Exception occurred while initializing writer factory for writer '{_config.RequestedWriter ?? "null"}'. Exception message: {ex.Message}";
                _logger.LogError(ex, error);

                return(RunSummary.FailedRunSummary(runId, error, ExitReason.UnclassifiedError, _processingNotificationsCollector, totalElapsedTimer.Elapsed));
            }

            using (_logger.BeginScope(runId))
                using (writerFactory)
                {
                    ProcessLogSetResult logSetProcessingResults;
                    using (var pluginManager = new PluginManager(_config, _loggerFactory))
                    {
                        var logTypeDetails    = new LogTypeDetails(_processingNotificationsCollector);
                        var tableauLogsReader = new TableauLogsProcessor(_config, pluginManager, writerFactory, logTypeDetails, _processingNotificationsCollector, _loggerFactory);
                        logSetProcessingResults = tableauLogsReader.ProcessLogSet();
                    }

                    if (logSetProcessingResults.IsSuccessful)
                    {
                        var pluginsReceivedAnyDataForLogs = string.Join(", ",
                                                                        logSetProcessingResults.PluginsReceivedAnyData.OrderBy(name => name));
                        _logger.LogInformation("Plugins that had any data sent to them: {pluginsReceivedAnyData}", pluginsReceivedAnyDataForLogs);
                    }
                    else
                    {
                        _logger.LogDebug($"Log processing failed with error: {logSetProcessingResults.ErrorMessage}");
                        return(RunSummary.FailedRunSummary(runId, logSetProcessingResults.ErrorMessage, logSetProcessingResults.ExitReason, _processingNotificationsCollector, totalElapsedTimer.Elapsed, logSetProcessingResults));
                    }

                    var workbookGenerator = writerFactory.GetWorkbookGenerator();
                    var generatorResults  = workbookGenerator.CompleteWorkbooksWithResults(logSetProcessingResults.PluginsExecutionResults.GetWritersStatistics());

                    if (!GeneratedAnyWorkbooks(generatorResults.CompletedWorkbooks) && workbookGenerator.GeneratesWorkbooks)
                    {
                        const string errorMessage = "No workbooks were generated successfully.";
                        _logger.LogError(errorMessage);
                        return(RunSummary.FailedRunSummary(runId, errorMessage, ExitReason.UnclassifiedError, _processingNotificationsCollector, totalElapsedTimer.Elapsed, logSetProcessingResults, generatorResults));
                    }

                    PublisherResults publisherResults = null;
                    if (_config.PublishWorkbooks)
                    {
                        var projectDescription = GetProjectDescription();
                        var workbookPublisher  = writerFactory.GetWorkbookPublisher(_publisherSettings);

                        publisherResults = await workbookPublisher.PublishWorkbooks(
                            runId,
                            projectDescription,
                            generatorResults.CompletedWorkbooks,
                            logSetProcessingResults.PluginsExecutionResults.GetSortedTagsFromAllPlugins());

                        if (!publisherResults.CreatedProjectSuccessfully)
                        {
                            var errorMessage = $"Workbook publisher failed to connect to the Tableau Server or create project for the results. Exception message: {publisherResults.ExceptionCreatingProject.Message}";
                            _logger.LogError(errorMessage);
                            return(RunSummary.FailedRunSummary(runId, errorMessage, ExitReason.UnclassifiedError, _processingNotificationsCollector, totalElapsedTimer.Elapsed, logSetProcessingResults, generatorResults, publisherResults));
                        }
                    }

                    _logger.LogInformation("Done processing {logSetPath}. Whole run took {fullRunElapsedTime}", _config.LogSetLocation, totalElapsedTimer.Elapsed);
                    return(RunSummary.SuccessfulRunSummary(runId, totalElapsedTimer.Elapsed, _processingNotificationsCollector, logSetProcessingResults, generatorResults, publisherResults));
                }
        }