6.12. Core Processing Engine

The Retrospective core processing engine searches and monitors your data sources. This chapter describes how it does that, and covers two features that let the engine skip work it does not need to do: search optimization and dynamic monitoring discovery. Retrospective handles four kinds of data source, and several details below differ between them:

  • Local files on the computer running Retrospective.

  • Remote files on a host reached over SSH.

  • Containers in a Docker or Kubernetes subsystem, reached through the local docker / kubectl command-line interfaces.

  • Windows event logs, read by a PowerShell script. For the local computer and for hosts using the WinRM transport, that script runs in the local PowerShell command-line interface: pwsh where PowerShell 7 is installed, the built-in Windows PowerShell otherwise. For hosts using the SSH transport, Retrospective connects itself and runs the PowerShell built into the target machine, or its PowerShell 7 if the host opts in.

6.12.1. How a Search Runs

When you start a search or a monitor, the engine first evaluates every enabled data source in parallel. This reveals the concrete list of files, containers or event logs each data source refers to. The engine performs a file, container or event-log listing, and applies the data source’s filter where one is defined. It then hands each revealed item to its own worker for searching or monitoring.

What happens next — and in particular where the filtering runs — depends on the data source type:

Data source

How a search is processed

Local files

The file is read in chunks. Retrospective splits the content into log entries, extracts the date/time and applies the search criteria — all inside the application.

Remote files (SSH)

The heavy work is pushed to the server: splitting, date/time extraction and criteria filtering are performed there by shell/awk scripts, so only the entries that match the criteria are transferred to Retrospective. Dates are parsed by a script tailored to the data source’s date format and locale.

Containers

The container log stream is fetched through the docker / kubectl CLI and is then split, date-extracted and filtered inside the application. No filtering is pushed to the CLI.

Windows event logs

The PowerShell command filters server-side: time criteria through Get-WinEvent -FilterHashtable (or, when a large log is read in parallel parts, the equivalent -FilterXPath query) and, optionally, other criteria through a Where-Object pipeline, so only matching events are returned. Timestamps come from the structured event record.

Where a search is processed for local files, remote files, containers and Windows event logs

Fig. 6.46 Where the work happens when a search runs, for each kind of data source.

  1. The computer running Retrospective.

  2. A local log file. Its raw content is read into the application.

  3. The core processing engine of Retrospective splits the content into entries, extracts the date/time and applies the search criteria.

  4. Matching entries are written to the result database, and the result table shows them.

  5. A remote server, reached over SSH.

  6. A log file on that server.

  7. A generated shell script splits, extracts the date/time and applies the criteria on the server.

  8. Only the matching entries cross the connection, so the network carries a fraction of the data and the server does the heavy work.

  9. The docker or kubectl command on this computer.

  10. The complete log of the container reaches Retrospective, which splits and filters it.

  11. The local PowerShell. It reads the event logs of this computer and runs the script on a WinRM host through Invoke-Command.

  12. A Windows host.

  13. PowerShell on the host filters the events with Get-WinEvent and Where-Object. Over SSH, Retrospective connects to the host itself.

  14. The host drops the events that do not match. Retrospective then applies the whole filter again.

Two related details also depend on the type:

  • Encoding. For files and containers, the raw bytes are converted to characters using the encoding configured for the data source. Windows event logs are structured records, so no encoding step applies.

  • Compressed files. For file data sources (local and remote), supported archives (.zip, .gz, .bz2, .tar, .tar.gz, .tgz, .tar.bz2, .tbz2) are decompressed on the fly. The type is recognized by the file name extension, which is case-sensitive: a .GZ file is not decompressed. Containers and event logs have no compression step. For remote hosts the appropriate decompression tools must be available (see Host Compatibility Information).

6.12.2. Searching Versus Monitoring

Searching runs once and finishes when every item has been processed. Monitoring runs continuously until you stop it, and fetches only data that has newly appeared. How it does so depends on the type:

  • Files get one repeating task per item. Each cycle fetches the data that has appeared at the end of the item.

  • Containers keep one continuous log stream open (logs -f).

  • Windows event logs are polled once a second.

By default, monitoring starts without existing data. A per-type start offset on the Search/Monitor preferences page (see Search/Monitor) delivers the most recent existing data when monitoring starts:

Start offset

Unit

Applies to

File Start Offset

Bytes (like tail -c), 0 to 8192

local and remote files

Container Start Offset

Lines (like tail -n), 0 to 100

Docker / Kubernetes containers; Kubernetes turns 0 into 1 line

Windows Event Log Start Offset

Events, 0 to 100

Windows event logs

For remote files, the place where the filtering runs during monitoring differs from searching. During monitoring, Retrospective applies the criteria inside the application for local files, containers and remote SSH files. Windows event logs continue to be filtered server-side through a sliding time window.

