Esempio n. 1
0
        public void ShouldParseAndPrioritizeTimePeriodGivenTimeSpanAndStartAndEndTimes()
        {
            var timePeriod = TimePeriodUtils.Parse(10000, 20000, "5m");

            timePeriod.Should().NotBeNull();
            (timePeriod.EndTimestamp - timePeriod.StartTimestamp).Should().Be(300);
        }
Esempio n. 2
0
        public void ShouldParseTimePeriodGivenTimeSpan()
        {
            var timePeriod = TimePeriodUtils.Parse(null, null, "5m");

            timePeriod.Should().NotBeNull();
            (timePeriod.EndTimestamp - timePeriod.StartTimestamp).Should().Be(300);
        }
Esempio n. 3
0
        public void ShouldParseTimePeriodGivenStartAndEndTime()
        {
            var timePeriod = TimePeriodUtils.Parse(10000, 20000, null);

            timePeriod.Should().NotBeNull();
            timePeriod.StartTimestamp.Should().Be(10000);
            timePeriod.EndTimestamp.Should().Be(20000);
        }
Esempio n. 4
0
        public async Task <MetricsTimeSeriesResultDto> Handle(GetMetricTimeSeriesQuery request, CancellationToken cancellationToken)
        {
            var dbMetrics = await ValidateMetrics(request);

            if (dbMetrics.Count == 0)
            {
                return(new MetricsTimeSeriesResultDto());
            }

            var timePeriod = TimePeriodUtils.Parse(request.StartTimestamp, request.EndTimestamp, request.LiveSpan);

            MetricsTimeSeriesResultDto result = new MetricsTimeSeriesResultDto();

            for (int i = 0; i < request.Metrics.Count; i++)
            {
                var requestMetric = request.Metrics[i];
                var dbMetric      = dbMetrics.FirstOrDefault(x => x.Name.Equals(requestMetric.MetricName) && x.Namespace.Equals(requestMetric.Namespace));

                if (dbMetric == null)
                {
                    continue;
                }

                // Retrieve the metrics
                var metricValues = await metricsRetriever.QueryAsync(dbMetric, timePeriod);

                // Down sample the metrics
                var samplingResult = metricDownSampler.DownSample(metricValues, request.SamplingTime, timePeriod.StartTimestamp, timePeriod.EndTimestamp);

                var metricValue = GetMetricTimeSeriesValueForSamplingType(requestMetric, samplingResult);

                result.Values.Add(metricValue);

                if (i == 0)
                {
                    result.Timestamps    = samplingResult.MetricValues.Select(x => x.TimeStamp).ToList();
                    result.Count         = samplingResult.MetricValues.Count;
                    result.SamplingValue = samplingResult.DownsamplingValue;
                }
            }

            return(result);
        }
        public async Task <List <MetricAggregatedValueDto> > Handle(GetMetricsAggregatedValueQuery request, CancellationToken cancellationToken)
        {
            var dbMetrics = await ValidateMetrics(request);

            if (dbMetrics.Count == 0)
            {
                return(new List <MetricAggregatedValueDto>());
            }

            var timePeriod = TimePeriodUtils.Parse(request.StartTimestamp, request.EndTimestamp, request.LiveSpan);

            var result = new List <MetricAggregatedValueDto>();

            for (int i = 0; i < request.Metrics.Count; i++)
            {
                var requestMetric = request.Metrics[i];
                var dbMetric      = dbMetrics.FirstOrDefault(x => x.Name.Equals(requestMetric.MetricName) && x.Namespace.Equals(requestMetric.Namespace));

                if (dbMetric == null)
                {
                    continue;
                }

                // Retrieve the metrics
                var metricValues = await metricsRetriever.QueryAsync(dbMetric, new TimePeriod()
                {
                    StartTimestamp = timePeriod.StartTimestamp, EndTimestamp = timePeriod.EndTimestamp
                });

                var metricValue = GetMetricTimeSeriesValue(requestMetric, metricValues);

                result.Add(metricValue);
            }

            return(result);
        }
Esempio n. 6
0
 public void ShouldThrowExceptionIfNoStartTimeOrLiveSpanProvided()
 {
     Assert.Throws <Exception>(() => TimePeriodUtils.Parse(null, 20000, null));
 }