Beispiel #1
0
        public static async Task <Result <Monitor> > CreateAsync(OperationContext context, Configuration configuration)
        {
            Tracer.Info(context, "Creating Kusto ingest client");
            var kustoIngestClient = ExternalDependenciesFactory.CreateKustoIngestClient(configuration.KustoIngestionCredentials).ThrowIfFailure();

            IIcmClient icmClient;

            if (!configuration.ReadOnly)
            {
                Tracer.Info(context, "Creating KeyVault client");
                var keyVaultClient = new KeyVaultClient(
                    configuration.KeyVaultUrl,
                    configuration.KeyVaultCredentials.TenantId,
                    configuration.KeyVaultCredentials.AppId,
                    configuration.KeyVaultCredentials.AppKey,
                    SystemClock.Instance,
                    Constants.IcmCertificateCacheTimeToLive);

                Tracer.Info(context, "Creating IcM client");
                icmClient = new IcmClient(
                    keyVaultClient,
                    configuration.IcmUrl,
                    configuration.IcmConnectorId,
                    configuration.IcmCertificateName,
                    SystemClock.Instance);
            }
            else
            {
                Tracer.Info(context, "Using mock ICM client");
                icmClient = new MockIcmClient();
            }

            var environmentResources = new Dictionary <MonitorEnvironment, EnvironmentResources>();

            // This does a bunch of Azure API calls, which are really slow. Making them a bit faster by doing them
            // concurrently.
            await configuration.Environments.ParallelForEachAsync(async (keyValuePair) =>
            {
                var environment = keyValuePair.Key;
                var environmentConfiguration = keyValuePair.Value;

                Tracer.Info(context, $"Loading resources for environment `{environment}`");
                var resources = await CreateEnvironmentResourcesAsync(context, environmentConfiguration);

                lock (environmentResources)
                {
                    environmentResources[environment] = resources;
                }
            });

            context.Token.ThrowIfCancellationRequested();
            return(new Monitor(
                       configuration,
                       kustoIngestClient,
                       icmClient,
                       SystemClock.Instance,
                       environmentResources,
                       context.TracingContext.Logger));
        }
Beispiel #2
0
        public static async Task <Result <Monitor> > CreateAsync(OperationContext context, Configuration configuration)
        {
            Tracer.Info(context, "Creating Kusto ingest client");
            var kustoIngestClient = ExternalDependenciesFactory.CreateKustoIngestClient(configuration.KustoIngestionCredentials).ThrowIfFailure();

            IIcmClient icmClient;

            if (!configuration.ReadOnly)
            {
                Tracer.Info(context, "Creating KeyVault client");
                var keyVaultClient = new KeyVaultClient(
                    configuration.KeyVaultUrl,
                    configuration.KeyVaultCredentials.TenantId,
                    configuration.KeyVaultCredentials.AppId,
                    configuration.KeyVaultCredentials.AppKey,
                    SystemClock.Instance,
                    Constants.IcmCertificateCacheTimeToLive);

                Tracer.Info(context, "Creating IcM client");
                icmClient = new IcmClient(
                    keyVaultClient,
                    configuration.IcmUrl,
                    configuration.IcmConnectorId,
                    configuration.IcmCertificateName,
                    SystemClock.Instance);
            }
            else
            {
                Tracer.Info(context, "Using mock ICM client");
                icmClient = new MockIcmClient();
            }

            var environmentResources = await CreateEnvironmentResourcesAsync(context, configuration.Environments);

            context.Token.ThrowIfCancellationRequested();
            return(new Monitor(
                       configuration,
                       kustoIngestClient,
                       icmClient,
                       SystemClock.Instance,
                       environmentResources,
                       context.TracingContext.Logger));
        }