-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(splunk hec sink)!: json encoding should get message first and then parse #20297
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The Splunk HEC sink is now using the `message` meaning to retrieve the relevant value and encodes the retrieved value | ||
only. Note that if the retrieved value is `None`, an event with an empty message will be published. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ pub enum HecEvent<'a> { | |
Text(Cow<'a, str>), | ||
} | ||
|
||
/// See https://docs.splunk.com/Documentation/Splunk/9.2.1/Data/FormateventsforHTTPEventCollector#Event_data. | ||
#[derive(Serialize, Debug)] | ||
pub struct HecData<'a> { | ||
#[serde(flatten)] | ||
|
@@ -86,16 +87,21 @@ impl Encoder<Vec<HecProcessedEvent>> for HecLogsEncoder { | |
} | ||
EndpointTarget::Event => { | ||
let serializer = encoder.serializer(); | ||
let hec_event = if serializer.supports_json() { | ||
HecEvent::Json( | ||
serializer | ||
.to_json_value(event) | ||
.map_err(|error| emit!(SplunkEventEncodeError { error })) | ||
.ok()?, | ||
) | ||
let hec_event = if let Some(message) = event.as_log().get_message() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: This is expected to break all integration tests using Also, all the tests rely on the legacy namespace. I might go ahead and use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @vladimir-dd and @jszwedko for confirming before I go ahead and edit all those. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should move all other fields from LogEvent to HecData.fields otherwise we could lost some fields. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, didn't notice that we pass fields through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like I'm getting a bit turned around by this now 😵 I think I'd talked to Pavlos about only encoding the message field, but, thinking about it more now, the field in the HEC payload is actually called
I agree with @vladimir-dd that if we only encode This might be a case where we need to play around with it a bit and see how it looks like in the Splunk interface under various conditions (like Splunk HEC -> Splunk and Syslog -> Splunk). Apologies for what feels like going in circles a bit here. I'm happy to chat about this if it helps resolve it more quickly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Marking it as a draft for now. It's not urgent to get to the bottom of this given we have other priorities. |
||
if serializer.supports_json() { | ||
let message_event = Event::from(LogEvent::from(message.clone())); | ||
HecEvent::Json( | ||
serializer | ||
.to_json_value(message_event) | ||
.map_err(|error| emit!(SplunkEventEncodeError { error })) | ||
.ok()?, | ||
) | ||
} else { | ||
encoder.encode(event, &mut bytes).ok()?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗒️ Encoders call |
||
HecEvent::Text(String::from_utf8_lossy(&bytes)) | ||
} | ||
} else { | ||
encoder.encode(event, &mut bytes).ok()?; | ||
HecEvent::Text(String::from_utf8_lossy(&bytes)) | ||
HecEvent::Text("".into()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should use the same logic as above here to avoid losing information - but instead of encoding message encode the whole event(either as json, or as text)? |
||
}; | ||
|
||
let mut hec_data = HecData::new( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions:
event
field?message
defined?/event
endpoint and not for/raw
?