public void SendCustomPingsWithSnakeCase() { PingType <NoReasonCodes> customPing = new PingType <NoReasonCodes>( name: "custom_ping", includeClientId: true, sendIfEmpty: false, reasonCodes: null ); BooleanMetricType sampleMetric = new BooleanMetricType( disabled: false, category: "test", lifetime: Lifetime.Ping, name: "boolean_metric", sendInPings: new string[] { "custom_ping" } ); sampleMetric.Set(true); Assert.True(sampleMetric.TestHasValue()); customPing.Submit(); MockUploader.UploadRequest request = mockUploader.GetPendingUpload(); Assert.Equal("custom_ping", request.docType); // Check that we have a non-null client id. JsonDocument jsonPayload = JsonDocument.Parse(request.payload); JsonElement root = jsonPayload.RootElement; Assert.NotNull(root.GetProperty("client_info").GetProperty("client_id").GetString()); // TODO: Check the ping schema. // checkPingSchema(pingJson) }
public void FlushQueuedEventsOnStartup() { string tempDataDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // Re-initialize, we need to point this to the data directory we know of. ResetGlean(tempDataDir); Private.EventMetricType <SomeExtraKeys> eventMetric = new Private.EventMetricType <SomeExtraKeys>( category: "telemetry", disabled: false, lifetime: Private.Lifetime.Ping, name: "test_event", sendInPings: new string[] { "events" }, allowedExtraKeys: new string[] { "someExtra" } ); eventMetric.Record(extra: new Dictionary <SomeExtraKeys, string> { { SomeExtraKeys.SomeExtra, "bar" } }); Assert.Single(eventMetric.TestGetValue()); // Start a new Glean instance to trigger the sending of "stale" events ResetGlean(tempDataDir); MockUploader.UploadRequest request = mockUploader.GetPendingUpload(); Assert.Equal("events", request.docType); Assert.Contains("/submit/org-mozilla-csharp-tests/events/", request.url); // Check the content of the events ping. JsonDocument data = JsonDocument.Parse(request.payload); JsonElement root = data.RootElement; // TODO: Check the ping schema. // checkPingSchema(data); JsonElement eventsProperty; Assert.True(root.TryGetProperty("events", out eventsProperty)); Assert.Equal(1, eventsProperty.GetArrayLength()); Assert.Equal("startup", root.GetProperty("ping_info").GetProperty("reason").GetString()); }
public void FlushQueuedEventsOnStartupAndCorrectlyHandlePreInitEvents() { string tempDataDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // Re-initialize, we need to point this to the data directory we know of. ResetGlean(tempDataDir); Private.EventMetricType <SomeExtraKeys> eventMetric = new Private.EventMetricType <SomeExtraKeys>( category: "telemetry", disabled: false, lifetime: Private.Lifetime.Ping, name: "test_event", sendInPings: new string[] { "events" }, allowedExtraKeys: new string[] { "someExtra" } ); eventMetric.Record(extra: new Dictionary <SomeExtraKeys, string> { { SomeExtraKeys.SomeExtra, "run1" } }); Assert.Single(eventMetric.TestGetValue()); Dispatchers.QueueInitialTasks = true; eventMetric.Record(extra: new Dictionary <SomeExtraKeys, string> { { SomeExtraKeys.SomeExtra, "pre-init" } }); ResetGlean(tempDataDir); eventMetric.Record(extra: new Dictionary <SomeExtraKeys, string> { { SomeExtraKeys.SomeExtra, "post-init" } }); MockUploader.UploadRequest request = mockUploader.GetPendingUpload(); Assert.Equal("events", request.docType); // Check the content of the events ping. JsonDocument data = JsonDocument.Parse(request.payload); JsonElement root = data.RootElement; // This event comes from disk from the prior "run" Assert.Equal("startup", root.GetProperty("ping_info").GetProperty("reason").GetString()); JsonElement eventsProperty; Assert.True(root.TryGetProperty("events", out eventsProperty)); Assert.Equal(1, eventsProperty.GetArrayLength()); Assert.Equal("run1", eventsProperty.EnumerateArray().ElementAt(0).GetProperty("extra").GetProperty("someExtra").GetString() ); GleanInstance.SubmitPingByName("events", "background"); request = mockUploader.GetPendingUpload(); Assert.Equal("events", request.docType); data = JsonDocument.Parse(request.payload); root = data.RootElement; // This event comes from the pre-initialization event Assert.Equal("background", root.GetProperty("ping_info").GetProperty("reason").GetString()); Assert.True(root.TryGetProperty("events", out eventsProperty)); Assert.Equal(2, eventsProperty.GetArrayLength()); Assert.Equal("pre-init", eventsProperty.EnumerateArray().ElementAt(0).GetProperty("extra").GetProperty("someExtra").GetString() ); Assert.Equal("post-init", eventsProperty.EnumerateArray().ElementAt(1).GetProperty("extra").GetProperty("someExtra").GetString() ); }