Beispiel #1
0
        public Monitor(Configuration configuration)
        {
            Contract.RequiresNotNull(configuration);
            _configuration = configuration;

            _logger = CreateLogger();

            Contract.RequiresNotNullOrEmpty(_configuration.KustoIngestionClusterUrl);
            Contract.RequiresNotNullOrEmpty(_configuration.ApplicationClientId);
            Contract.RequiresNotNullOrEmpty(_configuration.ApplicationKey);
            Contract.RequiresNotNullOrEmpty(_configuration.Authority);
            var kustoIngestConnectionString = new KustoConnectionStringBuilder(_configuration.KustoIngestionClusterUrl)
                                              .WithAadApplicationKeyAuthentication(_configuration.ApplicationClientId, _configuration.ApplicationKey, _configuration.Authority);

            _kustoIngestClient = KustoIngestFactory.CreateDirectIngestClient(kustoIngestConnectionString);

            var kustoConnectionString = new KustoConnectionStringBuilder(_configuration.KustoClusterUrl)
                                        .WithAadApplicationKeyAuthentication(_configuration.ApplicationClientId, _configuration.ApplicationKey, _configuration.Authority);

            _cslQueryProvider = KustoClientFactory.CreateCslQueryProvider(kustoConnectionString);

            Contract.RequiresNotNull(_configuration.KustoNotifier);
            _alertNotifier = new KustoWriter <Notification>(_configuration.KustoNotifier, _logger, _kustoIngestClient);

            Contract.RequiresNotNull(_configuration.SchedulerKustoNotifier);
            _schedulerLogWriter = new KustoWriter <Scheduler.LogEntry>(_configuration.SchedulerKustoNotifier, _logger, _kustoIngestClient);

            _scheduler = new Scheduler(_configuration.Scheduler, _logger, _clock, _schedulerLogWriter);
        }
Beispiel #2
0
        public Monitor(Configuration configuration)
        {
            Contract.RequiresNotNull(configuration);
            _configuration = configuration;

            _logger = CreateLogger();

            // TODO(jubayard): use streaming ingestion instead of direct ingestion. There seems to be some assembly
            // issues when attempting to do that
            Contract.RequiresNotNullOrEmpty(_configuration.KustoIngestionClusterUrl);
            Contract.RequiresNotNullOrEmpty(_configuration.ApplicationClientId);
            Contract.RequiresNotNullOrEmpty(_configuration.ApplicationKey);
            Contract.RequiresNotNullOrEmpty(_configuration.Authority);
            var kustoIngestConnectionString = new KustoConnectionStringBuilder(_configuration.KustoIngestionClusterUrl)
                                              .WithAadApplicationKeyAuthentication(_configuration.ApplicationClientId, _configuration.ApplicationKey, _configuration.Authority);

            _kustoIngestClient = KustoIngestFactory.CreateDirectIngestClient(kustoIngestConnectionString);

            var kustoConnectionString = new KustoConnectionStringBuilder(_configuration.KustoClusterUrl)
                                        .WithAadApplicationKeyAuthentication(_configuration.ApplicationClientId, _configuration.ApplicationKey, _configuration.Authority);

            _cslQueryProvider = KustoClientFactory.CreateCslQueryProvider(kustoConnectionString);

            Contract.RequiresNotNull(_configuration.KustoNotifier);
            _alertNotifier = new KustoWriter <Notification>(_configuration.KustoNotifier, _logger, _kustoIngestClient);

            Contract.RequiresNotNull(_configuration.SchedulerKustoNotifier);
            _schedulerLogWriter = new KustoWriter <Scheduler.LogEntry>(_configuration.SchedulerKustoNotifier, _logger, _kustoIngestClient);

            _scheduler = new Scheduler(_configuration.Scheduler, _logger, _clock, _schedulerLogWriter);
        }
Beispiel #3
0
        public int Execute(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            List <AdoBuildResultRow> rows = new List <AdoBuildResultRow>();

            if (!JenkinsConsoleUtility.TryGetArgVar(out pat, argsLc, "days"))
            {
                days = 3;
            }
            pat = JenkinsConsoleUtility.GetArgVar(argsLc, "pat");
            string kustoConfigFile = JenkinsConsoleUtility.GetArgVar(argsLc, "kustoConfig");

            if (!File.Exists(kustoConfigFile))
            {
                throw new ArgumentException("kustoConfig file does not exist.");
            }
            string      kustoConfigJson = File.ReadAllText(kustoConfigFile);
            KustoConfig kustoConfig     = JsonConvert.DeserializeObject <KustoConfig>(kustoConfigJson);

            kustoWriter = new KustoWriter(kustoConfig);

            Task <string> getBuildsTask = Task.Run(GetBuilds);
            string        buildJson     = getBuildsTask.Result;

            var builds     = JsonConvert.DeserializeObject <GetBuildsResult>(buildJson);
            var tabbedJson = JsonConvert.SerializeObject(builds, Formatting.Indented);

            File.WriteAllText("temp.json", tabbedJson);
            var buildReports = ProcessBuildList(builds.value);

            foreach (var eachReportPair in buildReports)
            {
                JcuUtil.FancyWriteToConsole(ConsoleColor.DarkCyan, eachReportPair.Value.name);
                foreach (var eachDailyResultPair in eachReportPair.Value.dailyResults)
                {
                    if (eachDailyResultPair.Key > days)
                    {
                        continue; // Skip the old tests
                    }
                    DateTime date;
                    int      passed, failed, others, total;
                    BuildReport.Count(eachDailyResultPair.Value, out date, out passed, out failed, out others, out total);
                    JcuUtil.FancyWriteToConsole(
                        ConsoleColor.White, eachDailyResultPair.Key, " days ago(", date, "): (",
                        ConsoleColor.Green, "P: ", passed, ConsoleColor.White, "/",
                        ConsoleColor.Red, "F:", failed, ConsoleColor.White, "/",
                        ConsoleColor.DarkYellow, "O:", others, ConsoleColor.White, "/",
                        ConsoleColor.Cyan, "T:", total, ConsoleColor.White, ")");
                    rows.Add(new AdoBuildResultRow(eachReportPair.Value.name, passed, failed, others, total, date));
                }
            }

            bool success = kustoWriter.WriteDataForTable(false, rows);

            return(success && builds.value.Count > 0 ? 0 : 1);
        }
