@@ -5,16 +5,18 @@ use codecs::{
5
5
StreamDecodingError ,
6
6
} ;
7
7
use futures:: StreamExt ;
8
- use lookup:: { lookup_v2:: BorrowedSegment , owned_value_path, path} ;
8
+ use lookup:: { lookup_v2:: OptionalValuePath , owned_value_path, path, OwnedValuePath } ;
9
9
use snafu:: { ResultExt , Snafu } ;
10
10
use tokio_util:: codec:: FramedRead ;
11
11
use value:: Kind ;
12
12
use vector_common:: internal_event:: {
13
13
ByteSize , BytesReceived , CountByteSize , InternalEventHandle as _, Protocol , Registered ,
14
14
} ;
15
15
use vector_config:: { configurable_component, NamedComponent } ;
16
- use vector_core:: config:: { LegacyKey , LogNamespace } ;
17
- use vector_core:: EstimatedJsonEncodedSizeOf ;
16
+ use vector_core:: {
17
+ config:: { LegacyKey , LogNamespace } ,
18
+ EstimatedJsonEncodedSizeOf ,
19
+ } ;
18
20
19
21
use crate :: {
20
22
codecs:: { Decoder , DecodingConfig } ,
@@ -116,7 +118,7 @@ pub struct RedisSourceConfig {
116
118
/// The value will be the Redis key that the event was read from.
117
119
///
118
120
/// By default, this is not set and the field will not be automatically added.
119
- redis_key : Option < String > ,
121
+ redis_key : Option < OptionalValuePath > ,
120
122
121
123
#[ configurable( derived) ]
122
124
#[ serde( default = "default_framing_message_based" ) ]
@@ -158,6 +160,7 @@ impl SourceConfig for RedisSourceConfig {
158
160
if self . key . is_empty ( ) {
159
161
return Err ( "`key` cannot be empty." . into ( ) ) ;
160
162
}
163
+ let redis_key = self . redis_key . clone ( ) . and_then ( |k| k. path ) ;
161
164
162
165
let client = redis:: Client :: open ( self . url . as_str ( ) ) . context ( ClientSnafu { } ) ?;
163
166
let connection_info = ConnectionInfo :: from ( client. get_connection_info ( ) ) ;
@@ -173,7 +176,7 @@ impl SourceConfig for RedisSourceConfig {
173
176
bytes_received : bytes_received. clone ( ) ,
174
177
events_received : events_received. clone ( ) ,
175
178
key : self . key . clone ( ) ,
176
- redis_key : self . redis_key . clone ( ) ,
179
+ redis_key,
177
180
decoder,
178
181
cx,
179
182
log_namespace,
@@ -193,8 +196,8 @@ impl SourceConfig for RedisSourceConfig {
193
196
194
197
let redis_key_path = self
195
198
. redis_key
196
- . as_ref ( )
197
- . map ( |x| owned_value_path ! ( x ) )
199
+ . clone ( )
200
+ . and_then ( |k| k . path )
198
201
. map ( LegacyKey :: InsertIfEmpty ) ;
199
202
200
203
let schema_definition = self
@@ -222,7 +225,7 @@ pub(self) struct InputHandler {
222
225
pub bytes_received : Registered < BytesReceived > ,
223
226
pub events_received : Registered < EventsReceived > ,
224
227
pub key : String ,
225
- pub redis_key : Option < String > ,
228
+ pub redis_key : Option < OwnedValuePath > ,
226
229
pub decoder : Decoder ,
227
230
pub log_namespace : LogNamespace ,
228
231
pub cx : SourceContext ,
@@ -257,15 +260,10 @@ impl InputHandler {
257
260
now,
258
261
) ;
259
262
260
- let redis_key_path = self
261
- . redis_key
262
- . as_deref ( )
263
- . map ( |x| [ BorrowedSegment :: from ( x) ] ) ;
264
-
265
263
self . log_namespace . insert_source_metadata (
266
264
RedisSourceConfig :: NAME ,
267
265
log,
268
- redis_key_path . as_ref ( ) . map ( LegacyKey :: InsertIfEmpty ) ,
266
+ self . redis_key . as_ref ( ) . map ( LegacyKey :: InsertIfEmpty ) ,
269
267
path ! ( "key" ) ,
270
268
self . key . as_str ( ) ,
271
269
) ;
@@ -307,10 +305,13 @@ mod integration_test {
307
305
use redis:: AsyncCommands ;
308
306
309
307
use super :: * ;
310
- use crate :: config:: log_schema;
311
- use crate :: test_util:: components:: { run_and_assert_source_compliance_n, SOURCE_TAGS } ;
312
308
use crate :: {
313
- test_util:: { collect_n, random_string} ,
309
+ config:: log_schema,
310
+ test_util:: {
311
+ collect_n,
312
+ components:: { run_and_assert_source_compliance_n, SOURCE_TAGS } ,
313
+ random_string,
314
+ } ,
314
315
SourceSender ,
315
316
} ;
316
317
@@ -369,7 +370,7 @@ mod integration_test {
369
370
} ) ,
370
371
url : REDIS_SERVER . to_owned ( ) ,
371
372
key : key. clone ( ) ,
372
- redis_key : Some ( "remapped_key" . into ( ) ) ,
373
+ redis_key : Some ( OptionalValuePath :: from ( owned_value_path ! ( "remapped_key" ) ) ) ,
373
374
framing : default_framing_message_based ( ) ,
374
375
decoding : default_decoding ( ) ,
375
376
log_namespace : Some ( true ) ,
0 commit comments