/// <summary>
        /// Creates a diagnostics report from the perspective of the client connected to each of the requeted services.
        /// </summary>
        /// <param name="reportId">The report identifer.</param>
        /// <returns>An <see cref="IDiagnosticsReport"/> with details of connected services.</returns>
        public IDiagnosticsReport Diagnostics(string reportId)
        {
            if (string.IsNullOrWhiteSpace(reportId))
            {
                throw new ArgumentException(nameof(reportId));
            }

            var configs = _clusterController.Buckets.Cast <IConfigObserver>().Select(x => x.ConfigInfo);

            return(DiagnosticsReportProvider.CreateDiagnosticsReport(reportId, configs));
        }
Beispiel #2
0
        public void Can_Create_DiagnosticsReport()
        {
            var reportId              = Guid.NewGuid().ToString();
            var kvLastActivity        = DateTime.UtcNow;
            var viewLastActivity      = kvLastActivity.AddSeconds(-5);
            var queryLastActivity     = kvLastActivity.AddSeconds(-10);
            var searchLastActivity    = kvLastActivity.AddSeconds(-15);
            var analyticsLastActivity = kvLastActivity.AddSeconds(-20);

            var connection = Mock.Of <IConnection>(c =>
                                                   c.LastActivity == kvLastActivity &&
                                                   c.IsConnected == true &&
                                                   c.IsAuthenticated == true
                                                   );

            var connectionPool = Mock.Of <IConnectionPool>(p =>
                                                           p.Connections == new List <IConnection> {
                connection
            }
                                                           );

            var server = Mock.Of <IServer>(s =>
                                           s.IsDataNode == true &&
                                           s.ConnectionPool == connectionPool &&
                                           s.IsViewNode == true &&
                                           s.ViewClient.LastActivity == viewLastActivity &&
                                           s.IsQueryNode == true &&
                                           s.QueryClient.LastActivity == queryLastActivity &&
                                           s.IsSearchNode == true &&
                                           s.SearchClient.LastActivity == searchLastActivity &&
                                           s.IsAnalyticsNode == true &&
                                           s.AnalyticsClient.LastActivity == analyticsLastActivity
                                           );

            var configInfo = Mock.Of <IConfigInfo>(c =>
                                                   c.Servers == new List <IServer> {
                server
            }
                                                   );

            var report = DiagnosticsReportProvider.CreateDiagnosticsReport(reportId, new[] { configInfo });

            Assert.IsNotNull(report);
            Assert.AreEqual(reportId, report.Id);
            Assert.AreEqual(1, report.Version);
            Assert.AreEqual(ClientIdentifier.GetClientDescription(), report.Sdk);

            Assert.IsTrue(report.Services["kv"].First(x => x.Type == ServiceType.KeyValue).LastActivity > 0);
            Assert.IsTrue(report.Services["view"].First(x => x.Type == ServiceType.Views).LastActivity > 0);
            Assert.IsTrue(report.Services["n1ql"].First(x => x.Type == ServiceType.Query).LastActivity > 0);
            Assert.IsTrue(report.Services["fts"].First(x => x.Type == ServiceType.Search).LastActivity > 0);
            Assert.IsTrue(report.Services["cbas"].First(x => x.Type == ServiceType.Analytics).LastActivity > 0);
        }
Beispiel #3
0
 public Task <IDiagnosticsReport> DiagnosticsAsync(DiagnosticsOptions?options = null)
 {
     options ??= new DiagnosticsOptions();
     return(Task.FromResult(DiagnosticsReportProvider.CreateDiagnosticsReport(_context, options.ReportIdValue ?? Guid.NewGuid().ToString())));
 }