public HistogramConfiguration(string name, string help, IReadOnlyList <string> labels, IReadOnlyList <double> buckets, MetricFlags options)
            : base(name, help, labels, options)
        {
            Buckets = buckets ?? _defaultBuckets;

            if (LabelNames.Any(l => l == "le"))
            {
                throw new ArgumentException("'le' is a reserved label name");
            }

            if (Buckets.Count == 0)
            {
                throw new ArgumentException("Histogram must have at least one bucket");
            }

            if (!double.IsPositiveInfinity(Buckets[Buckets.Count - 1]))
            {
                Buckets = Buckets.Concat(_positiveInf).ToArray();
            }

            for (int i = 1; i < Buckets.Count; i++)
            {
                if (Buckets[i] <= Buckets[i - 1])
                {
                    throw new ArgumentException("Bucket values must be increasing");
                }
            }

            FormattedBuckets = Buckets
                               .Select(b => b.ToString(CultureInfo.InvariantCulture))
                               .ToArray();
        }
Esempio n. 2
0
            public HistogramConfiguration(string name, string help, bool includeTimestamp, string[] labels, double[] buckets)
                : base(name, help, includeTimestamp, labels)
            {
                Buckets = buckets ?? _defaultBuckets;

                if (LabelNames.Any(l => l == "le"))
                {
                    throw new ArgumentException("'le' is a reserved label name");
                }

                if (Buckets.Count == 0)
                {
                    throw new ArgumentException("Histogram must have at least one bucket");
                }

                if (!double.IsPositiveInfinity(Buckets[Buckets.Count - 1]))
                {
                    Buckets = Buckets.Concat(new[] { double.PositiveInfinity }).ToArray();
                }

                for (int i = 1; i < Buckets.Count; i++)
                {
                    if (Buckets[i] <= Buckets[i - 1])
                    {
                        throw new ArgumentException("Bucket values must be increasing");
                    }
                }

                FormattedBuckets = Buckets
                                   .Select(b => b.ToString(CultureInfo.InvariantCulture))
                                   .ToArray();
            }