示例#1
0
 public MetricResetDaemon(
     IEventsTimestampProvider eventsTimestampProvider,
     MetricsAggregatorSettings settings,
     MetricAggregator aggregator)
 {
     this.eventsTimestampProvider = eventsTimestampProvider;
     this.settings   = settings;
     this.aggregator = aggregator;
     cts             = new CancellationTokenSource();
 }
        public DateTimeOffset?GetStartTimestampOnRebalance(string routingKey)
        {
            ValidateRoutingKey(routingKey);
            if (started)
            {
                throw new InvalidOperationException($"Unexpected {nameof(GetStartTimestampOnRebalance)} call. Possible reason: many partitions for one topic are not supported for aggregation");
            }
            started = true;
            eventsTimestampProvider = new EventsTimestampProvider(1000);
            var initialBorders = CreateBorders(DateTimeOffset.UtcNow);

            aggregator = new MetricAggregator(
                rootMetricScope,
                new BucketKeyProvider(),
                airlockClient,
                settings.MetricAggregationPastGap,
                initialBorders,
                routingKey);
            resetDaemon     = new MetricResetDaemon(eventsTimestampProvider, settings, aggregator);
            resetDaemonTask = resetDaemon.StartAsync(initialBorders);
            return(initialBorders.Past);
        }