Example #1
0
        private static void ConfigureAspNetHealthCheckInfrastructure(ISolariBuilder builder, IoOptions options,
                                                                     Action <IHealthChecksBuilder> addChecks)
        {
            IHealthChecksBuilder healthChecks = builder.Services.AddHealthChecks();

            addChecks?.Invoke(healthChecks);
        }
        public static ISolariBuilder AddCeres(this ISolariBuilder builder)
        {
            IConfigurationSection section = builder.Configuration.GetSection(CeresConstants.AppSettingsSection);

            if (!section.Exists())
            {
                throw new CeresException("Ceres AppSettings section not found!");
            }

            var options = section.GetOptions <CeresOptions>();

            ApplicationOptions appOptions = builder.GetAppOptions();
            var metricsBuilder            = new MetricsBuilder();

            if (!options.Enabled)
            {
                return(builder);
            }

            builder.Services.Configure <CeresOptions>(builder.Configuration.GetSection(CeresConstants.AppSettingsSection));

            ConfigureMetricsBuilder(metricsBuilder, options, appOptions);
            builder.Services.AddMetrics(metricsBuilder.Build());
            builder.Services.AddMetricsEndpoints();
            ConfigureReporters.ConfigurePrometheus(options, metricsBuilder);
            ConfigureInfluxDb(builder, options, metricsBuilder);
            ConfigureEndpoints(builder, options);
            ConfigureMiddleware(builder, options.Middlewares);
            ConfigureCpuUsageMetric(builder, options.CollectCpuMetrics);
            ConfigureMemoryUsageMetric(builder, options.CollectMemoryMetrics);
            return(builder);
        }
Example #3
0
 public static ISolariBuilder AddCallistoIdentityProvider <TUser>(this ISolariBuilder builder,
                                                                  string clientName,
                                                                  string database)
     where TUser : MongoUser
 {
     return(builder.AddCallistoIdentityProvider <TUser, MongoRole>(clientName, database, null));
 }
        private static void ConfigureEndpoints(ISolariBuilder builder, CeresOptions options)
        {
            builder.AddBuildAction(new BuildAction("Ceres Endpoints")
            {
                Action = provider =>
                {
                    var appBuilder = provider.GetService <ISolariMarshal>();
                    if (appBuilder == null)
                    {
                        return;
                    }

                    if (options.UseEnvEndpoint)
                    {
                        appBuilder.ApplicationBuilder.UseEnvInfoEndpoint();
                    }
                    if (options.UseProtoEndpoint)
                    {
                        appBuilder.ApplicationBuilder.UseMetricsEndpoint();
                    }
                    if (options.UseTextEndpoint)
                    {
                        appBuilder.ApplicationBuilder.UseMetricsTextEndpoint();
                    }
                }
            });
        }
Example #5
0
        private static void ConfigureUi(ISolariBuilder builder, IoOptions options)
        {
            if (!options.EnableUi)
            {
                return;
            }

            builder.Services.AddHealthChecksUI(a =>
            {
                a.DisableDatabaseMigrations();
                a.SetEvaluationTimeInSeconds(options.Interval);
                ConfigureHealthEndpoints(builder, a, options);
                ConfigureWebHooks(a, options);
            })
            .AddInMemoryStorage();
            builder.AddBuildAction(new BuildAction("HealthCheckUI")
            {
                Action = provider =>
                {
                    var app = provider.GetService <IApplicationBuilder>();
                    if (app == null)
                    {
                        return;
                    }
                    app.UseHealthChecksUI();
                }
            });
        }
        public static ISolariBuilder AddOberon(this ISolariBuilder builder)
        {
            IConfigurationSection section = builder.Configuration.GetSection(OberonLibConstants.AppSettingsSection);

            if (!section.Exists())
            {
                throw new OberonException("Oberon AppSettings section does not exists.");
            }

            var options = section.GetOptions <OberonOptions>();

            if (!options.Enabled)
            {
                return(builder);
            }

            builder.Services.Configure <OberonOptions>(section);
            builder.Services.AddDistributedRedisCache(config =>
            {
                config.Configuration = options.ConnectionString;
                config.InstanceName  = options.Instance;
            });

            builder.Services.AddSingleton <IOberon, Oberon>();
            return(builder);
        }
