Пример #1
0
        /// <summary>Update the cache and return the current cached record</summary>
        /// <param name="mr">the update record</param>
        /// <param name="includingTags">cache tag values (for later lookup by name) if true</param>
        /// <returns>the updated cache record</returns>
        public virtual MetricsCache.Record Update(MetricsRecord mr, bool includingTags)
        {
            string name = mr.Name();

            MetricsCache.RecordCache recordCache = map[name];
            if (recordCache == null)
            {
                recordCache = new MetricsCache.RecordCache(this);
                map[name]   = recordCache;
            }
            ICollection <MetricsTag> tags = mr.Tags();

            MetricsCache.Record record = recordCache[tags];
            if (record == null)
            {
                record            = new MetricsCache.Record();
                recordCache[tags] = record;
            }
            foreach (AbstractMetric m in mr.Metrics())
            {
                record.metrics[m.Name()] = m;
            }
            if (includingTags)
            {
                // mostly for some sinks that include tags as part of a dense schema
                foreach (MetricsTag t in mr.Tags())
                {
                    record.tags[t.Name()] = t.Value();
                }
            }
            return(record);
        }
Пример #2
0
 private void CheckMetricValue(string description, MetricsCache.Record cr, string
                               key, Number val)
 {
     Assert.Equal(description, val, cr.GetMetric(key));
     NUnit.Framework.Assert.IsNotNull("metric not null", cr.GetMetricInstance(key));
     Assert.Equal(description, val, cr.GetMetricInstance(key).Value
                      ());
 }
Пример #3
0
        public virtual void TestNullTag()
        {
            MetricsCache  cache = new MetricsCache();
            MetricsRecord mr    = MakeRecord("r", Arrays.AsList(MakeTag("t", null)), Arrays.AsList
                                                 (MakeMetric("m", 0), MakeMetric("m1", 1)));

            MetricsCache.Record cr = cache.Update(mr);
            Assert.True("t value should be null", null == cr.GetTag("t"));
        }
Пример #4
0
        public virtual void TestGet()
        {
            MetricsCache cache = new MetricsCache();

            NUnit.Framework.Assert.IsNull("empty", cache.Get("r", Arrays.AsList(MakeTag("t",
                                                                                        "t"))));
            MetricsRecord mr = MakeRecord("r", Arrays.AsList(MakeTag("t", "t")), Arrays.AsList
                                              (MakeMetric("m", 1)));

            cache.Update(mr);
            MetricsCache.Record cr = cache.Get("r", mr.Tags());
            Log.Debug("tags=" + mr.Tags() + " cr=" + cr);
            NUnit.Framework.Assert.IsNotNull("Got record", cr);
            Assert.Equal("contains 1 metric", 1, cr.Metrics().Count);
            CheckMetricValue("new metric value", cr, "m", 1);
        }
Пример #5
0
        public virtual void TestUpdate()
        {
            MetricsCache  cache = new MetricsCache();
            MetricsRecord mr    = MakeRecord("r", Arrays.AsList(MakeTag("t", "tv")), Arrays.AsList
                                                 (MakeMetric("m", 0), MakeMetric("m1", 1)));

            MetricsCache.Record cr = cache.Update(mr);
            Org.Mockito.Mockito.Verify(mr).Name();
            Org.Mockito.Mockito.Verify(mr).Tags();
            Org.Mockito.Mockito.Verify(mr).Metrics();
            Assert.Equal("same record size", cr.Metrics().Count, ((ICollection
                                                                   <AbstractMetric>)mr.Metrics()).Count);
            Assert.Equal("same metric value", 0, cr.GetMetric("m"));
            MetricsRecord mr2 = MakeRecord("r", Arrays.AsList(MakeTag("t", "tv")), Arrays.AsList
                                               (MakeMetric("m", 2), MakeMetric("m2", 42)));

            cr = cache.Update(mr2);
            Assert.Equal("contains 3 metric", 3, cr.Metrics().Count);
            CheckMetricValue("updated metric value", cr, "m", 2);
            CheckMetricValue("old metric value", cr, "m1", 1);
            CheckMetricValue("new metric value", cr, "m2", 42);
            MetricsRecord mr3 = MakeRecord("r", Arrays.AsList(MakeTag("t", "tv3")), Arrays.AsList
                                               (MakeMetric("m3", 3)));

            // different tag value
            cr = cache.Update(mr3);
            // should get a new record
            Assert.Equal("contains 1 metric", 1, cr.Metrics().Count);
            CheckMetricValue("updated metric value", cr, "m3", 3);
            // tags cache should be empty so far
            Assert.Equal("no tags", 0, cr.Tags().Count);
            // until now
            cr = cache.Update(mr3, true);
            Assert.Equal("Got 1 tag", 1, cr.Tags().Count);
            Assert.Equal("Tag value", "tv3", cr.GetTag("t"));
            CheckMetricValue("Metric value", cr, "m3", 3);
        }