/// <summary>
        /// Add a health check for Kafka cluster.
        /// </summary>
        /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
        /// <param name="configurationSection">The <see cref="IConfigurationSection"/>.</param>
        /// <param name="topic">The topic name to produce kafka messages on. Optional.</param>
        /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'KafkaOrleansStreams' will be used for the name.</param>
        /// <param name="failureStatus">
        /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
        /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
        /// </param>
        /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
        /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns>
        public static IHealthChecksBuilder AddKafkaOrleansStreams([NotNull] this IHealthChecksBuilder builder,
                                                                  [NotNull] IConfigurationSection configurationSection, string topic = null,
                                                                  string name = Constants.DefaultHealthCheckName,
                                                                  HealthStatus?failureStatus = default, IEnumerable <string> tags = default)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configurationSection?.Exists() != true)
            {
                throw new ConfigurationErrorsException(
                          $"Configuration section '{configurationSection?.Path}' is incorrect.");
            }

            var streamsOptions = configurationSection.Get <KafkaOptions>();

            var producerOptions = new ProducerConfig {
                BootstrapServers = streamsOptions.Brokers.Replace(';', ',')
            };

            if (streamsOptions.Security.IsEnabled)
            {
                producerOptions.SaslUsername     = streamsOptions.Security.SaslUsername;
                producerOptions.SaslPassword     = streamsOptions.Security.SaslPassword;
                producerOptions.SecurityProtocol = (SecurityProtocol)(int)streamsOptions.Security.SecurityProtocol;
                producerOptions.SaslMechanism    = (SaslMechanism)(int)streamsOptions.Security.SaslMechanism;
            }

            var instance = new KafkaHealthCheck(producerOptions, topic ?? StreamHelper.GetNamespace("telemetry", "health-check"));

            return(builder.AddCachedCheck(name, _ => instance, failureStatus, tags));
        }
        ///  <summary>
        ///   Adds a new Cached HealthCheck with the specified name and implementation.
        ///  </summary>
        ///  <typeparam name="T">The HealthCheck type.</typeparam>
        ///  <param name="builder">The <see cref="IHealthChecksBuilder" />.</param>
        ///  <param name="name">The HealthCheck name.</param>
        /// <param name="failureStatus">
        /// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
        /// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
        /// </param>
        /// <param name="tags">A list of tags that can be used to filter health checks.</param>
        /// <param name="cacheExpirationMs">The Expiration of the Cache in milliseconds.</param>
        ///  <returns>The <see cref="IHealthChecksBuilder"/>.</returns>
        public static IHealthChecksBuilder AddCachedCheck <T>([NotNull] this IHealthChecksBuilder builder,
                                                              [NotNull] string name, HealthStatus?failureStatus = null, IEnumerable <string> tags = null,
                                                              ulong cacheExpirationMs = CachedHealthCheck.DefaultCacheExpirationMs)
            where T : class, IHealthCheck
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException($"'{nameof(name)}' must not be null, empty or whitespace.", nameof(name));
            }

            return(builder.AddCachedCheck(name, ActivatorUtilities.GetServiceOrCreateInstance <T>, failureStatus, tags, cacheExpirationMs));
        }