public void SummaryEventIsSerialized() { var summary = new EventSummary(); summary.NoteTimestamp(UnixMillisecondTime.OfMillis(1001)); summary.IncrementCounter("first", 1, 11, LdValue.Of("value1a"), LdValue.Of("default1")); summary.IncrementCounter("second", 1, 21, LdValue.Of("value2a"), LdValue.Of("default2")); summary.IncrementCounter("first", 1, 11, LdValue.Of("value1a"), LdValue.Of("default1")); summary.IncrementCounter("first", 1, 12, LdValue.Of("value1a"), LdValue.Of("default1")); summary.IncrementCounter("second", 2, 21, LdValue.Of("value2b"), LdValue.Of("default2")); summary.IncrementCounter("second", null, 21, LdValue.Of("default2"), LdValue.Of("default2")); // flag exists (has version), but eval failed (no variation) summary.IncrementCounter("third", null, null, LdValue.Of("default3"), LdValue.Of("default3")); // flag doesn't exist (no version) summary.NoteTimestamp(UnixMillisecondTime.OfMillis(1000)); summary.NoteTimestamp(UnixMillisecondTime.OfMillis(1002)); var f = new EventOutputFormatter(new EventsConfiguration()); var outputEvent = LdValue.Parse(f.SerializeOutputEvents(new object[0], summary, out var count)).Get(0); Assert.Equal(1, count); Assert.Equal("summary", outputEvent.Get("kind").AsString); Assert.Equal(1000, outputEvent.Get("startDate").AsInt); Assert.Equal(1002, outputEvent.Get("endDate").AsInt); var featuresJson = outputEvent.Get("features"); Assert.Equal(3, featuresJson.Count); var firstJson = featuresJson.Get("first"); Assert.Equal("default1", firstJson.Get("default").AsString); TestUtil.AssertContainsInAnyOrder(firstJson.Get("counters").AsList(LdValue.Convert.Json), LdValue.Parse(@"{""value"":""value1a"",""variation"":1,""version"":11,""count"":2}"), LdValue.Parse(@"{""value"":""value1a"",""variation"":1,""version"":12,""count"":1}")); var secondJson = featuresJson.Get("second"); Assert.Equal("default2", secondJson.Get("default").AsString); TestUtil.AssertContainsInAnyOrder(secondJson.Get("counters").AsList(LdValue.Convert.Json), LdValue.Parse(@"{""value"":""value2a"",""variation"":1,""version"":21,""count"":1}"), LdValue.Parse(@"{""value"":""value2b"",""variation"":2,""version"":21,""count"":1}"), LdValue.Parse(@"{""value"":""default2"",""version"":21,""count"":1}")); var thirdJson = featuresJson.Get("third"); Assert.Equal("default3", thirdJson.Get("default").AsString); TestUtil.AssertContainsInAnyOrder(thirdJson.Get("counters").AsList(LdValue.Convert.Json), LdValue.Parse(@"{""unknown"":true,""value"":""default3"",""count"":1}")); }
// Adds this event to our counters, if it is a type of event we need to count. public void SummarizeEvent( UnixMillisecondTime timestamp, string flagKey, int?flagVersion, int?variation, LdValue value, LdValue defaultValue ) { _eventsState.IncrementCounter(flagKey, variation, flagVersion, value, defaultValue); _eventsState.NoteTimestamp(timestamp); }