Beispiel #1
0
        public void Clean_WithAllReportsFilteringOutEvents_RemovesAllEvents()
        {
            ResetCleaner();

            const string context  = "";
            var          registry = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(context, registry);
            var timer = new MockTimer();

            EventMetricsCleaner.EnableTestTimer(timer);

            var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var metric       = new EventMetric();

            registry.Event(MetricName, () => { return(metric); }, MetricTags.None);
            metric.Record();
            metric.Record();
            metric.Record();
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, new List <EventValueSource>());
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex2, new List <EventValueSource>());

            GetReportsReportedEventDetailCount(reportIndex1, MetricNameType).Should().Be(0);
            GetReportsReportedEventDetailCount(reportIndex2, MetricNameType).Should().Be(0);
            var registryCounts = GetRegistryEventDetailCounts(MetricNameType);

            registryCounts[context].Should().Be(3);

            timer.OnTimerCallback();

            registryCounts = GetRegistryEventDetailCounts(MetricNameType);
            registryCounts[context].Should().Be(0);
        }
Beispiel #2
0
        public void Clean_WithNoReportsRegistered_RemovesAllEvents()
        {
            ResetCleaner();

            const string context  = "";
            var          registry = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(context, registry);
            var timer = new MockTimer();

            EventMetricsCleaner.EnableTestTimer(timer);

            var metric = new EventMetric();

            registry.Event(MetricName, () => { return(metric); }, MetricTags.None);

            metric.Record();
            metric.Record();
            metric.Record();
            var registryCounts = GetRegistryEventDetailCounts(MetricNameType);

            registryCounts[context].Should().Be(3);

            timer.OnTimerCallback();

            registryCounts = GetRegistryEventDetailCounts(MetricNameType);
            registryCounts[context].Should().Be(0);
        }
Beispiel #3
0
        public void Clean_IgnoresReportsThatHaveNotReportedAnyEvents()
        {
            ResetCleaner();

            const string context  = "";
            var          registry = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(context, registry);
            var timer = new MockTimer();

            EventMetricsCleaner.EnableTestTimer(timer);

            var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var metric       = new EventMetric();

            registry.Event(MetricName, () => { return(metric); }, MetricTags.None);

            metric.Record();
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, registry.DataProvider.Events);

            GetReportsReportedEventDetailCount(reportIndex1, metricNameTypeTags).Should().Be(1);
            GetReportsReportedEventDetailCount(reportIndex2, metricNameTypeTags).Should().Be(0);

            timer.OnTimerCallback();

            var registryCounts = GetRegistryEventDetailCounts(MetricNameType);

            registryCounts[context].Should().Be(0);
        }
Beispiel #4
0
        private void RunReport(CancellationToken token)
        {
            var data = this.metricsDataProvider.CurrentMetricsData;

            this.report.RunReport(data, this.healthStatus, token);
            EventMetricsCleaner.UpdateTotalReportedEvents(this.reportIdentifier, data.Events);
        }
            public void Remove(string name, MetricTags tags)
            {
                var        key = MetricIdentifier.Calculate(name, tags.Tags);
                MetricMeta m;

                this.metrics.TryRemove(key, out m);
                EventMetricsCleaner.RemoveEvent(key);
            }
Beispiel #6
0
        public void RegisterReport_IncrementsReportCount()
        {
            ResetCleaner();

            EventMetricsCleaner.RegisterReport(new TimeSpan(0));

            EventMetricsCleaner.TotalReports.Should().Be(1);
        }
Beispiel #7
0
 public ScheduledReporter(MetricsReport report, MetricsDataProvider metricsDataProvider, Func <HealthStatus> healthStatus, TimeSpan interval, Scheduler scheduler)
 {
     this.report = report;
     this.metricsDataProvider = metricsDataProvider;
     this.healthStatus        = healthStatus;
     this.scheduler           = scheduler;
     this.scheduler.Start(interval, t => RunReport(t));
     this.reportIdentifier = EventMetricsCleaner.RegisterReport(interval);
 }
Beispiel #8
0
        public void RegisterReport_UpdatesCleanerInterval()
        {
            ResetCleaner();

            EventMetricsCleaner.CurrentIntervalSeconds.Should().Be(5);

            EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 60));

            EventMetricsCleaner.CurrentIntervalSeconds.Should().Be(65);
        }
Beispiel #9
0
        public void RegisterMultipleReports_UpdatesCleanerInterval_UsingLargestReportInverval()
        {
            ResetCleaner();

            EventMetricsCleaner.CurrentIntervalSeconds.Should().Be(5);

            EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 3));
            EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 8));
            EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 2));

            EventMetricsCleaner.CurrentIntervalSeconds.Should().Be(13);
        }
Beispiel #10
0
        public void Clean_WithMultipleRegistriesInSeparateContexts_RemovesEvents()
        {
            ResetCleaner();

            const string ctx1      = "ctx1";
            var          registry1 = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(ctx1, registry1);

            const string ctx2      = "ctx2";
            var          registry2 = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(ctx2, registry2);

            var timer = new MockTimer();

            EventMetricsCleaner.EnableTestTimer(timer);

            var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var metric1      = new EventMetric();

            registry1.Event("test1", () => { return(metric1); }, MetricTags.None);
            metric1.Record();
            metric1.Record();
            metric1.Record();
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, registry1.DataProvider.Events);

            var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var metric2      = new EventMetric();

            registry2.Event("test2", () => { return(metric2); }, MetricTags.None);
            metric2.Record();
            metric2.Record();
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex2, registry2.DataProvider.Events);

            var registryCounts = GetRegistryEventDetailCounts("test1.event");

            registryCounts[ctx1].Should().Be(3);
            registryCounts[ctx2].Should().Be(0);
            registryCounts = GetRegistryEventDetailCounts("test2.event");
            registryCounts[ctx1].Should().Be(0);
            registryCounts[ctx2].Should().Be(2);

            timer.OnTimerCallback();

            registryCounts = GetRegistryEventDetailCounts("test1.event");
            registryCounts[ctx1].Should().Be(0);
            registryCounts[ctx2].Should().Be(0);
            registryCounts = GetRegistryEventDetailCounts("test2.event");
            registryCounts[ctx1].Should().Be(0);
            registryCounts[ctx2].Should().Be(0);
        }
Beispiel #11
0
        public void Update_RegistersEventAssociatedWithReport()
        {
            ResetCleaner();

            var registry = new DefaultMetricsRegistry();

            registry.Event(MetricName, () => { return(new EventMetric()); }, MetricTags.None);
            var reportIndex = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));

            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex, registry.DataProvider.Events);

            GetReportsEventCount(reportIndex).Should().Be(1);
        }
Beispiel #12
0
        public void RemoveEvent_RemovesEventFromAllReports()
        {
            ResetCleaner();

            var registry = new DefaultMetricsRegistry();

            registry.Event(MetricName, () => { return(new EventMetric()); }, MetricTags.None);
            var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));

            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, registry.DataProvider.Events);
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex2, registry.DataProvider.Events);

            EventMetricsCleaner.RemoveEvent(metricNameTypeTags);

            GetReportsEventCount(reportIndex1).Should().Be(0);
            GetReportsEventCount(reportIndex2).Should().Be(0);
        }
Beispiel #13
0
 public void ResetCleaner()
 {
     EventMetricsCleaner.ContextRegistries.Clear();
     EventMetricsCleaner.ReportEventCounts.Clear();
     EventMetricsCleaner.ResetInterval();
 }