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();
        }
Пример #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();
            }
        public SummaryConfiguration(
            string name,
            string help,
            string[] labelNames,
            bool includeTimestamp,
            IReadOnlyList <QuantileEpsilonPair> objectives = null,
            TimeSpan?maxAge = null,
            int?ageBuckets  = null,
            int?bufCap      = null)
            : base(name, help, labelNames, includeTimestamp)
        {
            Objectives = objectives;
            if (Objectives == null || Objectives.Count == 0)
            {
                Objectives       = DefaultObjectives;
                SortedObjectives = DefaultSortedObjectives;
            }
            else
            {
                var sorted = new double[Objectives.Count];
                for (int i = 0; i < Objectives.Count; i++)
                {
                    sorted[i] = Objectives[i].Quantile;
                }

                Array.Sort(sorted);
                SortedObjectives = sorted;
            }

            _formattedObjectives = new Lazy <string[]>(() => GetFormattedObjectives(SortedObjectives));

            MaxAge = maxAge ?? _defaultMaxAge;
            if (MaxAge < TimeSpan.Zero)
            {
                throw new ArgumentException($"Illegal max age {MaxAge}");
            }

            AgeBuckets = ageBuckets ?? _defaultAgeBuckets;
            if (AgeBuckets == 0)
            {
                AgeBuckets = _defaultAgeBuckets;
            }

            BufCap = bufCap ?? _defaultBufCap;
            if (BufCap == 0)
            {
                BufCap = _defaultBufCap;
            }

            if (LabelNames.Any(_ => _ == _quantileLabel))
            {
                throw new ArgumentException($"{_quantileLabel} is a reserved label name");
            }
        }
Пример #4
0
            public SummaryConfiguration(
                string name,
                string help,
                bool includeTimestamp,
                bool suppressEmptySamples,
                IReadOnlyList <string> labelNames,
                IReadOnlyList <QuantileEpsilonPair> objectives = null,
                TimeSpan?maxAge = null,
                int?ageBuckets  = null,
                int?bufCap      = null)
                : base(name, help, includeTimestamp, suppressEmptySamples, labelNames)
            {
                Objectives = objectives;
                if (Objectives == null || Objectives.Count == 0)
                {
                    Objectives = DefaultObjectives;
                }

                var sorted = new double[Objectives.Count];

                for (int i = 0; i < Objectives.Count; i++)
                {
                    sorted[i] = Objectives[i].Quantile;
                }

                Array.Sort(sorted);
                SortedObjectives    = sorted;
                FormattedObjectives = SortedObjectives
                                      .Select(o => o.ToString(CultureInfo.InvariantCulture))
                                      .ToArray();

                MaxAge = maxAge ?? _defaultMaxAge;
                if (MaxAge < TimeSpan.Zero)
                {
                    throw new ArgumentException($"Illegal max age {MaxAge}");
                }

                AgeBuckets = ageBuckets ?? _defaultAgeBuckets;
                if (AgeBuckets == 0)
                {
                    AgeBuckets = _defaultAgeBuckets;
                }

                BufCap = bufCap ?? _defaultBufCap;
                if (BufCap == 0)
                {
                    BufCap = _defaultBufCap;
                }

                if (LabelNames.Any(_ => _ == _quantileLabel))
                {
                    throw new ArgumentException($"{_quantileLabel} is a reserved label name");
                }
            }
Пример #5
0
        private void EnsureUnlabelledMetricCreatedIfNoLabels()
        {
            // We want metrics to exist even with 0 values if they are supposed to be used without labels.
            // Labelled metrics are created when label values are assigned. However, as unlabelled metrics are lazy-created
            // (they might are optional if labels are used) we might lose them for cases where they really are desired.

            // If there are no label names then clearly this metric is supposed to be used unlabelled, so create it.
            // Otherwise, we allow unlabelled metrics to be used if the user explicitly does it but omit them by default.
            if (!_unlabelledLazy.IsValueCreated && !LabelNames.Any())
            {
                GetOrAddLabelled(LabelValues.Empty);
            }
        }
Пример #6
0
        public ListingLabelsSteps(IStage stage, LabelNames labelNames, LabelInfo labelInfo)
        {
            if (labelInfo == null)
            {
                throw new ArgumentNullException(nameof(labelInfo));
            }
            if (labelNames == null)
            {
                throw new ArgumentNullException(nameof(labelNames));
            }
            if (stage == null)
            {
                throw new ArgumentNullException(nameof(stage));
            }

            this.labelInfo  = labelInfo;
            this.labelNames = labelNames;
            this.stage      = stage;
        }
Пример #7
0
            public SummaryConfiguration(
                string name,
                string help,
                bool includeTimestamp,
                string[] labelNames,
                IReadOnlyList <QuantileEpsilonPair> objectives = null,
                TimeSpan?maxAge = null,
                int?ageBuckets  = null,
                int?bufCap      = null)
                : base(name, help, includeTimestamp, labelNames)
            {
                Objectives = objectives;
                if (Objectives == null || Objectives.Count == 0)
                {
                    Objectives = DefaultObjectives;
                }

                MaxAge = maxAge ?? _defaultMaxAge;
                if (MaxAge < TimeSpan.Zero)
                {
                    throw new ArgumentException($"Illegal max age {MaxAge}");
                }

                AgeBuckets = ageBuckets ?? _defaultAgeBuckets;
                if (AgeBuckets == 0)
                {
                    AgeBuckets = _defaultAgeBuckets;
                }

                BufCap = bufCap ?? _defaultBufCap;
                if (BufCap == 0)
                {
                    BufCap = _defaultBufCap;
                }

                if (LabelNames.Any(_ => _ == _quantileLabel))
                {
                    throw new ArgumentException($"{_quantileLabel} is a reserved label name");
                }
            }
