Parsing Logs

Overview

Transform unstructured log messages into structured, queryable data. By extracting fields from log messages, you can unlock powerful filtering, searching, and analysis capabilities in groundcover.

Why Parse Logs?

Raw log messages often contain valuable information buried in unstructured text. Parsing allows you to:

  • Extract meaningful fields from log messages for better searchability

  • Structure your data to enable powerful filtering and querying

  • Enrich logs with additional context and metadata

  • Standardize formats across different services and applications

Best Practices

  1. Use conditions effectively - Only parse logs from relevant workloads to minimize processing overhead

  2. Test in the Parsing Playground - Always test your parsing rules before deploying

  3. Cache intermediate results - Use the cache variable for temporary storage during multi-step transformations

  4. Be specific with patterns - More specific GROK patterns perform better and are less likely to cause false matches

Common Parsing Use Cases

Parsing JSON Logs

Extract fields from JSON-formatted log messages.

Log

Rule

Result

Merging Multiline Logs

Merge multiline log entries (stack traces, system warnings, etc) into a single record.

Log

Rule

Result

Extracting Structured Data with GROK Patterns

Use GROK patterns to extract specific fields from formatted log messages.

Log

Rule

Result

Parsing Key-Value Pairs

Extract multiple key-value pairs from bracketed log sections.

Log

Rule

Result

Common GROK Patterns

Here are some commonly used GROK patterns:

  • %{TIMESTAMP_ISO8601} - ISO8601 timestamps (2025-03-23T10:30:45)

  • %{LOGLEVEL} - Log levels (INFO, ERROR, DEBUG, etc.)

  • %{IP} - IP addresses

  • %{NUMBER} - Numeric values

  • %{WORD} - Single words

  • %{NOTSPACE} - Non-whitespace characters

  • %{GREEDYDATA} - Match everything (greedy)

  • %{DATA} - Match everything (non-greedy)

  • %{SPACE} - Whitespace characters

Key Functions

ExtractGrokPatterns

Extracts structured data using GROK patterns.

Basic Usage:

Example - Extract timestamp and error code:

ParseJSON

Parses JSON strings into structured attributes.

Basic Usage:

Example - Parse embedded JSON:

ParseKeyValue

Parses key=value formatted strings.

Basic Usage:

Example - Parse query parameters:

merge_maps

Merges extracted data into the attributes map.

Basic Usage:

Modes:

  • insert - Only add keys that don't exist

  • update - Only update keys that exist

  • upsert - Add or update keys (default behavior)

Example:

keep_matching_keys

Filters a map to keep only keys matching a regex pattern.

Basic Usage:

Example - Keep only lowercase field names:

set

Sets a value to a specific field or attribute.

Basic Usage:

Example - Set computed fields:

replace_pattern

Replaces parts of a string matching a regex pattern.

Basic Usage:

Example - Clean up log messages:

delete_key

Removes a specific key from a map.

Basic Usage:

Example - Remove temporary fields:

Concat

Concatenates multiple strings or values together.

Basic Usage:

Example - Create composite fields:

ToLowerCase / ToUpperCase

Converts strings to lowercase or uppercase.

Basic Usage:

Example - Normalize field values:

Substring

Extracts a portion of a string.

Basic Usage:

Example - Extract prefixes and suffixes:

Split

Splits a string into an array based on a delimiter.

Basic Usage:

Example - Parse comma-separated values:

Len

Returns the length of a string or array.

Basic Usage:

Example - Conditional processing based on length:

Int / Double / String

Type conversion functions.

Basic Usage:

Example - Convert and compute:

IsMatch

Checks if a field matches a regex pattern.

Basic Usage:

Example - Conditional field extraction:

multiline_merge

Reassembles multiline log entries into a single merge record.

Basic Usage:

Arguments:

  • first_line_pattern (string, required) - Regex matching the first line of a new block. Lines not matching are continuations.

  • max_lines (int, optional, default: 128)- Maximum lines per block. Buffer is flushed when reached.

  • max_time (string, optional, default: "800ms")- Maximum time for continuations. Buffer is flushed when reached.

Example - Merge then parse with grok:

Important notes:

  • Place multiline_merge as the first statement in the rule. Subsequent statements see the merged content when a flush occurs.

  • The rule's conditions must capture both first lines and continuations, don't filter on a pattern that only matches first lines.

  • Buffers are isolated per instance. Logs from different pods. containers or files never mix.

Last updated