예제 #1
0
        public void MakeFromConfig_WithMissingAddress_ThrowsArgumentNullException()
        {
            var configurationRoot = new Mock <IConfigurationRoot>();

            // missing 'metadataElasticAddress'
            Assert.That(() => MetadataConnectionDetailsFactory.MakeFromConfiguration(configurationRoot.Object), Throws.TypeOf <ArgumentNullException>());
        }
예제 #2
0
        public void MakeFromConfig_WithValidValues_ReturnsValidConnectionDetails()
        {
            var configurationRoot = new Mock <IConfigurationRoot>();
            var contosoesAddress  = "http://contoso-es:1234/";

            configurationRoot.SetupGet(
                x => x[It.Is <string>(s => s.Equals("metadataElasticAddress", StringComparison.OrdinalIgnoreCase))]).Returns(contosoesAddress);

            var metadataConnectionDetails = MetadataConnectionDetailsFactory.MakeFromConfiguration(configurationRoot.Object);

            Assert.NotNull(metadataConnectionDetails);
            Assert.AreEqual(contosoesAddress, metadataConnectionDetails.MetadataEndpoint);
        }
예제 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigureTelemetryServices(services);

            services.AddControllers();

            services.AddSingleton(Log.Logger);

            services.AddSingleton <IConnectionDetails, KustoConnectionDetails>(
                s => KustoConnectionDetailsFactory.MakeFromConfiguration(Configuration as IConfigurationRoot));

            services.AddSingleton(
                s => MetadataConnectionDetailsFactory.MakeFromConfiguration(Configuration as IConfigurationRoot));

            services.AddSingleton <IQueryExecutor, KustoQueryExecutor>(
                s =>
            {
                var conn = KustoQueryExecutor
                           .CreateKustoConnectionStringBuilder(s.GetRequiredService <IConnectionDetails>());

                return(new KustoQueryExecutor(
                           KustoClientFactory.CreateCslQueryProvider(conn),
                           KustoClientFactory.CreateCslAdminProvider(conn),
                           s.GetRequiredService <ILogger <KustoQueryExecutor> >(),
                           s.GetRequiredService <Telemetry.Metrics>()));
            });

            services.AddHttpContextAccessor();
            services.AddScoped(
                s => new RequestContext(s.GetRequiredService <IHttpContextAccessor>()));

            services.AddTransient <ITranslator, ElasticQueryTranslator>();

            services.AddTransient <IKustoDataAccess, KustoDataAccess>(
                s => new KustoDataAccess(
                    s.GetRequiredService <IQueryExecutor>(),
                    s.GetRequiredService <RequestContext>(),
                    s.GetRequiredService <ILogger <KustoDataAccess> >()));

            services.AddTransient <ISchemaRetrieverFactory, SchemaRetrieverFactory>(
                s => new SchemaRetrieverFactory(
                    s.GetRequiredService <ILogger <SchemaRetriever> >(),
                    s.GetRequiredService <IKustoDataAccess>()));

            services.AddTransient <IVisitor, ElasticSearchDSLVisitor>(
                s => new ElasticSearchDSLVisitor(
                    s.GetRequiredService <ISchemaRetrieverFactory>(),
                    s.GetRequiredService <IConnectionDetails>().DefaultDatabaseName));

            services.AddTransient <IResponseParser, KustoResponseParser>(
                s => new KustoResponseParser(
                    s.GetRequiredService <ILogger <KustoResponseParser> >(),
                    bool.Parse((Configuration as IConfigurationRoot)["outputBackendQuery"]),
                    s.GetRequiredService <Telemetry.Metrics>()));

            // use this http client factory to issue requests to the metadata elastic instance
            services.AddHttpClient(MetadataController.ElasticMetadataClientName, (svcProvider, elasticClient) =>
            {
                var metadataConnectionDetails = svcProvider.GetRequiredService <MetadataConnectionDetails>();
                elasticClient.BaseAddress     = new Uri(metadataConnectionDetails.MetadataEndpoint);
            });

            // Add a health/liveness service
            services.AddHealthChecks();

            // required on ASP.NET Core 3 https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-2.2&tabs=visual-studio#jsonnet-support
            services.AddMvcCore().AddNewtonsoftJson();
        }