Rogier Boon & Olaf Hartong
Understanding the ingestion of logs
To understand how time plays a role in detections, it is important to find out how ingestion takes place.
In the ideal world, if an event happens on a system, it is immediately sent to the cloud and can directly be used in a detection. It turns out that reality is different. To understand this process a bit better, let’s follow an event from the moment it is generated up to the point that it is part of a detection.
For example, on Windows, a process can view the memory of another process with the use of the function NtMapViewOfSection. This can be an interesting event, as in an attack scenario this can be used to inject arbitrary code in another process and running such code potentially provides benefit to the attacker.
For our defensive benefit, the NtMapViewOfSection function call results in an event being generated on the system where both involved processes are active. The moment this event is being created is known as TimeGenerated or Timestamp. Note that this timestamp is set by the local clock. So, when for some reason the local clock is 42 minutes ahead, this timestamp will also be 42 minutes ahead.
Our generated event is then stored on the system in a buffer. How long it stays there depends on the delivery channel and what the device is doing. The arrival of our event is registered in the cloud as _TimeReceived, a field available in Log Analytics-based tables. Defender does not expose this (hidden) field in its tables.
After the event has been received, it is processed so the fields of the appropriate table can be filled. The amount of processing required will vary by event, but may take something between seconds and minutes.
Eventually, the processed event is available in the table to be queried and this moment is recorded in the hidden field $IngestionTime of which the value can be obtained with the function ingestion_time().
Figure1. Graphical overview of the event ingestion process and relevant timestamp fields.
Our event will end up in the DeviceEvents table where the event is given the ActionType NtMapViewOfSectionRemoteApiCall.
Figure 2. Timestamp details of our event in Sentinel.
We can see all the mentioned timestamps in a Sentinel environment, but not in MDE, as the _TimeReceived field isn’t available for a query there.
Ingestion delay
With more detailed knowledge of log ingestion, we can pinpoint the following spots that will cause a delay in the ingestion of events:
- Buffering events on the system.
- Upload time from the system to the cloud, probably depending on available bandwidth.
- Event processing time.
While these specific delays apply to the Defender solution that we are exploring, other solutions have similar or the same spots of ingestion delay in their architecture.
Of course, life is happening and all sorts of situations can add to the ingestion delay. Think of the scenario when an event is generated on a laptop at the same moment the user is traveling between meeting rooms. The network connection of the laptop may be interrupted for a while, resulting in small delay.
Or another situation where the user closes the laptop at the end of the day. The event will happily have a sleepover in the local buffer and be shipped to the cloud first thing next morning. This scenario will easily add a couple of hours to the ingestion delay.
How long does the sensor hold an event?
Let’s leave the laptop plugged in and online for a moment. While investigating this behavior, we have created several packet captures to analyze the flow of telemetry from a host. In one of our Windows MDE captures, the sensor sent a batch of 405 event envelopes to OneCollector, the telemetry collection endpoint in the cloud. Just 1.4 seconds later, it sent another six to exactly the same URL. Why make a second trip so soon?
The difference was in the sensor’s check-in with the command service. It reports two timestamps, lastNormalUploadTime and lastRealtimeUploadTime. When we matched those to the captures we’ve made, the time between normal uploads was about two minutes. For real-time envelopes, the median wait between the timestamp on the envelope and the start of its upload was 1.19 seconds. The cloud still had to process the event before we, or our detection, could see it in the tables.
The MDE configuration defines whether the event takes the normal or expedited (realTime) route. While we leave the retrieval of this configuration as an exercise to the reader, most of the events collected follow the normal flow. The expedited / real-time flow is configured for approximately 32 event types. For example, AV detections, tampering detections, driver unloads, and sensor health monitoring.
Additionally, the configuration gives us a clear view on what happens when we unplug the laptop or when it is on a slow connection. It contains two sets of timers. One is for the telemetry reporter, the other for checking in with the command service. The former influences how frequently the normal telemetry is being uploaded from the buffer in the database.
A dash means there was no entry for that condition. All three configurations selected the Normal profile. Expedite had the same timer values. The one-second entry applies during shutdown. The real-time numbers mentioned above come from timing the uploads themselves.
What if the laptop goes offline altogether? We know the sensor can keep events on disk and found the following limits in the configuration.
The disk budget only tells us how much data it will retain. How many hours that buys our laptop depends on how busy it is.
Device performance can be another potential factor for missing or delayed. The sensor defines several modes of operation, where Critical mode is the important distinction. Microsoft documents that the EDR client stops processing new events while in Critical mode and resumes when resource usage returns to normal. That affects what the sensor processes in the first place, upstream of the normal and real-time upload channels. The config doesn’t establish that 85 means 85% total machine CPU, nor specifies which event families are included or excluded. Since this is not a direct time-related topic and more a capping / telemetry completeness issue, we will defer this topic to a future blog post.
Investigating the real world – profiling your environment
We have learned that there is not only one, but there are at least three timestamps involved with an ingested event, and we can use them to profile our environment.
For example, we can calculate how much time has passed between event generation TimeGenerated and ingestion ingestion_time() to get the ingestion delay.
Consider the following KQL:
union withsource=Table Device*Events
| where Table !contains “Custom”
| extend IngestionTime = ingestion_time()
| extend Diff = datetime_diff(‘minute’, IngestionTime, TimeGenerated)
| project Table, TimeGenerated, IngestionTime, Diff
| summarize avg(Diff), percentiles(Diff, 50, 95, 96, 97, 98, 99) by Table
| sort by percentile_Diff_99 asc
The result of this query is the number of minutes it takes for a certain percentage of data is available. This is reported per table.
When running this in a reasonably sized production environment, it produces the following:
Figure 3. Results of ingestion delay calculation.
This delay calculation provides us some insights into the completeness of the percentage of ingested data in a certain timeframe. What we can see from the results above is that it takes a bit over an hour (65 minutes) for 96% of the data in the DeviceNetworkEvents table to be ingested. Or phrased the other way around, about 4% of the data is still missing.
That said, we’ve seen quite some improvement recently. We have been tracking this in our lab environment for over 2 years. And besides some maintenance that is performed, the systems in our lab as they are always on and aren’t moving to different meeting rooms during the day, or shut down at 16:59 on Friday afternoon to call it a weekend.
The following are the numbers from our lab in 2024:
Figure 4a. 2024 ingestion delay numbers in our lab environment.
Running the same around October 2026 provided the following:
Figure 4b. October 2026 delay numbers in our lab environment.
We clearly see improvement, especially when you look at the 98 and 99 percentiles.
What does this mean for our detections? To answer that question, we need to dive a bit into the detection scheduling mechanism.
Detection scheduling mechanism
A custom detection behaves a bit like job scheduling, similar to scheduled tasks or cron jobs. We want to periodically perform a KQL query on our data, which means that:
- We configure the frequency we want our detection to be executed.
- We configure the data where we want to apply our query to, also known as lookback.
This allows you, for example, to create a custom detection that runs every hour and uses the last four hours of available data.
The way the frequency and the lookback are configured is currently being altered by Microsoft, as there is an UI difference for configuring these properties when the preview features are enabled for XDR. One way you can notice this, is when creating a custom detection through the XDR portal. The XDR portal offers what seems to be called the “Unified Experience” as a UI, which can behave differently between different tenants depending on the preview feature setting.
First, we should be aware that this UI is currently supporting two products behind the scenes. MDE is one of them, with its own (shared) infrastructure and detection scheduler. The configuration options for scheduled detections are somewhat limited, which I’ll explain in a bit. The other one is what I call the “Sentinel scheduler”, which allows you to run custom detections labeled in the XDR portal as analytics rules. This Sentinel scheduler allows a bit more parameters to be configured when scheduling a detection.
Scheduling in MDE
For a long time, when you created a custom detection in MDE, you only had the option to configure the frequency. This is still the case in one of our tenants that doesn’t have any preview features enabled and (still) only has the frequency as option to configure the schedule of the custom detection.
Figure 5. Screenshot of the create custom detection user interface of MDE. You can see that there is only a frequency field that can be configured to schedule the detection.
The MDE UI also supports creating a custom frequency, which makes it possible to configure a more fine-grained frequency that can range from 5 minutes to 14 days without the need to provide the lookback.
Figure 6. Screenshot of the create custom detection user interface of MDE. You can see that, even if you configure a custom frequency, you cannot specify a lookback.
So, if the UI won’t let us specify the lookback period, on what data is the query executed?
According to the Microsoft custom detection documentation the following applies:
- For detections set to run every 24 hours, the lookback period is 30 days.
- For detections set to run every 12 hours, the lookback period is 48 hours
- For detections set to run every three hours, the lookback period is 12 hours.
- For detections set to run hourly, the lookback period is four hours.
This means that when you create a custom detection that runs every hour, the query will process 4 hours of data. We now have two issues that need to be considered:
- Every hour you need to process 4 hours of data, which may take quite some processing effort.
- With this schedule and this volume of data, a single event can create 4 alerts, one every hour, until the event is no longer in the lookback period. Luckily, MDE will deduplicate these alerts for us.
Observe that the documentation does not make a statement about the lookback for detections running every 5 minutes.
Scheduling in Sentinel
The Sentinel custom detection scheduler allows a more fine-grained configuration with regards to detection scheduling. From its early beginning, Sentinel allowed a detection to run every five minutes. Also, the lookback period always had to be specified explicitly per detection. As usual, great power comes with great responsibility. For us, it means we must choose our lookback period very strictly or do the deduplication of alerts ourselves.
As far as I can tell, the Sentinel way of creating detections is going to be the new standard, and the new XDR UI requires the configuration of a lookback period in addition to the detection frequency. Notice the additional lookback field that isn’t available in the ‘MDE’ UI shown above.
Figure 7. Sentinel scheduler options available, including a lookback value.
Time in detections
As a detection engineer, you want to have control on what is being queried. Adding a KQL clause on time to clearly mark what data is to be processed is therefore common practice. Also, the statically configured frequency/lookback behavior of MDE forces you to be stricter on the data that is being processed, to keep the performance of a detection in control.
Often this time clause takes the following form:
| where TimeGenerated >= ago(timeframe)
Where timeframe is a value that is close or equal to the frequency.
This greatly improves efficiency, as there is less data to process and there is no chance of duplicate alerts. It also introduces a gap in the detection with regards to delayed events (remember the 4% of data arriving late to the party?). This is because at the time the detection is executed, the event with a TimeGenerated value in the timeframe might not yet be ingested.
When the event is eventually ingested and the next scheduled run is executed, the TimeGenerated of the event will not be in the timeframe period of this run. Basically, we’re missing events that have happened, but never triggered an alert.
A solution to this issue is to use ingestion_time() instead of TimeGenerated. The time clause will then become:
| where ingestion_time() >= ago(timeframe)
This way, even when an event arrives at a later moment, it will be taken into account by the detection logic.
About lookback
If you’ve arrived at this point in the blog and are still reading, you probably ask yourself the following: If the lookback is going to be configurable for everyone anyways, why bother adding a time clause in the KQL for every custom detection and just choose a proper lookback?
Well, good question and answered with the usual answer: it depends.
From a functional perspective, setting a lookback period has basically the same meaning as adding a time clause in the KQL. From a technical perspective, setting the lookback has bigger implications.
Until it doesn’t.
We performed a small test by scheduling the following query in both the fully-preview- feature-enabled lab tenant, as well as in our boring out-of-the-box tenant:
union DeviceProcessEvents, DeviceFileEvents
| extend IngestTime = ingestion_time()
| extend Now = now()
| project IngestTime, TimeGenerated, Now, DeviceId
| summarize MinIngest = min(IngestTime), MaxIngest = max(IngestTime), MinTimeGen = min(TimeGenerated), MaxTimeGen = max(TimeGenerated), MinNow = min(Now), MaxNow = arg_max(Now, *)
| extend DiffIngestTime = datetime_diff(‘minute’, MaxNow, MinIngest)
| extend DiffTimeGenerated = datetime_diff(‘minute’, MaxNow, MinTimeGen)
This query takes the ingestion_time() and the TimeGenerated and calculates the difference between the moment the query executed (now()) and the first available ingestion time and TimeGenerated respectively. If the TimeGenerated is used as to determine the dataset for the lookback we expect a DiffTimeGenerated of about 60 minutes as result. If ingestion_time() is used to determine the lookback dataset, we expect the DiffIngestTime to be about 60 minutes.
For the boring tenant, we configured a frequency of 5 minutes, which lead to a lookback of 1 hour. For the preview tenant, we configured a frequency of 1 hour with a lookback of 1 hour.
For the boring tenant, we can indeed spot the results of a TimeGenerated cutoff of the lookback. As can be seen in the snippet below, the TimeGenerated difference is cut off at 60 minutes, while the ingestion time difference is less. This makes sense, as an event is generated first, setting TimeGenerated, and ingested later.
Figure 8. Result of the query in an out-of-the box tenant (no preview options enabled).
When running the same query in the preview tenant, we get the following:
Figure 9. Result of the query in a tenant with preview options enabled
What can be seen here, is a series of ingest time differences with a maximum of 60 minutes, while the TimeGenerated difference is above the 60-minute threshold. For me, this suggests that Microsoft is moving to using ingestion_time() as a method to determine the lookback period.
This is a very nice improvement and basically would allow you to use the lookback configuration of a custom detection as a time constraint and adding an explicit time condition in the KQL is a thing of the past.
Going back to the laptop example where data arrives more than 4h after an infection because it was closed and the user went home right after. The data arrives 12 hours later when the user continues work the next morning. The data is ingested, but will have a TimeGenerated of 12 hours ago. In the old situation, this data will be lost, causing a blindspot. With this improvement, this data will be in the 4-hour lookback dataset and can be taken into account by a detection.
Are there more time issues?
There definitely used to be more time-related issues. One of them being scheduler drift. What you would expect from the scheduler when a frequency is set to 1 hour is a very strict sequence of runs. So, let say the first run is at 10:00:00, then the next one is expected at 11:00:00, 12:00:00, 13:00:00 and so on.
What actually happened is that the first one starts at 10:00:00 and the next one runs on 11:06:00. So, there is a gap of 6 minutes that may cause blindspots if the data lookback value is set too strict. This applies to both the time constraint being set in the query and in the lookback configuration of the custom detection.
We’ve made a graph of the scheduler drift in the past resulting in the following:
Figure 10. Scheduler drift in 2022.
Note that the scale of this graph is measured in minutes. So, the drift of the scheduler would on average be 5 minutes past the hour when a frequency of 1 hour is configured.
To solve this issue, we’ve chosen to always double the lookback timeframe within our configurations and we’ve created tooling to lower the chances for us making mistakes.
When we make the same graph now, we get the following results:
This graph measures the difference in seconds and not in minutes. The big peak in the graph has about a 20 second offset from the hour and this offset is compensated in the next run to get the schedule back on track. It looks very similar to the behavior as we have found during our NRT research.
Having said all that about the scheduler drift, we know for certain that Microsoft will continue to make changes. It is wise to keep an eye out for changes in the scheduler drift and prevent making assumptions on the behavior.
To sum it up
There is more to time than using UTC. To get a solid grasp of it, you have to understand the moving parts of the detection stack. Ingestion time is something that will always be there and that you have to take into account when creating detections.
There have been quite some improvements in the XDR environment to the benefit of the detection engineer. Nevertheless, it is important to be aware that things will continue to change in the future. It is important to keep an eye out on ingestion delay and make sure that your detections can cope with fluctuations of the delay for your important log sources.
Still, the improvements in the detection scheduler are quite impressive and for the change using ingestion time as lookup criterium I think: it’s about time.
Knowledge center
Other articles
Dissecting WerFault
[dsm_breadcrumbs show_home_icon="off" separator_icon="K||divi||400" admin_label="Supreme Breadcrumbs" _builder_version="4.18.0" _module_preset="default" items_font="||||||||" items_text_color="rgba(255,255,255,0.6)" custom_css_main_element="color:...
Introducing FalconDash, your tuning companion
[dsm_breadcrumbs show_home_icon="off" separator_icon="K||divi||400" admin_label="Supreme Breadcrumbs" _builder_version="4.18.0" _module_preset="default" items_font="||||||||" items_text_color="rgba(255,255,255,0.6)" custom_css_main_element="color:...
I’m in your logs now: deceiving analysts and blinding EDRs
[dsm_breadcrumbs show_home_icon="off" separator_icon="K||divi||400" admin_label="Supreme Breadcrumbs" _builder_version="4.18.0" _module_preset="default" items_font="||||||||" items_text_color="rgba(255,255,255,0.6)" custom_css_main_element="color:...
FalconForce realizes ambitions by working closely with its customers in a methodical manner, improving their security in the digital domain.
Energieweg 3
3542 DZ Utrecht
The Netherlands
FalconForce B.V.
[email protected]
(+31) 85 044 93 34
KVK 76682307
BTW NL860745314B01