Beispiel #4
0
        private Monitor(Configuration configuration, IKustoIngestClient kustoIngestClient, ICslQueryProvider cslQueryProvider, IClock clock, IReadOnlyDictionary <CloudBuildEnvironment, EnvironmentResources> environmentResources, ILogger logger)
        {
            _configuration = configuration;

            _clock                = clock;
            _logger               = logger;
            _kustoIngestClient    = kustoIngestClient;
            _cslQueryProvider     = cslQueryProvider;
            _environmentResources = environmentResources;

            _alertNotifier = new KustoWriter <Notification>(_configuration.KustoNotifier, _logger, _kustoIngestClient);

            _schedulerLogWriter = new KustoWriter <RuleScheduler.LogEntry>(_configuration.SchedulerKustoNotifier, _logger, _kustoIngestClient);

            _scheduler = new RuleScheduler(_configuration.Scheduler, _logger, _clock, _schedulerLogWriter);
        }
Beispiel #5
0
        private async Task <int> ExecuteAsync(Dictionary <string, string> argsLc, Dictionary <string, string> argsCased)
        {
            List <AdoBuildResultRow> rows = new List <AdoBuildResultRow>();

            string daysStr;

            if (!JenkinsConsoleUtility.TryGetArgVar(out daysStr, argsLc, "days") || !int.TryParse(daysStr, out days))
            {
                days = 3;
            }
            pat = JenkinsConsoleUtility.GetArgVar(argsLc, "pat");
            string kustoConfigFile = JenkinsConsoleUtility.GetArgVar(argsLc, "kustoConfig");

            if (!File.Exists(kustoConfigFile))
            {
                throw new ArgumentException("kustoConfig file does not exist.");
            }
            string      kustoConfigJson = File.ReadAllText(kustoConfigFile);
            KustoConfig kustoConfig     = JsonConvert.DeserializeObject <KustoConfig>(kustoConfigJson);

            kustoWriter = new KustoWriter(kustoConfig);

            GetPipelinesResult pipelines = await MakeAdoApiCall <GetPipelinesResult>(pipelinesUrl, "pipelines.json");

            if (!FilterPipelines(pipelines.value))
            {
                JcuUtil.FancyWriteToConsole(ConsoleColor.Red, "No pipelines found in expected folder: " + expectedFolderPrefix);
                return(1);
            }

            int buildsWritten = 0;

            foreach (var eachPipeline in pipelines.value)
            {
                GetBuildsResult builds = await MakeAdoApiCall <GetBuildsResult>(buildsUrl.Replace("{definitionId}", eachPipeline.id.ToString()), "builds" + eachPipeline.id + ".json");

                var buildReports = ProcessBuildList(builds.value);
                foreach (var eachReportPair in buildReports)
                {
                    JcuUtil.FancyWriteToConsole(ConsoleColor.DarkCyan, eachReportPair.Value.name);
                    foreach (var eachDailyResultPair in eachReportPair.Value.dailyResults)
                    {
                        if (eachDailyResultPair.Key > days)
                        {
                            continue; // Skip the old tests
                        }
                        DateTime date;
                        int      passed, failed, others, total;
                        BuildReport.Count(eachDailyResultPair.Value, out date, out passed, out failed, out others, out total);
                        JcuUtil.FancyWriteToConsole(
                            ConsoleColor.White, eachDailyResultPair.Key, " days ago(", date, "): (",
                            ConsoleColor.Green, "P: ", passed, ConsoleColor.White, "/",
                            ConsoleColor.Red, "F:", failed, ConsoleColor.White, "/",
                            ConsoleColor.DarkYellow, "O:", others, ConsoleColor.White, "/",
                            ConsoleColor.Cyan, "T:", total, ConsoleColor.White, ")");
                        rows.Add(new AdoBuildResultRow(eachReportPair.Value.name, passed, failed, others, total, date));
                    }
                }
                buildsWritten += builds.value.Count;
            }

            bool success = kustoWriter.WriteDataForTable(false, rows);

            return(success && buildsWritten > 0 ? 0 : 1);
        }