internal EventProcessorInternal( EventsConfiguration config, BlockingCollection <IEventMessage> messageQueue, IEventSender eventSender, IUserDeduplicator userDeduplicator, IDiagnosticStore diagnosticStore, Logger logger, Action testActionOnDiagnosticSend ) { _config = config; _diagnosticStore = diagnosticStore; _userDeduplicator = userDeduplicator; _testActionOnDiagnosticSend = testActionOnDiagnosticSend; _flushWorkersCounter = new CountdownEvent(1); _eventSender = eventSender; _logger = logger; _random = new Random(); EventBuffer buffer = new EventBuffer(config.EventCapacity > 0 ? config.EventCapacity : 1, _diagnosticStore, _logger); // Here we use TaskFactory.StartNew instead of Task.Run() because that allows us to specify the // LongRunning option. This option tells the task scheduler that the task is likely to hang on // to a thread for a long time, so it should consider growing the thread pool. Task.Factory.StartNew( () => RunMainLoop(messageQueue, buffer), TaskCreationOptions.LongRunning ); }
public void WithEventProperties() { foreach (var customEventsBasUri in new bool[] { false, true }) { foreach (var allAttributesPrivate in new bool[] { false, true }) { foreach (var inlineUsersInEvents in new bool[] { false, true }) { var eventsConfig = new EventsConfiguration { AllAttributesPrivate = allAttributesPrivate, DiagnosticRecordingInterval = TimeSpan.FromMilliseconds(11111), EventCapacity = 22222, EventFlushInterval = TimeSpan.FromMilliseconds(33333), InlineUsersInEvents = inlineUsersInEvents }; string expected = LdValue.BuildObject() .Add("allAttributesPrivate", allAttributesPrivate) .Add("customEventsURI", customEventsBasUri) .Add("diagnosticRecordingIntervalMillis", 11111) .Add("eventsCapacity", 22222) .Add("eventsFlushIntervalMillis", 33333) .Add("inlineUsersInEvents", inlineUsersInEvents) .Build().ToJsonString(); string actual = LdValue.BuildObject().WithEventProperties(eventsConfig, customEventsBasUri) .Build().ToJsonString(); AssertJsonEqual(expected, actual); } } } }
public void AllAttributesPrivateMakesAttributesPrivate() { var user = User.Builder("userkey") .Anonymous(true) .Avatar("http://avatar") .Country("US") .Custom("custom1", "value1") .Custom("custom2", "value2") .Email("*****@*****.**") .FirstName("first") .IPAddress("1.2.3.4") .LastName("last") .Name("me") .Secondary("s") .Build(); var userJson = LdValue.Parse(@"{ ""key"":""userkey"", ""anonymous"":true, ""privateAttrs"":[ ""avatar"", ""country"", ""custom1"", ""custom2"", ""email"", ""firstName"", ""ip"", ""lastName"", ""name"", ""secondary"" ] }"); var config = new EventsConfiguration() { AllAttributesPrivate = true }; TestInlineUserSerialization(user, userJson, config); }
public EventUserBuilder(User user, EventsConfiguration config) { _user = user; _config = config; _result = new EventUser(); _privateAttrs = null; }
public EventProcessor( EventsConfiguration config, IEventSender eventSender, IUserDeduplicator userDeduplicator, IDiagnosticStore diagnosticStore, IDiagnosticDisabler diagnosticDisabler, Logger logger, Action testActionOnDiagnosticSend ) { _logger = logger; _stopped = new AtomicBoolean(false); _offline = new AtomicBoolean(false); _sentInitialDiagnostics = new AtomicBoolean(false); _inputCapacityExceeded = new AtomicBoolean(false); _messageQueue = new BlockingCollection <EventProcessorInternal.IEventMessage>( config.EventCapacity > 0 ? config.EventCapacity : 1); _processorInternal = new EventProcessorInternal( config, _messageQueue, eventSender, userDeduplicator, diagnosticStore, _logger, testActionOnDiagnosticSend ); if (config.EventFlushInterval > TimeSpan.Zero) { _flushTimer = new Timer(DoBackgroundFlush, null, config.EventFlushInterval, config.EventFlushInterval); } _diagnosticStore = diagnosticStore; _diagnosticRecordingInterval = config.DiagnosticRecordingInterval; if (userDeduplicator != null && userDeduplicator.FlushInterval.HasValue) { _flushUsersTimer = new Timer(DoUserKeysFlush, null, userDeduplicator.FlushInterval.Value, userDeduplicator.FlushInterval.Value); } else { _flushUsersTimer = null; } if (diagnosticStore != null) { SetupDiagnosticInit(diagnosticDisabler == null || !diagnosticDisabler.Disabled); if (diagnosticDisabler != null) { diagnosticDisabler.DisabledChanged += ((sender, args) => SetupDiagnosticInit(!args.Disabled)); } } }
/// <summary> /// Adds the standard properties for events configuration. /// </summary> /// <param name="builder">the object builder</param> /// <param name="config">the standard event properties</param> /// <param name="customEventsBaseUri">true if the SDK is using a custom base URI for events</param> /// <returns>the builder</returns> public static LdValue.ObjectBuilder WithEventProperties( this LdValue.ObjectBuilder builder, EventsConfiguration config, bool customEventsBaseUri ) => builder.Set("allAttributesPrivate", config.AllAttributesPrivate) .Set("customEventsURI", customEventsBaseUri) .Set("diagnosticRecordingIntervalMillis", config.DiagnosticRecordingInterval.TotalMilliseconds) .Set("eventsCapacity", config.EventCapacity) .Set("eventsFlushIntervalMillis", config.EventFlushInterval.TotalMilliseconds) .Set("inlineUsersInEvents", config.InlineUsersInEvents);
private DefaultEventSender MakeSender(HttpServer server) { var config = new EventsConfiguration { DiagnosticUri = server.Uri.AddPath(DiagnosticUriPath), EventsUri = server.Uri.AddPath(EventsUriPath), RetryInterval = TimeSpan.FromMilliseconds(10) }; var httpProps = HttpProperties.Default.WithAuthorizationKey(AuthKey); return(new DefaultEventSender(httpProps, config, NullLogger)); }
private void TestPrivateAttribute(string privateAttrName, bool globallyPrivate) { var builder = User.Builder("userkey") .Anonymous(true) .Secondary("s"); var topJsonBuilder = LdValue.BuildObject() .Add("key", "userkey") .Add("anonymous", true) .Add("secondary", "s"); var customJsonBuilder = LdValue.BuildObject(); Action<string, Func<string, IUserBuilderCanMakeAttributePrivate>, string, LdValue.ObjectBuilder> setAttr = (attrName, setter, value, jsonBuilder) => { if (attrName == privateAttrName) { if (globallyPrivate) { setter(value); } else { setter(value).AsPrivateAttribute(); } } else { setter(value); jsonBuilder.Add(attrName, value); } }; setAttr("avatar", builder.Avatar, "http://avatar", topJsonBuilder); setAttr("country", builder.Country, "US", topJsonBuilder); setAttr("custom1", v => builder.Custom("custom1", v), "value1", customJsonBuilder); setAttr("custom2", v => builder.Custom("custom2", v), "value2", customJsonBuilder); setAttr("email", builder.Email, "*****@*****.**", topJsonBuilder); setAttr("firstName", builder.FirstName, "first", topJsonBuilder); setAttr("ip", builder.IPAddress, "1.2.3.4", topJsonBuilder); setAttr("lastName", builder.LastName, "last", topJsonBuilder); setAttr("name", builder.Name, "me", topJsonBuilder); topJsonBuilder.Add("custom", customJsonBuilder.Build()); topJsonBuilder.Add("privateAttrs", LdValue.ArrayOf(LdValue.Of(privateAttrName))); var userJson = topJsonBuilder.Build(); var config = new EventsConfiguration(); if (globallyPrivate) { config.PrivateAttributeNames = ImmutableHashSet.Create<UserAttribute>( UserAttribute.ForName(privateAttrName)); }; TestInlineUserSerialization(builder.Build(), userJson, config); }
public DefaultEventSender(HttpProperties httpProperties, EventsConfiguration config, Logger logger) { _httpClient = httpProperties.NewHttpClient(); _httpProperties = httpProperties; _eventsUri = config.EventsUri; _diagnosticUri = config.DiagnosticUri; _retryInterval = config.RetryInterval ?? DefaultRetryInterval; _logger = logger; // Currently we do not have a good method of setting the connection timeout separately // from the socket read timeout, so the value we're computing here is for the entire // request-response cycle. See comments in HttpProperties. _timeout = httpProperties.ConnectTimeout.Add(httpProperties.ReadTimeout); }
private EventProcessor MakeProcessor(EventsConfiguration config, Mock <IEventSender> mockSender, IDiagnosticStore diagnosticStore, IDiagnosticDisabler diagnosticDisabler, CountdownEvent diagnosticCountdown) { return(new EventProcessor(config, mockSender.Object, new TestUserDeduplicator(), diagnosticStore, diagnosticDisabler, NullLogger, () => { diagnosticCountdown.Signal(); })); }
private EventProcessor MakeProcessor(EventsConfiguration config, Mock <IEventSender> mockSender) { return(MakeProcessor(config, mockSender, null, null, null)); }
public EventOutputFormatterScope(EventsConfiguration config, JWriter jw, bool inlineUsers) { _config = config; _jsonWriter = jw; _obj = new ObjectWriter(); }
public EventOutputFormatter(EventsConfiguration config) { _config = config; }
private void TestInlineUserSerialization(User user, LdValue expectedJsonValue, EventsConfiguration config) { config.InlineUsersInEvents = true; var f = new EventOutputFormatter(config); var evalEvent = new EvaluationEvent { FlagKey = "flag", User = user }; var outputEvent = SerializeOneEvent(f, evalEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(expectedJsonValue, outputEvent.Get("user")); Assert.Equal(user.Anonymous ? LdValue.Of("anonymousUser") : LdValue.Null, outputEvent.Get("contextKind")); var identifyEvent = new IdentifyEvent { User = user }; outputEvent = SerializeOneEvent(f, identifyEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(expectedJsonValue, outputEvent.Get("user")); Assert.False(outputEvent.Dictionary.ContainsKey("contextKind")); var customEvent = new CustomEvent { EventKey = "customkey", User = user }; outputEvent = SerializeOneEvent(f, customEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(expectedJsonValue, outputEvent.Get("user")); Assert.Equal(user.Anonymous ? LdValue.Of("anonymousUser") : LdValue.Null, outputEvent.Get("contextKind")); var indexEvent = new IndexEvent { User = user }; outputEvent = SerializeOneEvent(f, indexEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(expectedJsonValue, outputEvent.Get("user")); Assert.False(outputEvent.Dictionary.ContainsKey("contextKind")); }
public static EventUser FromUser(User user, EventsConfiguration config) { EventUserBuilder eub = new EventUserBuilder(user, config); return(eub.Build()); }