Example #7
0
 public static ISolariBuilder AddRhea(this ISolariBuilder builder, Action <RheaPipelineConfigurator> configure)
 {
     Check.ThrowIfNull(configure, nameof(Action <RheaPipelineConfigurator>));
     builder.AddVanth();
     configure(new RheaPipelineConfigurator(builder));
     return(builder);
 }
Example #8
0
        public static ISolariBuilder AddHyperion(this ISolariBuilder builder)
        {
            HyperionOptions options = ConfigureHyperionOptions(builder.Services, builder.Configuration);

            AddHyperionCoreServices(builder.Services, options);
            RegisterApplication(builder.Services, options);
            return(builder);
        }
 private static void ConfigureMemoryUsageMetric(ISolariBuilder builder, bool enabled)
 {
     if (!enabled)
     {
         return;
     }
     builder.Services.AddHostedService <MemoryMeasurementHostedService>();
 }
 private static void ConfigureInfluxDb(ISolariBuilder builder, CeresOptions options, IMetricsBuilder metricsBuilder)
 {
     if (options.InfluxDb is null || !options.InfluxDb.Enabled)
     {
         return;
     }
     ConfigureReporters.ConfigureInfluxDbReporter(options, metricsBuilder);
     builder.Services.AddMetricsReportingHostedService();
 }
Example #11
0
 /// <summary>
 /// Configures the library to use default class maps and conventions.
 /// It also adds the callisto connector.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="configure"></param>
 /// <returns></returns>
 public static ISolariBuilder AddCallistoWithDefaults(this ISolariBuilder builder,
                                                      Action <ICallistoClientConfigurator> configure,
                                                      ServiceLifetime factoriesLifetime)
 {
     builder.AddCallisto(registry => registry.AddDefaultConventions().RegisterConventionPack(),
                         mapper => mapper.RegisterClassMaps(GetCallistoTypes(ReadAppDomain())),
                         configure, factoriesLifetime);
     return(builder);
 }
Example #12
0
 private static void ConfigureFluentValidation(VanthOptions options, ISolariBuilder builder)
 {
     if (!options.UseFluentValidation)
     {
         return;
     }
     builder.Services.TryAddSingleton <IVanthValidationService, VanthValidationService>();
     builder.Services.TryAddSingleton <IValidatorFactory, VanthValidatorFactory>();
     builder.Services.AddValidatorsFromAssemblies(AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic));
 }
Example #13
0
        public static void ConfigureHealthEndpoints(ISolariBuilder builder, Settings settings, IoOptions options)
        {
            if (options.Endpoints == null || !options.Endpoints.Any())
            {
                settings.AddHealthCheckEndpoint(builder.GetAppOptions().ApplicationName, options.HealthEndpoint);
                return;
            }

            options.Endpoints.ForEach(a => settings.AddHealthCheckEndpoint(a.Name, a.Uri));
        }
Example #14
0
        private static void ConfigureHttpIn(ISolariBuilder builder, DeimosOptions options)
        {
            builder.Services.AddOpenTracing(build => build.ConfigureAspNetCore(diagnosticOptions =>
            {
                ConfigureHttpInRequestFiltering(diagnosticOptions, options);

                diagnosticOptions.Hosting.ExtractEnabled = message => true;
                DeimosLogger.JaegerLogger.ConfiguredHttpIn();
            }));
        }
Example #15
0
 public static ISolariBuilder AddCallistoIdentityProvider(this ISolariBuilder builder,
                                                          string clientName,
                                                          string database,
                                                          Action <IdentityOptions> setupIdentity)
 {
     return(builder.AddCallistoIdentityProvider <MongoUser, MongoRole>(opt =>
     {
         opt.ClientName = clientName;
         opt.Database = database;
     }, setupIdentity));
 }
