This Repo contains the labs we are going to work though as part of the Log on Grail - DQL Hands On Workshop.
For the purposes of the Hands-On, we will automate and make the steps seamless for the participants
We will start with simple use-cases such as simple filters and aggregations to more refined scenarios where arithmetics is used to calculate time distances between significant events.
In this part the workshop tutor will explain the fundamentals of DQL.
Task: Get an Overview of the current state of the DQL capabilities by exploring the documentation
Task: Try to find narrow down the hosts where hipstershop is running
Intended result:
Directions and supporting material
fetch logsTask: Get an overview about whether processes suffer from significant logs on a specific host.
fetch logs and extend the timeframe to last 3h"i-040585ffc09e5c519".Intended result:
Directions and supporting material
Task: Find the most recent ERROR log for a specific host
fetch logs, from:now()-6h
| filter contains(dt.process.name,"reverseproxy") and loglevel == "ERROR"
filter host.name == "i-040585ffc09e5c519" and loglevel == "ERROR", assuming this host existsIntended result:

Directions and supporting material
Task: Calculate the age in seconds and minutes of the most recent Error log
fetch logs, from:now()-1h
| filter host.name == "i-040585ffc09e5c519" and loglevel == "ERROR"
| sort timestamp desc
| limit 1
| fieldsAdd age_seconds = (now()-timestamp)/1000000000
Intended result:
Directions and supporting material
Task: Did the same ip-address have both a successful and unsuccessful checkout event within a 10 minute time window?
fetch logs, from: now()-1h
| filter host.name == "i-040585ffc09e5c519"
| filter contains(content, "POST /cart/checkout")
| sort timestamp desc
| parse content, "IPADDR:ip LD 'HTTP/1.1' SPACE LONG:http_s SPACE LD "
summarize command in combination with the countIf() function to callculate the number of successful checkouts and failed checkoutsby: Parameter of summarize to group the result by ip and 10 minte timebucketsIntended result:
Directions and supporting material
...
| summarize success = countIf(http_s>=200 and http_s <=400), fail = ... , by:{ip, bin(timestamp, 10m)} | sort fail desc
Now let's go a few steps ahead and get a glimps what can already be done with DQL!
Task 6.1: Let‘s find all IP addresses that first have put a product into the cart and afterwards failed to checkout. Also, let‘s calculate the time distance between those events
fetch logs, from:now()-30m
| filter host.name == "i-040585ffc09e5c519"
| filter contains(content, "POST /cart")
| parse content, "IPADDR:ip LD 'HTTP/1.1' SPACE LONG:http_s SPACE LD"
| fields timestamp, content, ip, http_s
Intended result:

Task 6.2: Calculating the time distance between cart events and checkout fails
Extend the query used in task 6.1 and add the following five pipeline processing steps and try to understand what happens. Feel free to add each line sequentially to see the intermediate results up to the final stage!
...
| fieldsAdd isCheckout = contains(content,"checkout")
| fieldsAdd checkout_fail_ts = if(isCheckout and http_s == 500, toLong(timestamp)),
cart_success_ts = if(NOT isCheckout and http_s <= 302, toLong(timestamp))
| summarize cart_success_first = first(cart_success_ts), checkout_fail_first = first(checkout_fail_ts), by:ip
| fieldsAdd delay_seconds = (checkout_fail_first - cart_success_first)/1000000000
| fieldsAdd failAfterCart = if(delay_seconds > 0, true, else:false)
Intended result:
fetch logs, from:now()-30m
| filter host.name == "i-040585ffc09e5c519"
| filter contains(content, "POST /cart")
| parse content, "IPADDR:ip LD 'HTTP/1.1' SPACE LONG:http_s SPACE LD"
| fields timestamp, content, ip, http_s
| fieldsAdd isCheckout = contains(content,"checkout")
| fieldsAdd checkout_fail_ts = if(isCheckout and http_s == 500, toLong(timestamp)),
cart_success_ts = if(NOT isCheckout and http_s <= 302, toLong(timestamp))
| summarize cart_success_first = first(cart_success_ts), checkout_fail_first = first(checkout_fail_ts), by:ip
| fieldsAdd delay_seconds = (checkout_fail_first - cart_success_first)/1000000000
| fieldsAdd failAfterCart = if(delay_seconds > 0, true, else:false)