Пример #8
0
        public HistogramConfiguration(string name, string help, string[] labels, double[] buckets, bool includeTimestamp)
            : base(name, help, labels, includeTimestamp)
        {
            if (LabelNames.Any(l => l == "le"))
            {
                throw new ArgumentException("'le' is a reserved label name");
            }

            if (buckets == null)
            {
                Buckets           = _defaultBuckets;
                _formattedBuckets = new Lazy <string[]>(() => _defaultFormattedBuckets);
            }
            else
            {
                Buckets = buckets;

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

                var lastVal = double.MinValue;
                foreach (var val in buckets)
                {
                    if (lastVal >= val)
                    {
                        throw new ArgumentException("Bucket values must be increasing");
                    }

                    lastVal = val;
                }

                _formattedBuckets = new Lazy <string[]>(() => GetFormattedBuckets(Buckets));
            }
        }
        public async Task <IResponse <List <ViewModels.LabelNames> > > GetLabelsUI(ViewModels.PageLabelReq view)
        {
            var PageLabelRes   = new List <LabelNames>();
            var PageLabelModel = new List <Languages_Label>();

            if (view.page_name == "ALL")
            {
                var EnData = (from file in _appContext.Languages_Label
                              where file.Is_Active == 1 & file.Language_Code == "En"
                              orderby file.Pagename ascending, file.Labelname descending, file.Language_Code descending
                              select new
                {
                    Page_Name = file.Pagename,
                    Page_Display_Name = file.Page_Displayname,
                    Label_Name = file.Labelname,
                    Value = file.Value,
                    LanguageCode = file.Language_Code
                });
                var ArData = (from file in _appContext.Languages_Label
                              where file.Is_Active == 1 & file.Language_Code == "Ar"
                              orderby file.Pagename ascending, file.Labelname descending, file.Language_Code descending
                              select new
                {
                    Page_Name = file.Pagename,
                    Page_Display_Name = file.Page_Displayname,
                    Label_Name = file.Labelname,
                    Value = file.Value,
                    LanguageCode = file.Language_Code
                });
                var FinalData = from item in EnData
                                join item1 in ArData
                                on new { item.Page_Name, item.Label_Name } equals new { item1.Page_Name, item1.Label_Name }
                select new
                {
                    PageName        = item.Page_Name,
                    PageDisplayName = item.Page_Display_Name,
                    LabelName       = item.Label_Name,
                    English         = item.Value,
                    Arabic          = item1.Value
                };
                foreach (var item in FinalData)
                {
                    LabelNames ll = new LabelNames();
                    ll.PageName        = item.PageName;
                    ll.PageDisplayName = item.PageDisplayName;
                    ll.LabelName       = item.LabelName;
                    ll.English         = item.English.ToString().Trim();
                    ll.Arabic          = item.Arabic.ToString().Trim();

                    PageLabelRes.Add(ll);
                }
            }
            else
            {
                var EnData = from file in _appContext.Languages_Label
                             where file.Is_Active == 1 & file.Language_Code == "En" & file.Pagename == view.page_name || file.Pagename == "Common"
                             orderby file.Pagename ascending, file.Labelname descending, file.Language_Code descending
                    select new
                {
                    Page_Name         = file.Pagename,
                    Page_Display_Name = file.Page_Displayname,
                    Label_Name        = file.Labelname,
                    Value             = file.Value,
                    LanguageCode      = file.Language_Code
                };
                var ArData = from file in _appContext.Languages_Label
                             where file.Is_Active == 1 & file.Language_Code == "Ar" & file.Pagename == view.page_name || file.Pagename == "Common"
                             orderby file.Pagename ascending, file.Labelname descending, file.Language_Code descending
                    select new
                {
                    Page_Name         = file.Pagename,
                    Page_Display_Name = file.Page_Displayname,
                    Label_Name        = file.Labelname,
                    Value             = file.Value,
                    LanguageCode      = file.Language_Code
                };
                var FinalData = from item in EnData
                                join item1 in ArData
                                on new { item.Label_Name } equals new { item1.Label_Name }
                select new
                {
                    PageName        = item.Page_Name,
                    PageDisplayName = item.Page_Display_Name,
                    LabelName       = item.Label_Name,
                    English         = item.Value,
                    Arabic          = item1.Value
                };
                foreach (var item in FinalData)
                {
                    LabelNames ll = new LabelNames();
                    ll.PageName        = item.PageName;
                    ll.PageDisplayName = item.PageDisplayName;
                    ll.LabelName       = item.LabelName;
                    ll.English         = item.English.ToString().Trim();
                    ll.Arabic          = item.Arabic.ToString().Trim();

                    PageLabelRes.Add(ll);
                }
            }

            return(new LangResponseUI(PageLabelRes));
        }