Example #16
0
        public static ISolariBuilder AddJaeger(ISolariBuilder solariBuilder, DeimosOptions options)
        {
            if (!options.Enabled)
            {
                return(solariBuilder);
            }

            ConfigureHttpOut(solariBuilder, options);
            ConfigureHttpIn(solariBuilder, options);
            ConfigureTracer(solariBuilder, options.Jaeger);
            return(solariBuilder);
        }
        private static void ConfigureMiddleware(ISolariBuilder builder, MetricsTrackingMiddlewareOptions options)
        {
            if (options is null)
            {
                return;
            }

            builder.Services.AddMetricsTrackingMiddleware(a =>
            {
                a.ApdexTrackingEnabled   = options.ApdexTracking;
                a.ApdexTSeconds          = options.ApdexSeconds;
                a.IgnoredHttpStatusCodes = options.IgnoredHttpStatusCodes;
                a.OAuth2TrackingEnabled  = options.OAuth2Tracking;
            });

            builder.AddBuildAction(new BuildAction("Ceres Middleware")
            {
                Action = provider =>
                {
                    var appBuilder = provider.GetService <ISolariMarshal>();
                    if (appBuilder == null)
                    {
                        return;
                    }

                    if (options.ApdexTracking)
                    {
                        appBuilder.ApplicationBuilder.UseMetricsApdexTrackingMiddleware();
                    }
                    if (options.PostAndPutSizeTracking)
                    {
                        appBuilder.ApplicationBuilder.UseMetricsPostAndPutSizeTrackingMiddleware();
                    }
                    if (options.RequestTracking)
                    {
                        appBuilder.ApplicationBuilder.UseMetricsRequestTrackingMiddleware();
                    }
                    if (options.OAuth2Tracking)
                    {
                        appBuilder.ApplicationBuilder.UseMetricsOAuth2TrackingMiddleware();
                    }
                    if (options.ErrorTracking)
                    {
                        appBuilder.ApplicationBuilder.UseMetricsErrorTrackingMiddleware();
                    }
                    if (options.ActiveRequests)
                    {
                        appBuilder.ApplicationBuilder.UseMetricsActiveRequestMiddleware();
                    }
                }
            });
        }
Example #18
0
        private static void ConfigureHttpOut(ISolariBuilder builder, DeimosOptions options)
        {
            builder.Services.PostConfigure <HttpHandlerDiagnosticOptions>(conf =>
            {
                conf.InjectEnabled = message => true;
                foreach (string httpIgnoredEndpoint in options.Http.IgnoredOutEndpoints)
                {
                    conf.IgnorePatterns.Add(context => context.RequestUri.OriginalString.Contains(httpIgnoredEndpoint));
                }

                DeimosLogger.JaegerLogger.ConfiguredHttpOut();
            });
        }
Example #19
0
        public static ISolariBuilder AddThemis(this ISolariBuilder builder, bool addHealthChecks,
                                               Action <ITracerPluginManager> tracingPlugins = null,
                                               Action <IHealthChecksBuilder> healthChecks   = null)
        {
            if (addHealthChecks)
            {
                builder.AddIo(healthChecks);
            }

            builder.AddDeimos(tracingPlugins);
            builder.Services.TryAdd(ServiceDescriptor.Singleton(typeof(IThemis <>), typeof(Themis <>)));
            return(builder);
        }
        public static ISolariBuilder AddConnectorCoreServices(this ISolariBuilder builder)
        {
            builder.Services.AddSingleton(provider => CallistoClientRegistry.Instance);

            builder.Services.AddTransient <IEventFilter, EventFilter>();
            builder.Services.Configure <CallistoTracerOptions>(builder.Configuration.GetSection(CallistoConstants.TracerAppSettingsSection));
            builder.Services.AddSingleton <ICallistoEventListener>(provider =>
            {
                var eventFilter           = provider.GetService <IEventFilter>();
                var callistoTracerOptions = provider.GetService <IOptions <CallistoTracerOptions> >();
                return(new CallistoJaegerEventListener(provider.GetService <ITracer>(), eventFilter, callistoTracerOptions));
            });
            return(builder);
        }
        public static ISolariBuilder AddGanymede(this ISolariBuilder builder,
                                                 Action <GanymedePolicyRegistry> configurePoliceRegistry,
                                                 Action <GanymedeClientActions> configureClients)
        {
            if (configurePoliceRegistry != null)
            {
                var registry = new GanymedePolicyRegistry();
                configurePoliceRegistry.Invoke(registry);
                builder.Services.AddPolicyRegistry(registry.PolicyRegistry);
            }

            configureClients(new GanymedeClientActions(builder, builder.Configuration));
            return(builder);
        }
