public void CanIncrementDeduplicateUsers()
        {
            IDiagnosticStore _serverDiagnosticStore = CreateDiagnosticStore();

            _serverDiagnosticStore.IncrementDeduplicatedUsers();
            DiagnosticEvent periodicEvent = _serverDiagnosticStore.CreateEventAndReset();

            Assert.Equal(1, periodicEvent.JsonValue.Get("deduplicatedUsers").AsInt);
        }
        public void CreatingEventResetsFields()
        {
            IDiagnosticStore _serverDiagnosticStore = CreateDiagnosticStore();

            _serverDiagnosticStore.IncrementDroppedEvents();
            _serverDiagnosticStore.IncrementDeduplicatedUsers();
            _serverDiagnosticStore.RecordEventsInBatch(10);
            _serverDiagnosticStore.AddStreamInit(DateTime.Now, TimeSpan.FromMilliseconds(200.0), true);
            LdValue firstPeriodicEvent = _serverDiagnosticStore.CreateEventAndReset().JsonValue;
            LdValue nextPeriodicEvent  = _serverDiagnosticStore.CreateEventAndReset().JsonValue;

            Assert.Equal(firstPeriodicEvent.Get("creationDate"), nextPeriodicEvent.Get("dataSinceDate"));
            Assert.Equal(0, nextPeriodicEvent.Get("eventsInLastBatch").AsInt);
            Assert.Equal(0, nextPeriodicEvent.Get("droppedEvents").AsInt);
            Assert.Equal(0, nextPeriodicEvent.Get("deduplicatedUsers").AsInt);
            Assert.Equal(0, nextPeriodicEvent.Get("eventsInLastBatch").AsInt);
            LdValue streamInits = nextPeriodicEvent.Get("streamInits");

            Assert.Equal(0, streamInits.Count);
        }
Esempio n. 3
0
        private void ProcessEvent(object e, EventBuffer buffer)
        {
            if (_disabled)
            {
                return;
            }

            // Decide whether to add the event to the payload. Feature events may be added twice, once for
            // the event (if tracked) and once for debugging.
            bool                willAddFullEvent = true;
            DebugEvent?         debugEvent       = null;
            UnixMillisecondTime timestamp;
            User                user = null;

            switch (e)
            {
            case EvaluationEvent ee:
                buffer.AddToSummary(ee);     // only evaluation events go into the summarizer
                timestamp        = ee.Timestamp;
                user             = ee.User;
                willAddFullEvent = ee.TrackEvents;
                if (ShouldDebugEvent(ee))
                {
                    debugEvent = new DebugEvent {
                        FromEvent = ee
                    };
                }
                break;

            case IdentifyEvent ie:
                timestamp = ie.Timestamp;
                user      = ie.User;
                break;

            case CustomEvent ce:
                timestamp = ce.Timestamp;
                user      = ce.User;
                break;

            default:
                timestamp = new UnixMillisecondTime();
                break;
            }

            // Tell the user deduplicator, if any, about this user; this may produce an index event.
            // We only need to do this if there is *not* already going to be a full-fidelity event
            // containing an inline user.
            if (!(willAddFullEvent && _config.InlineUsersInEvents) && user != null &&
                _userDeduplicator != null)
            {
                bool needUserEvent = _userDeduplicator.ProcessUser(user);
                if (needUserEvent && !(e is IdentifyEvent))
                {
                    IndexEvent ie = new IndexEvent {
                        Timestamp = timestamp, User = user
                    };
                    buffer.AddEvent(ie);
                }
                else if (!(e is IdentifyEvent))
                {
                    _diagnosticStore?.IncrementDeduplicatedUsers();
                }
            }

            if (willAddFullEvent)
            {
                buffer.AddEvent(e);
            }
            if (debugEvent != null)
            {
                buffer.AddEvent(debugEvent);
            }
        }