1
- use lookup:: lookup_v2:: OptionalValuePath ;
1
+ use lookup:: lookup_v2:: { OptionalTargetPath , OptionalValuePath } ;
2
2
use lookup:: { OwnedTargetPath , OwnedValuePath } ;
3
3
use once_cell:: sync:: { Lazy , OnceCell } ;
4
4
use vector_config:: configurable_component;
5
+ use vrl:: path:: PathPrefix ;
5
6
6
7
static LOG_SCHEMA : OnceCell < LogSchema > = OnceCell :: new ( ) ;
7
8
static LOG_SCHEMA_DEFAULT : Lazy < LogSchema > = Lazy :: new ( LogSchema :: default) ;
@@ -49,24 +50,24 @@ pub struct LogSchema {
49
50
///
50
51
/// This would be the field that holds the raw message, such as a raw log line.
51
52
#[ serde( default = "LogSchema::default_message_key" ) ]
52
- message_key : OptionalValuePath ,
53
+ message_key : OptionalTargetPath ,
53
54
54
55
/// The name of the event field to treat as the event timestamp.
55
56
#[ serde( default = "LogSchema::default_timestamp_key" ) ]
56
- timestamp_key : OptionalValuePath ,
57
+ timestamp_key : OptionalTargetPath ,
57
58
58
59
/// The name of the event field to treat as the host which sent the message.
59
60
///
60
61
/// This field will generally represent a real host, or container, that generated the message,
61
62
/// but is somewhat source-dependent.
62
63
#[ serde( default = "LogSchema::default_host_key" ) ]
63
- host_key : OptionalValuePath ,
64
+ host_key : OptionalTargetPath ,
64
65
65
66
/// The name of the event field to set the source identifier in.
66
67
///
67
68
/// This field will be set by the Vector source that the event was created in.
68
69
#[ serde( default = "LogSchema::default_source_type_key" ) ]
69
- source_type_key : OptionalValuePath ,
70
+ source_type_key : OptionalTargetPath ,
70
71
71
72
/// The name of the event field to set the event metadata in.
72
73
///
@@ -89,28 +90,28 @@ impl Default for LogSchema {
89
90
}
90
91
91
92
impl LogSchema {
92
- fn default_message_key ( ) -> OptionalValuePath {
93
- OptionalValuePath :: new ( MESSAGE )
93
+ fn default_message_key ( ) -> OptionalTargetPath {
94
+ OptionalTargetPath :: event ( MESSAGE )
94
95
}
95
96
96
- fn default_timestamp_key ( ) -> OptionalValuePath {
97
- OptionalValuePath :: new ( TIMESTAMP )
97
+ fn default_timestamp_key ( ) -> OptionalTargetPath {
98
+ OptionalTargetPath :: event ( TIMESTAMP )
98
99
}
99
100
100
- fn default_host_key ( ) -> OptionalValuePath {
101
- OptionalValuePath :: new ( HOST )
101
+ fn default_host_key ( ) -> OptionalTargetPath {
102
+ OptionalTargetPath :: event ( HOST )
102
103
}
103
104
104
- fn default_source_type_key ( ) -> OptionalValuePath {
105
- OptionalValuePath :: new ( SOURCE_TYPE )
105
+ fn default_source_type_key ( ) -> OptionalTargetPath {
106
+ OptionalTargetPath :: event ( SOURCE_TYPE )
106
107
}
107
108
108
109
fn default_metadata_key ( ) -> OptionalValuePath {
109
110
OptionalValuePath :: new ( METADATA )
110
111
}
111
112
112
113
pub fn message_key ( & self ) -> Option < & OwnedValuePath > {
113
- self . message_key . path . as_ref ( )
114
+ self . message_key . path . as_ref ( ) . map ( |key| & key . path )
114
115
}
115
116
116
117
/// Returns an `OwnedTargetPath` of the message key.
@@ -119,39 +120,59 @@ impl LogSchema {
119
120
/// This should only be used where the result will either be cached,
120
121
/// or performance isn't critical, since this requires parsing / memory allocation.
121
122
pub fn owned_message_path ( & self ) -> OwnedTargetPath {
122
- OwnedTargetPath :: event ( self . message_key . clone ( ) . path . expect ( "valid message key" ) )
123
+ self . message_key
124
+ . path
125
+ . as_ref ( )
126
+ . expect ( "valid message key" )
127
+ . clone ( )
123
128
}
124
129
125
130
pub fn timestamp_key ( & self ) -> Option < & OwnedValuePath > {
126
- self . timestamp_key . path . as_ref ( )
131
+ self . timestamp_key . as_ref ( ) . map ( |key| & key . path )
127
132
}
128
133
129
134
pub fn host_key ( & self ) -> Option < & OwnedValuePath > {
130
- self . host_key . path . as_ref ( )
135
+ self . host_key . as_ref ( ) . map ( |key| & key . path )
131
136
}
132
137
133
138
pub fn source_type_key ( & self ) -> Option < & OwnedValuePath > {
134
- self . source_type_key . path . as_ref ( )
139
+ self . source_type_key . as_ref ( ) . map ( |key| & key . path )
135
140
}
136
141
137
142
pub fn metadata_key ( & self ) -> Option < & OwnedValuePath > {
138
143
self . metadata_key . path . as_ref ( )
139
144
}
140
145
146
+ pub fn message_key_target_path ( & self ) -> Option < & OwnedTargetPath > {
147
+ self . message_key . as_ref ( )
148
+ }
149
+
150
+ pub fn timestamp_key_target_path ( & self ) -> Option < & OwnedTargetPath > {
151
+ self . timestamp_key . as_ref ( )
152
+ }
153
+
154
+ pub fn host_key_target_path ( & self ) -> Option < & OwnedTargetPath > {
155
+ self . host_key . as_ref ( )
156
+ }
157
+
158
+ pub fn source_type_key_target_path ( & self ) -> Option < & OwnedTargetPath > {
159
+ self . source_type_key . as_ref ( )
160
+ }
161
+
141
162
pub fn set_message_key ( & mut self , path : Option < OwnedValuePath > ) {
142
- self . message_key = OptionalValuePath { path } ;
163
+ self . message_key = OptionalTargetPath :: from ( PathPrefix :: Event , path) ;
143
164
}
144
165
145
- pub fn set_timestamp_key ( & mut self , v : Option < OwnedValuePath > ) {
146
- self . timestamp_key = OptionalValuePath { path : v } ;
166
+ pub fn set_timestamp_key ( & mut self , path : Option < OwnedValuePath > ) {
167
+ self . timestamp_key = OptionalTargetPath :: from ( PathPrefix :: Event , path ) ;
147
168
}
148
169
149
170
pub fn set_host_key ( & mut self , path : Option < OwnedValuePath > ) {
150
- self . host_key = OptionalValuePath { path } ;
171
+ self . host_key = OptionalTargetPath :: from ( PathPrefix :: Event , path) ;
151
172
}
152
173
153
174
pub fn set_source_type_key ( & mut self , path : Option < OwnedValuePath > ) {
154
- self . source_type_key = OptionalValuePath { path } ;
175
+ self . source_type_key = OptionalTargetPath :: from ( PathPrefix :: Event , path) ;
155
176
}
156
177
157
178
pub fn set_metadata_key ( & mut self , path : Option < OwnedValuePath > ) {
0 commit comments