Example #22
0
        public static ISolariBuilder AddCallistoIdentityProvider <TUser>(this ISolariBuilder builder,
                                                                         Action <CallistoIdentityOptions>
                                                                         setupOptions,
                                                                         Action <IdentityOptions> setupIdentity)
            where TUser : MongoUser
        {
            var opt = new CallistoIdentityOptions();

            setupOptions(opt);

            return(builder.AddCallistoIdentityProvider <TUser, MongoRole>(opt.ClientName, opt.Database,
                                                                          opt.UsersCollection,
                                                                          opt.RolesCollection, setupIdentity));
        }
Example #23
0
        private static ISolariBuilder ConfigureTracer(ISolariBuilder builder, JaegerOptions options)
        {
            builder.Services.AddSingleton(sp =>
            {
                var loggerFactory             = sp.GetRequiredService <ILoggerFactory>();
                ApplicationOptions appOptions = sp.GetService <IOptions <ApplicationOptions> >().Value;
                ITracer tracer = BuildTracer(options, appOptions, loggerFactory);
                GlobalTracer.Register(tracer);
                DeimosLogger.JaegerLogger.ConfiguredTracer();
                DeimosLogger.JaegerLogger.UsingJaegerTracing();
                return(tracer);
            });

            return(builder);
        }
Example #24
0
        /// <summary>
        ///     Add Vanth into the DI Container.
        /// </summary>
        /// <param name="builder">
        ///     <see cref="ISolariBuilder" />
        /// </param>
        /// <returns>
        ///     <see cref="ISolariBuilder" />
        /// </returns>
        public static ISolariBuilder AddVanth(this ISolariBuilder builder)
        {
            IConfigurationSection section = builder.Configuration.GetSection(VanthLibConstants.AppSettingsSection);

            if (!section.Exists())
            {
                builder.Services.TryAddTransient <IResultFactory, ResultFactory>();
                return(builder);
            }

            var opt = section.GetOptions <VanthOptions>();

            ConfigureFluentValidation(opt, builder);
            ConfigureExceptionMiddleware(opt, builder, section);
            return(builder);
        }
Example #25
0
        public static ISolariBuilder AddCallisto(this ISolariBuilder builder,
                                                 Action <ICallistoConventionRegistry> conventionPackAction,
                                                 Action <ICallistoClassMapper> classMapAction,
                                                 Action <ICallistoClientConfigurator> configure,
                                                 ServiceLifetime factoriesLifetime)
        {
            AddCoreServices(builder, factoriesLifetime);
            classMapAction?.Invoke(new CallistoClassMapper());
            conventionPackAction?.Invoke(new CallistoConventionRegistry());


            IConfigurationSection section = builder.Configuration.GetSection(CallistoConstants.ConnectorAppSettingsSection);
            var options = section.GetOptions <List <CallistoConnectorOptions> >();

            configure?.Invoke(new CallistoClientConfigurator(builder, options));
            return(builder);
        }
Example #26
0
        public static ISolariBuilder AddCallistoIdentityProvider <TUser, TRole>(this ISolariBuilder builder,
                                                                                string clientName,
                                                                                string database,
                                                                                string usersCollection,
                                                                                string rolesCollection,
                                                                                Action <IdentityOptions> setupIdentity)
            where TUser : MongoUser
            where TRole : MongoRole
        {
            IdentityBuilder identityBuilder = builder.Services.AddIdentity <TUser, TRole>(setupIdentity ?? (x => { }));

            identityBuilder.AddRoleStore <RoleStore <TRole> >()
            .AddUserStore <UserStore <TUser, TRole> >()
            .AddUserManager <UserManager <TUser> >()
            .AddRoleManager <RoleManager <TRole> >()
            .AddDefaultTokenProviders();


            var conventions = new CallistoConventionRegistry();

            conventions.AddDefaultConventions();
            conventions.RegisterConventionPack("CallistoIdentityConventionPack", type =>
            {
                bool user = typeof(TUser).IsAssignableFrom(typeof(MongoUser)) && typeof(TUser) == type;
                bool role = typeof(TRole).IsAssignableFrom(typeof(MongoRole)) && typeof(TRole) == type;
                return(user && role);
            });
            ApplicationOptions       app     = builder.GetAppOptions();
            CallistoConnectorOptions options = builder.Configuration.GetCallistoConnectorOptions(clientName);
            IMongoCollection <TUser> users   = MongoUtil.FromCallistoConnectorOptions <TUser>(options, app, usersCollection, database);
            IMongoCollection <TRole> roles   = MongoUtil.FromCallistoConnectorOptions <TRole>(options, app, rolesCollection, database);

            builder.Services.AddSingleton(x => users);
            builder.Services.AddSingleton(x => roles);

            // Identity Services
            builder.Services.AddTransient <IRoleStore <TRole> >(x => new RoleStore <TRole>(roles));
            builder.Services.AddTransient <IUserStore <TUser> >(x => new UserStore <TUser, TRole>(users, new RoleStore <TRole>(roles), x.GetService <ILookupNormalizer>()));


            return(builder);
        }
