truncate_all
less than a minute
This function is used to truncate all string values within a specified map so that none exceed a given character limit. This function helps manage value length in telemetry data to ensure consistency and compliance with size constraints.
Syntax: truncate_all(target, limit)
- Target: A path expression pointing to map type field whose string values need to be truncated.
- Limit: An integer representing the maximum number of characters allowed for each string value. Non-string values within the map are unaffected.
Input
{
"_type": "log",
"attributes": {
"manifest": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"name\":\"nginx-deployment\",\"labels\":{\"app\":\"nginx\"}},\"spec\":{\"replicas\":3,\"selector\":{\"matchLabels\":{\"app\":\"nginx\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"nginx\"}},\"spec\":{\"containers\":[{\"name\":\"nginx\",\"image\":\"nginx:1.14.2\",\"ports\":[{\"containerPort\":80}]}]}}}"
},
"body": "Deployment issue",
"resource": {...},
"timestamp": 1733439976983
}
Statement
truncate_all(attributes, 80)
Output
{
"_type": "log",
"attributes": {
"manifest": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"name\":\"nginx-deployment"
},
"body": "Deployment issue",
"resource": {...},
"timestamp": 1733440045272
}
The string value within attributes, which exceeds 30 characters, is truncated to exactly 80 characters.