Duration
Synopsis
Converts time duration strings to seconds.
Schema
- duration:
field: <ident>
target_field: <ident>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
Configuration
The following fields are used to define the processor:
Field | Required | Default | Description |
---|---|---|---|
field | Y | - | Source field containing the duration string |
target_field | N | value of field | Destination field to store the converted duration in seconds |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | Continue processing if conversion fails |
ignore_missing | N | false | Skip if source field doesn't exist |
on_failure | N | - | Error handling processors |
on_success | N | - | Success handling processors |
tag | N | - | Identifier |
Supported Formats
The processor can handle the following duration formats:
-
Go Duration Format:
- "5s" (5 seconds)
- "1m30s" (1 minute and 30 seconds)
- "2h45m" (2 hours and 45 minutes)
- "24h" (24 hours)
-
Time Format:
- "HH:MM:SS" (hours:minutes:seconds)
- "MM:SS" (minutes:seconds)
Description
Converts a string representing a time duration into a numeric value in seconds. The processor supports multiple duration formats including Go's duration syntax (e.g., "5m", "2h30m") and time notation formats (e.g., "HH:MM:SS", "MM:SS").
When using the time format (HH:MM:SS), the processor assumes that the values represent hours, minutes, and seconds respectively. For MM:SS format, the processor assumes minutes and seconds.
The processor is useful for normalizing various time duration notations into a consistent numeric format that can be used for calculations, filtering, or visualization.
Invalid duration formats will cause the processor to fail unless ignore_failure
is set to true
. Always validate input data or provide proper error handling when processing user-generated duration strings.
Examples
Basic
Go duration format... |
|
is converted to seconds: |
|
Time Format
Converting time notation... |
|
parses hours, minutes, and seconds: |
|
In-Place
Replacing the original field... |
|
converts the value in place: |
|
Error Handling
Handling potential parsing errors... |
|
continues execution: |
|