Example #27
0
 private static void ConfigureExceptionMiddleware(VanthOptions options, ISolariBuilder builder, IConfigurationSection section)
 {
     if (!options.UseExceptionHandlingMiddleware)
     {
         return;
     }
     builder.Services.Configure <VanthOptions>(section);
     builder.AddBuildAction(new BuildAction("Solari.Vanth (ExceptionHandlingMiddleware)")
     {
         Action = provider =>
         {
             var marshal = provider.GetService <ISolariMarshal>();
             if (marshal.ApplicationBuilder == null)
             {
                 return;
             }
             marshal.ApplicationBuilder.UseMiddleware <ExceptionHandlingMiddleware>();
         }
     });
 }
        /// <summary>
        ///     Add Deimos CorrelationId infrastructure into the DI Container.
        /// </summary>
        /// <param name="solariBuilder">The builder</param>
        /// <param name="useMiddleware">Indicates if <see cref="CorrelationIdMiddleware" /> should be used</param>
        /// <returns></returns>
        public static ISolariBuilder AddDeimosCorrelationId(this ISolariBuilder solariBuilder, bool useMiddleware)
        {
            if (useMiddleware)
            {
                solariBuilder.Services.AddSingleton <ICorrelationContextFactory, CorrelationContextFactory>();
                solariBuilder.Services.AddSingleton <ICorrelationContextAccessor, CorrelationContextAccessor>();
                solariBuilder.Services.AddSingleton <ICorrelationContextManager, CorrelationContextManager>();

                solariBuilder.AddBuildAction(new BuildAction("Deimos CorrelationId")
                {
                    Action = provider =>
                    {
                        var marshal = provider.GetRequiredService <ISolariMarshal>();
                        marshal.ApplicationBuilder?.UseMiddleware <CorrelationIdMiddleware>();
                        DeimosLogger.CorrelationIdLogger.UsingCorrelationIdMiddleware();
                    }
                });
            }
            return(solariBuilder);
        }
Example #29
0
        public static ISolariBuilder AddIo(this ISolariBuilder builder, Action <IHealthChecksBuilder> addChecks = null)
        {
            IConfigurationSection section = builder.Configuration.GetSection(IoConstants.AppSettingsSection);

            if (!section.Exists())
            {
                throw new IOException("Io AppSettings section not found!");
            }
            var options = section.GetOptions <IoOptions>();

            builder.Services.Configure <IoOptions>(section);
            if (!options.Enabled)
            {
                return(builder);
            }
            ConfigureAspNetHealthCheckInfrastructure(builder, options, addChecks);
            ConfigureUi(builder, options);


            return(builder);
        }
Example #30
0
        public static ISolariBuilder AddDeimos(this ISolariBuilder solariBuilder, Action <ITracerPluginManager> plugins = null)
        {
            IConfigurationSection section = solariBuilder.Configuration.GetSection(DeimosConstants.TracingAppSettingsSection);

            if (!section.Exists())
            {
                throw new DeimosException("Deimos AppSettings section not found!");
            }

            var options = section.GetOptions <DeimosOptions>();

            solariBuilder.Services.Configure <DeimosOptions>(section);

            ConfigureTracing(solariBuilder, options);

            if (plugins == null)
            {
                return(solariBuilder);
            }
            var manager = new TracerPluginManager(solariBuilder);

            plugins(manager);
            return(solariBuilder);
        }