-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
enhancement(http source): URL path configuration flexibility, path also exposed as a new field #6626
enhancement(http source): URL path configuration flexibility, path also exposed as a new field #6626
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.
Nice work @prognant !
I left one comment about configuration, but otherwise I think this looks good. I appreciate the comprehensive tests as well as support for url_path
and strict_path
config options.
In my opinion, we should expand this support to heroku_logs
and any other HTTP-based sources for consistency. I think this would include: prometheus_remote_write
, splunk_hec
, aws_kinesis_firehose
. We can split that off into a separate issue though.
src/sources/http.rs
Outdated
@@ -20,41 +17,47 @@ use tokio_util::codec::Decoder; | |||
use warp::http::{HeaderMap, HeaderValue, StatusCode}; | |||
|
|||
#[derive(Deserialize, Serialize, Debug, Clone)] | |||
#[serde(default)] |
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 think this (plus the Default
trait implementation below) will have the undesired effect of not requiring the user to specify the address
field in their config. We currently require this field.
On the other hand, I could see trying to choose a sensible default for it like you did here. I might suggest something other than :80
as that is likely to be blocked.
For now, I'd recommend just replacing the #[serde(default)]
s below and removing it from the struct. You can provide a default value for the field with something like:
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 think not changing the default behaviour should be favoured when possible, I followed your suggestion to keep the current mandatory behaviour for the address
setting and rely on function to provided other default values.
@@ -107,8 +107,38 @@ components: sources: http: { | |||
} | |||
} | |||
} | |||
url_path: { |
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.
What would you think of just calling this path
? I think, in the context it appears, it'll be pretty clear it refers to an HTTP URL path.
e3c0538
to
7527840
Compare
Thanks for the review, I addressed your comments and created a follow-up issue to leverage this change in other relevant sources.
|
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.
Thanks @prognant ! I noticed one more thing, but otherwise this looks good to me.
@@ -30,6 +30,12 @@ pub struct SimpleHttpConfig { | |||
query_parameters: Vec<String>, | |||
tls: Option<TlsConfig>, | |||
auth: Option<HttpSourceAuthConfig>, | |||
#[serde(default = "crate::serde::default_true")] |
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.
TIL we have these helpers
src/sources/http.rs
Outdated
.await; | ||
|
||
assert_eq!( | ||
405, |
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 realized that 405, "Method not allowed", is a bit of an odd error for this condition. I would have expected a 404.
This looks like a bug in warp: seanmonstar/warp#77
I think you could work around this by, instead of relying on warp's error handling with path::end
, just accepting all requests and then, in the handler itself, when strict_match
is true, check that the path matches and return a 404 manually if not.
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.
The code looks good, except for the HTTP response code issue identified by @jszwedko. Otherwise, I just have a few wording suggestions for the docs.
for event in events.iter_mut() { | ||
event | ||
.as_mut_log() | ||
.insert(key, Value::from(path.to_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.
FWIW this should be equivalent to:
.insert(key, Value::from(path.to_string())); | |
.insert(key, path.to_string().into()); |
(Not really a suggestion to change it, just a note)
…source Signed-off-by: Sam Giles <sam.giles@citymapper.com>
Allow the HTTP source to use a customised path (instead of / previously). The URL path is also extracted into the "path" key (can be changed by configuration). Signed-off-by: prognant <pierre.rognant@datadoghq.com>
Signed-off-by: prognant <pierre.rognant@datadoghq.com>
Signed-off-by: prognant <pierre.rognant@datadoghq.com>
Co-authored-by: Bruce Guenter <bruce@timber.io> Signed-off-by: prognant <pierre.rognant@datadoghq.com>
Signed-off-by: prognant <pierre.rognant@datadoghq.com>
a9acf69
to
9a8556e
Compare
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.
Nice work!
src/sources/util/http.rs
Outdated
debug!(message = "Path rejected."); | ||
Err(warp::reject::custom( | ||
ErrorMessage::new(StatusCode::NOT_FOUND, | ||
StatusCode::NOT_FOUND.canonical_reason().unwrap().to_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.
Could we use unwrap_or_default()
here? I realize that this particular code always has a canonical reason, but unwrap()
s tend to jump out.
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.
That sounds safer. In this case I think we may directly go for "Not found".to_string()
WDYT ?
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'm also fine with 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.
It looks like there is also a warp::reject::not_found()
you could use instead of warp::reject::custom()
:
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 tried to used warp::reject::not_found()
but it seems we hit the same issue you shared earlier (seanmonstar/warp#77) that why I moved forward reusing the ErrorMessage
struct that already has proper handling code to propagate a http return code.
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.
Aha, gotcha, thanks for the note 👍
Signed-off-by: prognant <pierre.rognant@datadoghq.com>
Nice work! |
Closes #5112
Add three options to the http source:
url_path
: the path where log event should be posted (default: /)path_key
: the name of the key used to export the path for each log even (default: path)strict_path
: whether strict path should be enforce, if true only event send to the exact url_path will be accepted, if false log sent to a path that start with the value of url_path will be acceptedFor example:
Will accept events posted to "/events/1234" and "/events/5678".
Outside the http source there is no behaviour change.
Open question: should we accept all URLs for the
heroku_logs
source as it would allow a user to send logs from multiple app to the same source.