public void CanRecordEventsInBatch() { IDiagnosticStore _serverDiagnosticStore = CreateDiagnosticStore(); _serverDiagnosticStore.RecordEventsInBatch(4); DiagnosticEvent periodicEvent = _serverDiagnosticStore.CreateEventAndReset(); Assert.Equal(4, periodicEvent.JsonValue.Get("eventsInLastBatch").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); }
// Grabs a snapshot of the current internal state, and starts a new task to send it to the server. private void StartFlush(EventBuffer buffer) { if (_disabled) { return; } FlushPayload payload = buffer.GetPayload(); if (_diagnosticStore != null) { _diagnosticStore.RecordEventsInBatch(payload.Events.Length); } if (payload.Events.Length > 0 || !payload.Summary.Empty) { lock (_flushWorkersCounter) { // Note that this counter will be 1, not 0, when there are no active flush workers. // This is because a .NET CountdownEvent can't be reused without explicitly resetting // it once it has gone to zero. if (_flushWorkersCounter.CurrentCount >= MaxFlushWorkers + 1) { // We already have too many workers, so just leave the events as is return; } // We haven't hit the limit, we'll go ahead and start a flush task _flushWorkersCounter.AddCount(1); } buffer.Clear(); Task.Run(async() => { try { await FlushEventsAsync(payload); } finally { _flushWorkersCounter.Signal(); } }); } }