Note

A Windows event log monitor reads each time window once. An event can be missed when it is written before the first window opens, when it reaches the log only after its window was read, or when it is written while the monitor reconnects. The Windows Event Log Start Offset delivers the most recent existing events when monitoring starts. For a complete result over a time range, run a search.

How a monitor fetches new data from a remote file, a container and a Windows event log

Fig. 6.47 How a monitor fetches new data.

  1. The core processing engine starts a cycle and keeps repeating it until you stop the monitor.

  2. Each cycle lists the items the data source resolves to and compares them with the previous round.

  3. The listing reads only the size and identity of each item, not its content.

  4. An item that has grown gets a task that fetches the newly appended data; a new item gets one that reads it from the beginning. An unchanged item causes no fetch at all.

  5. The core processing engine splits, date-extracts and filters the fetched data. The new entries are written to the result database and appended to the result table.

  6. A container keeps one continuous log stream (logs -f) open. Unless all data is fetched, the stream starts with --tail N, where N is the start offset (at least 1 for Kubernetes). Retrospective filters the stream itself.

  7. For a Windows event log, one long-running script fetches the events of each new one-second time window and filters them where it runs.

The newest entry of a file or container appears once its item has stayed quiet for half a second, so an entry written in several parts appears as one. A Windows event-log event appears within about one second.

When the host of a data source stops answering during monitoring, for example because it shuts down, Retrospective retries the affected item up to four times, one second apart. If it still fails, it reports the error in the status view, and the other items continue. When no item is left to monitor, the monitor stops by itself with the warning Monitoring stopped because none of the data sources can be monitored any more. Monitoring duration was <duration>.

6.12.3. Processing Over SSH

For remote files Retrospective never installs an agent and never modifies anything on the server. It only needs SSH access, and it uses the standard tools already present on the host (detected as described in Host Compatibility Information). Moving the work to the server has several benefits:

  • The heavy work does not consume the resources of the computer running Retrospective, and only the data matching the criteria crosses the network.

  • The server performs the date/time filtering with a script that adapts to the date format and locale of the data source. Dates in any supported format are therefore interpreted correctly there.

  • Each file is searched by its own SSH command. Thread and connection pooling limit the number of connections. The number of parallel connections to a host rises after 10 successful openings and falls on connection errors. It stays between 1 and the host’s Maximum Connections, set in the Host Manager (at most 15).

A timestamp in a log file carries no description of itself, so the script has to be told how to read it. In 2012-05-08, is 05 the month or the day? In May 17 12:20:39.227, which year does the entry belong to, and is 227 a fraction of a second or something else? A month name may also be written in the language of the server, as in Mai 17. Retrospective therefore generates the filtering script from the date format and locale configured for the data source, not from a fixed pattern. A wrong date format consequently shows up as unreliable time filtering rather than as an error.

6.12.4. Search Optimization

Search optimization lets the engine avoid reading files whose content cannot possibly fall within a time criterion. For remote files, it also avoids reading the parts of a file that cannot fall within that criterion.

Applies to

File data sources only (local and remote). It is not used for containers or Windows event logs. It runs during searching only, never during monitoring, and only when the search criteria contain a time criterion. It applies when that time criterion is AND-joined with the other criteria. For local files it also applies when the criteria are OR-joined and every one of them is a time criterion. For remote files it supports one time criterion only, and aborts with a status message when there are several.

For each eligible file, Retrospective reads about 64 KB from the start and from the end. This gives the date of the first and the last log entry, which Retrospective compares with the time criterion:

  • Local files larger than 1,000,000 bytes: if the whole file falls outside the time frame it is skipped.

  • Remote files of 500 KB or more: the file is skipped if it falls entirely outside the time frame, and otherwise the search is narrowed down to the byte range that can match.

For a local compressed file, only the start is analyzed, because decompressing the whole file would be too slow. A remote compressed file is searched in full. Multi-file tar archives are not optimized, because no assumption can be made about the date ordering across the contained files.

A separate option, Consider file modification date, skips a file whose last-modified time lies entirely before the search time frame. It applies to files only, and the status view reports each skipped file.

Before it trusts the two border dates, Retrospective checks that the sample it read is representative. The check fails, and the file is then searched in full, when any of the following holds:

  • more than two of the analyzed entries carry no date at all;

  • fewer than five entries yielded a date (fewer than four for a remote file);

  • the dates of the analyzed entries are not in ascending order.

For a local file, a failed check is reported as Search optimization failed in the status view. The report names the host and file it read, which end of the file was analyzed, and which of the three rules above was not met; further warnings of the same search are suppressed. For a remote file, the report comes from the server script and names the analyzed 64 KB. It usually points at the data source rather than at the file: a date format or locale that does not match the data, a log entry separation that splits entries in the wrong place, or genuinely unordered dates. The first two are worth correcting in Configure Data Source(s), because they also affect sorting and time filtering. See When Processing Goes Wrong.

