-
Notifications
You must be signed in to change notification settings - Fork 1.9k
chore(splunk_hec source): Refactor to support custom extractors #23803
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
base: master
Are you sure you want to change the base?
Conversation
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.
I approve of this approach and left some comments for cleanups.
src/sources/splunk_hec/mod.rs
Outdated
} | ||
|
||
pub struct RequestMeta { | ||
token: Option<String>, |
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.
I notice the type of this changed from Arc<str>
to String
. What motivated that?
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.
Initially, the token is retrieved as an Option<String>
. It is converted to an Arc<str>
because this is the type expected by set_splunk_hec_token
, but now we want to also make it available to the Extractor. I opted to keep the Option<String>
type here because there is no explicit reason to use an Arc
for that so it sounded more natural to keep a more "basic" type. What do you think?
src/sources/splunk_hec/mod.rs
Outdated
), | ||
], | ||
token: f.meta.token.clone().map(Into::into), | ||
extractors: E::new(f.meta, f.log_namespace), |
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.
Could this be moved into EventIteratorGenerator
instead of new
being called here? How far up the call chain could that go?
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.
Done in 8f0d2d0, lmk if that looks better
src/sources/splunk_hec/mod.rs
Outdated
/// handle to EventsReceived registry | ||
events_received: Registered<EventsReceived>, | ||
/// Whether to store the HEC token in the log event metadata | ||
store_hec_token: bool, |
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.
Could this flag eventually be expressed as an optional extractor? I'd call it out of scope for this PR but something to think about.
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.
done ✅ 8616be0
Summary
This PR modifies the internal Splunk HEC source so that it can be extended with a custom set of extractors. It does not change the config or the behavior of the default implementation of the source.
Detailed explanation
Extractor
was created and added as a generic parameter toSplunkSource
DefaultExtractor
s used in theEventIterator
were grouped under a singleDefaultExtractor
type implementingExtractor
and provided as the default type for the splunk source generic (the originalDefaultExtractor
type was renamedMetaExtractor
)Extractor
trait provides a constructor which is called when instantiating theEventIterator
, passing aRequestMeta
object containing information about the request being processed (splunk token, remote address)SplunkConfig
into alisten
method so that the SplunkSource can be easily initialized in a different contextSplunkSource
impl which did not depend on the SplunkSource struct (options
,required_channel
,lenient_json_content_type_check
) were moved to plain functions to avoid the need for calling them withSplunkSource::<DefaultExtractor>::options()
Vector configuration
How did you test this PR?
Change Type
Is this a breaking change?
Does this PR include user facing changes?
no-changelog
label to this PR.References
Notes
@vectordotdev/vector
to reach out to us regarding this PR.pre-push
hook, please see this template.make fmt
make check-clippy
(if there are failures it's possible some of them can be fixed withmake clippy-fix
)make test
git merge origin master
andgit push
.Cargo.lock
), pleaserun
make build-licenses
to regenerate the license inventory and commit the changes (if any). More details here.