Log Ingestion and Query
Implement a simplified logging system that supports log ingestion and conditional queries.
Each operation is one of the following strings:
ADD timestamp service level message: append one log entryQUERY startTs endTs serviceOr* levelOr* keywordOr*: count matching logs
A log matches a query if startTs <= timestamp <= endTs, service and level match exactly unless the filter is *, and keyword appears as a substring of the message unless the filter is *.
Process all operations in order and return the outputs produced by the QUERY commands.
Complete the function runLogIngestionQueries in the editor below.
runLogIngestionQueries has the following parameter:
String[] operations: the operations to execute in order
Returns
int[]: the counts produced by the QUERY operations.
operations = ["ADD 1 api INFO hello world", "ADD 2 api ERROR something failed", "ADD 3 web INFO user login", "QUERY 1 3 * * *", "QUERY 1 2 api * *", "QUERY 2 3 api ERROR failed"] return = [3, 2, 1]
The three queries count all logs, then all api logs in the first two timestamps, then only the single error log whose message contains failed.
operations = ["ADD 1 api INFO login ok", "ADD 2 api INFO logout ok", "ADD 3 api INFO login failed", "QUERY 1 3 api INFO login", "QUERY 1 3 api INFO ok", "QUERY 1 2 api INFO login", "QUERY 3 3 api INFO login"] return = [2, 2, 1, 1]
Substring matching on the message field allows both successful and failed login events to match the keyword login.
1 <= operations.length <= 2 * 10^5- Timestamps are non-negative integers.
serviceandlevelcontain no spaces.messagemay contain spaces and is matched by substring search.
public int[] runLogIngestionQueries(String[] operations) {
// write your code here
}