Both options, Enable file time range optimization and Consider file modification date, live in the Searching group of the Search/Monitor preferences page (see Search/Monitor). Both are enabled by default. Reading the start and the end of each file carries a small overhead. Disable search optimization only in cases where it cannot help, for example when searching many small files for a time frame that covers most of them.

6.12.5. Dynamic Monitoring Discovery

Dynamic monitoring discovery lets a running monitor pick up items that appear after monitoring has started.

Applies to

Monitoring only. It is supported for local files, remote SSH files and containers, but not for Windows event logs.

While a monitor is running with dynamic discovery enabled, Retrospective includes new items that begin to match the data source. Examples are a new file matching a Select items using filter data source, a new file created in a watched directory, and a new container matching the filter. The next daily file of a syslog server such as WinSyslog is a typical case (see Log Files from a Syslog Server). For a Select items individually data source whose path does not yet exist, Retrospective waits until the path appears and then starts monitoring it.

Log rotation is handled correctly: a renamed file is recognized by checksum rather than treated as new, so only genuinely new content is fetched.

Behind this, Retrospective repeatedly lists the items the data source resolves to and compares each with the state of the previous round. A new item gets its own fetch task that reads the file from its beginning; an item that has grown gets one that reads only the new data; an unchanged item causes no work at all. Because the tasks are created only when there is something to read, a filter-matching data source with many idle files costs little on either machine.

Two kinds of item are skipped. A compressed file is not followed, since its content only becomes readable once it is complete, and a file the account cannot read is skipped as well. Each newly discovered file of either kind is reported once in the status view: a compressed one while Show Warnings for Compressed File is on, an unreadable one always. Compressed files present when the monitor starts are reported there too while the option is on.

With and allow Autofind enabled, Retrospective fetches an initial part of a newly discovered item before it starts following it, and verifies that the configuration fits the data. Two things can go wrong, and both are reported in the status view rather than silently ignored:

  • The log entry separation is not found. Autofind then analyzes the item and determines encoding, log entry separation and date format. The warning reads In initial part of file <file> log entry separation was not found. <details>.

  • The date cannot be parsed in some of the initial entries. The warning reads Data Source <name>: The date could NOT be parsed in <n>/<m> initial entries. <details> <hint> and so names how many entries failed. The remedy is to check the date format configured for the data source.

Without and allow Autofind, no verification runs and the item is followed with the configured separation.

Dynamic discovery is controlled by the Enable Dynamic Discovery option on the Search/Monitor preferences page (see Search/Monitor). The and allow Autofind checkbox that follows it on the same row lets Retrospective analyze newly discovered files and containers automatically. Both options are defaults that each search tab can override.

6.12.6. When Processing Goes Wrong

Most processing problems are reported in the status view rather than as a dialog, so a search finishes with fewer entries than expected instead of failing outright. The table names what each report means and what to do about it.

Report

Cause and remedy

The host cannot be reached, or a command is refused

The account has no access to the path, or the host is unreachable. Test the connection in the Host Manager and check that the account may read the data source.

Monitoring stopped because none of the data sources can be monitored any more

Every item of the monitor has stopped, usually because its host cannot be reached. The status view lists the error for each one. Correct the cause, then start the monitor again.

The date could not be parsed in some entries

The date format configured for the data source does not match the data. Correct it in Configure Data Source(s), step Date/Time Recognition (Step 2 of 3) (see Configure Sources), or let Autofind determine it. Until it is right, sorting and time filtering stay unreliable and search optimization is skipped.

Log entry separation was not found

The configured separation does not occur in the data, so entries are split in the wrong place. Correct it in Configure Data Source(s), step Log Entry Separation (Step 1 of 3).

The content is unreadable, or entries look garbled

The configured character encoding does not match the file. Correct the encoding of the data source in step Log Entry Separation (Step 1 of 3); Autofind proposes one from the data.

Search optimization failed

The sample Retrospective read was not representative. The file is searched in full, so no entries are lost. The underlying cause is one of the two above, or genuinely unordered dates.

A data source whose entries differ in shape — several formats written to one file — is best split into two data sources with matching filters, so each can carry its own separation, date format and encoding.

6.12.7. Limits

Two safeguards protect the computer running Retrospective:

  • Free disk space. When less than 100 MB is free on the partition of the result database, results are no longer stored and a warning appears. The search itself continues.

  • Unsplit content. When the data contains no log entry separation for a long stretch, the content accumulates. A search or monitor stops when it exceeds 10 MB by default, adjustable from 1 to 100 MB. At monitor start the limit is 100 KB by default, adjustable from 1 to 1000 KB. Both are set on the Search/Monitor ‣ Log Entry Separation preferences page.