-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathremap.cue
228 lines (215 loc) · 6.5 KB
/
remap.cue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package metadata
#Remap: {
#Characteristic: {
anchor: name
enum?: #Enum
name: string
title: string
description: string
}
#Characteristics: [Name=string]: #Characteristic & {
name: Name
}
#Example: {
title: string
input?: #Event
source: string
raises?: {
compiletime?: string
runtime?: string
}
if raises == _|_ {
return?: _
output?: #Event
}
if raises != _|_ {
diff?: string
}
notes?: [string, ...string]
warnings?: [string, ...string]
}
#Type: "any" | "array" | "boolean" | "float" | "integer" | "object" | "null" | "path" | "string" | "regex" | "timestamp"
concepts: _
description: string
errors: _
examples: [#Example, ...#Example]
expressions: _
features: _
functions: _
literals: _
principles: _
syntax: _
}
remap: #Remap & {
description: #"""
**Vector Remap Language** (VRL) is an [expression-oriented](\#(urls.expression_oriented_language)) language
designed for transforming obervability data (logs and metrics) in a [safe](\#(urls.vrl_safety)) and
[performant](\#(urls.vrl_performance)) manner. It features a simple [syntax](\#(urls.vrl_expressions)) and a
rich set of built-in [functions](\#(urls.vrl_functions)) tailored specifically to observability use cases.
You can use VRL in Vector via the [`remap` transform](\#(urls.vector_remap_transform)), and for a more in-depth
picture, see the [announcement blog post](\#(urls.vrl_announcement)).
"""#
examples: [
{
title: "Parse Syslog logs"
input: log: message: "<102>1 2020-12-22T15:22:31.111Z vector-user.biz su 2666 ID389 - Something went wrong"
source: """
structured = parse_syslog!(.message)
. = merge(., structured)
"""
output: log: {
appname: "su"
facility: "ntp"
hostname: "vector-user.biz"
message: "Something went wrong"
msgid: "ID389"
procid: 2666
severity: "info"
timestamp: "2020-12-22T15:22:31.111Z"
}
notes: [
"Attributes are coerced into their proper types, including `timestamp`.",
]
},
{
title: "Parse key/value (logfmt) logs"
input: log: message: "@timestamp=\"Sun Jan 10 16:47:39 EST 2021\" level=info msg=\"Stopping all fetchers\" tag#production=stopping_fetchers id=ConsumerFetcherManager-1382721708341 module=kafka.consumer.ConsumerFetcherManager"
source: """
structured = parse_key_value!(.message)
. = merge(., structured)
"""
output: log: {
"@timestamp": "Sun Jan 10 16:47:39 EST 2021"
level: "info"
msg: "Stopping all fetchers"
"tag#production": "stopping_fetchers"
id: "ConsumerFetcherManager-1382721708341"
module: "kafka.consumer.ConsumerFetcherManager"
}
warnings: [
"All attributes are strings and will require manual type coercing.",
]
},
{
title: "Parse custom logs"
input: log: message: #"2021/01/20 06:39:15 [error] 17755#17755: *3569904 open() "/usr/share/nginx/html/test.php" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /test.php HTTP/1.1", host: "yyy.yyy.yyy.yyy""#
source: #"""
structured = parse_regex!(.message, /^(?P<timestamp>\d+/\d+/\d+ \d+:\d+:\d+) \[(?P<severity>\w+)\] (?P<pid>\d+)#(?P<tid>\d+):(?: \*(?P<connid>\d+))? (?P<message>.*)$/)
. = merge(., structured)
# Coerce parsed fields
.timestamp = parse_timestamp(.timestamp, "%Y/%m/%d %H:%M:%S") ?? now()
.pid = to_int(.pid)
.tid = to_int(.tid)
# Extract structured data
message_parts = split(.message, ", ", limit: 2)
structured = parse_key_value(message_parts[1], key_value_delimiter: ":", field_delimiter: ",") ?? {}
.message = message_parts[0]
. = merge(., structured)
"""#
output: log: {
timestamp: "2021/01/20 06:39:15"
severity: "error"
pid: "17755"
tid: "17755"
connid: "3569904"
message: #"open() "/usr/share/nginx/html/test.php" failed (2: No such file or directory)"#
client: "xxx.xxx.xxx.xxx"
server: "localhost"
request: "GET /test.php HTTP/1.1"
host: "yyy.yyy.yyy.yyy"
}
},
{
title: "Multiple parsing strategies"
input: log: message: "<102>1 2020-12-22T15:22:31.111Z vector-user.biz su 2666 ID389 - Something went wrong"
source: #"""
structured =
parse_syslog(.message) ??
parse_common_log(.message) ??
parse_regex!(.message, /^(?P<timestamp>\d+/\d+/\d+ \d+:\d+:\d+) \[(?P<severity>\w+)\] (?P<pid>\d+)#(?P<tid>\d+):(?: \*(?P<connid>\d+))? (?P<message>.*)$/)
. = merge(., structured)
"""#
output: log: {
appname: "su"
facility: "ntp"
hostname: "vector-user.biz"
message: "Something went wrong"
msgid: "ID389"
procid: 2666
severity: "info"
timestamp: "2020-12-22 15:22:31.111 UTC"
}
},
{
title: "Modify metric tags"
input: metric: {
kind: "incremental"
name: "user_login_total"
counter: {
value: 102.0
}
tags: {
host: "my.host.com"
instance_id: "abcd1234"
email: "vic@vector.dev"
}
}
source: #"""
.environment = get_env_var!("ENV") # add
.hostname = del(.host) # rename
del(.email)
"""#
output: metric: {
kind: "incremental"
name: "user_login_total"
counter: {
value: 102.0
}
tags: {
environment: "production"
hostname: "my.host.com"
instance_id: "abcd1234"
}
}
},
{
title: "Invalid argument type"
input: log: not_a_string: 1
source: """
upcase(.not_a_string)
"""
raises: compiletime: """
error: invalid argument type
┌─ :1:1
│
1 │ upcase(.not_a_string)
│ ^^^^^^^^^^^^^
│ │
│ this expression resolves to unknown type
│ but the parameter "value" expects the exact type "string"
│
= see language documentation at: https://vector.dev/docs/reference/vrl/
"""
},
{
title: "Unhandled error"
input: log: message: "key1=value1 key2=value2"
source: """
structured = parse_key_value(.message)
"""
raises: compiletime: """
error: unhandled error
┌─ :1:1
│
1 │ structured = parse_key_value(.message)
│ ^^^^^^^^^^
│ │
│ expression can result in runtime error
│ handle the error case to ensure runtime success
│
= see error handling documentation at: https://vector.dev/docs/reference/vrl/errors/
= see language documentation at: https://vector.dev/docs/reference/vrl/
"""
},
]
}