예제 #1
0
        private static CounterInfo BuildCounterInfo(Counter counter, DimensionSpecification queryParameters)
        {
            var counterInfo = new CounterInfo
            {
                Name            = counter.Name,
                Type            = counter.Type,
                StartTime       = counter.StartTime.ToMillisecondTimestamp(),
                EndTime         = counter.EndTime.ToMillisecondTimestamp(),
                Dimensions      = counter.Dimensions.ToList(),
                DimensionValues = null,                   // null this out by default to avoid response bloat.
            };

            // Queries for dimension values will come with a 'dimension=pattern' query parameter.
            // Dimension values can be further filtered with '<dimensionName>=pattern'
            string dimensionPattern;

            if (queryParameters.TryGetValue(ReservedDimensions.DimensionDimension, out dimensionPattern))
            {
                counterInfo.DimensionValues = new Dictionary <string, ISet <string> >();

                // We want to be able to filter dimension values by time (and only time)
                var    dimensionQuery = new DimensionSpecification();
                string timeValue;
                if (!queryParameters.TryGetValue(ReservedDimensions.StartTimeDimension, out timeValue))
                {
                    timeValue = MinimumStartTime;
                }
                dimensionQuery[ReservedDimensions.StartTimeDimension] = timeValue;
                if (!queryParameters.TryGetValue(ReservedDimensions.EndTimeDimension, out timeValue))
                {
                    timeValue = MaximumEndTime;
                }
                dimensionQuery[ReservedDimensions.EndTimeDimension] = timeValue;

                foreach (var dim in counter.Dimensions.Where(d => d.MatchGlob(dimensionPattern)))
                {
                    string filterPattern;
                    if (queryParameters.TryGetValue(dimensionPattern, out filterPattern))
                    {
                        counterInfo.AddDimensionValues(dim,
                                                       counter.GetDimensionValues(dim, dimensionQuery)
                                                       .Where(dimensionValue =>
                                                              dimensionValue.MatchGlob(filterPattern)));
                    }
                    else
                    {
                        counterInfo.AddDimensionValues(dim, counter.GetDimensionValues(dim, dimensionQuery));
                    }
                }
            }

            return(counterInfo);
        }
예제 #2
0
        private static void MergeSampleData(CounterInfo original, CounterInfo newSample)
        {
            foreach (var dim in newSample.Dimensions)
            {
                if (!original.Dimensions.Any(d => d.Equals(dim, StringComparison.OrdinalIgnoreCase)))
                {
                    original.Dimensions.Add(dim);
                }

                if (original.StartTime > newSample.StartTime)
                {
                    original.StartTime = newSample.StartTime;
                }
                if (original.EndTime < newSample.EndTime)
                {
                    original.EndTime = newSample.EndTime;
                }
            }

            if (newSample.DimensionValues != null)
            {
                // Necessary because of some fun quackery in Bond.
                original.FixDimensionValuesCaseSensitivity();
                foreach (var kvp in newSample.DimensionValues)
                {
                    var dim       = kvp.Key;
                    var newValues = kvp.Value;
                    original.AddDimensionValues(dim, newValues);
                }
            }
        }
예제 #3
0
        private static CounterInfo BuildCounterInfo(Counter counter, DimensionSpecification queryParameters)
        {
            var counterInfo = new CounterInfo
                              {
                                  Name = counter.Name,
                                  Type = counter.Type,
                                  StartTime = counter.StartTime.ToMillisecondTimestamp(),
                                  EndTime = counter.EndTime.ToMillisecondTimestamp(),
                                  Dimensions = counter.Dimensions.ToList(),
                                  DimensionValues = null, // null this out by default to avoid response bloat.
                              };

            // Queries for dimension values will come with a 'dimension=pattern' query parameter.
            // Dimension values can be further filtered with '<dimensionName>=pattern'
            string dimensionPattern;
            if (queryParameters.TryGetValue(ReservedDimensions.DimensionDimension, out dimensionPattern))
            {
                counterInfo.DimensionValues = new Dictionary<string, ISet<string>>();

                // We want to be able to filter dimension values by time (and only time)
                var dimensionQuery = new DimensionSpecification();
                string timeValue;
                if (!queryParameters.TryGetValue(ReservedDimensions.StartTimeDimension, out timeValue))
                {
                    timeValue = MinimumStartTime;
                }
                dimensionQuery[ReservedDimensions.StartTimeDimension] = timeValue;
                if (!queryParameters.TryGetValue(ReservedDimensions.EndTimeDimension, out timeValue))
                {
                    timeValue = MaximumEndTime;
                }
                dimensionQuery[ReservedDimensions.EndTimeDimension] = timeValue;

                foreach (var dim in counter.Dimensions.Where(d => d.MatchGlob(dimensionPattern)))
                {
                    string filterPattern;
                    if (queryParameters.TryGetValue(dimensionPattern, out filterPattern))
                    {
                        
                        counterInfo.AddDimensionValues(dim,
                                                       counter.GetDimensionValues(dim, dimensionQuery)
                                                              .Where(dimensionValue =>
                                                                     dimensionValue.MatchGlob(filterPattern)));
                    }
                    else
                    {
                        counterInfo.AddDimensionValues(dim, counter.GetDimensionValues(dim, dimensionQuery));
                    }
                }
            }

            return counterInfo;
        }
        private static void MergeSampleData(CounterInfo original, CounterInfo newSample)
        {
            foreach (var dim in newSample.Dimensions)
            {
                if (!original.Dimensions.Any(d => d.Equals(dim, StringComparison.OrdinalIgnoreCase)))
                {
                    original.Dimensions.Add(dim);
                }

                if (original.StartTime > newSample.StartTime)
                {
                    original.StartTime = newSample.StartTime;
                }
                if (original.EndTime < newSample.EndTime)
                {
                    original.EndTime = newSample.EndTime;
                }
            }

            if (newSample.DimensionValues != null)
            {
                // Necessary because of some fun quackery in Bond.
                original.FixDimensionValuesCaseSensitivity();
                foreach (var kvp in newSample.DimensionValues)
                {
                    var dim = kvp.Key;
                    var newValues = kvp.Value;
                    original.AddDimensionValues(dim, newValues);
                }
            }
        }