public static IMetricContext Get([NotNull] HerculesSinkSettings settings, [CanBeNull] ILog log)
        {
            if (defaultMetricContext != null)
            {
                return(defaultMetricContext);
            }

            lock (Sync)
            {
                if (defaultMetricContext != null)
                {
                    return(defaultMetricContext);
                }

                var memoryLimit  = 8 * 1024 * 1024;
                var sinkSettings = new HerculesSinkSettings(settings.Cluster, settings.ApiKeyProvider)
                {
                    AdditionalSetup                   = settings.AdditionalSetup,
                    MaximumMemoryConsumption          = memoryLimit,
                    MaximumPerStreamMemoryConsumption = memoryLimit
                };

                log = (log ?? LogProvider.Get()).WithMinimumLevel(LogLevel.Warn);
                var sink          = new HerculesSink(sinkSettings, log);
                var metricsSender = new HerculesMetricSender(new HerculesMetricSenderSettings(sink));
                return(defaultMetricContext = new MetricContext(new MetricContextConfig(metricsSender)));
            }
        }
Beispiel #2
0
        public void SetUp()
        {
            cancellationTokenSource = new CancellationTokenSource();

            leftCoordinatesStorage  = new InMemoryCoordinatesStorage();
            rightCoordinatesStorage = new InMemoryCoordinatesStorage();

            senderSettings = new HerculesMetricSenderSettings(Hercules.Instance.Sink);

            var management = Hercules.Instance.Management;

            var streamNames = new[] { senderSettings.FinalStream, senderSettings.TimersStream, senderSettings.CountersStream, senderSettings.HistogramsStream };

            var streamCreateTasks = streamNames.Select(
                name => Task.Run(
                    async() =>
            {
                var createResult = await management.CreateStreamAsync(
                    new CreateStreamQuery(name)
                {
                    Partitions  = streamPartitions,
                    ShardingKey = new[] { "tagsHash" }
                },
                    20.Seconds());
                createResult.EnsureSuccess();
            }))
                                    .ToArray();

            Task.WaitAll(streamCreateTasks);

            var herculesSender = new HerculesMetricSender(new HerculesMetricSenderSettings(Hercules.Instance.Sink));

            testMetricSender = new TestsHelpers.TestMetricSender();

            metricContext = new MetricContext(
                new MetricContextConfig(
                    new CompositeMetricEventSender(
                        new IMetricEventSender[]
            {
                herculesSender,
                testMetricSender
            }))
            {
                ErrorCallback = error => log.Error(error)
            });

            aggregators = new List <AggregatorApplication>();
        }