Fix reading config files starting with http:#9275
Fix reading config files starting with http:#9275akrantz01 merged 11 commits intoinfluxdata:masterfrom
Conversation
|
Thanks so much for the pull request! |
|
!signed-cla |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
srebhan
left a comment
There was a problem hiding this comment.
No. This means files take precedence over URLs even though you specified a valid (remote) URI. You can achieve the same with specifying file://http:whateverfileyouneed.
|
Thanks for the PR! I don't think this change is unreasonable. Hipska has a good point about handling the error messages, so we need to pay attention to that. Probably the best way to decide if we should parse it as a file or a url is to look for a character sequence that clearly identifies it. Parsing files as urls will still give you a url, which is what caused the original problem. This PR does in fact resolve that problem, it just comes at the cost of checking the disk for matching files first.. Which honestly isn't really a big deal. If we wanted to stick closely to the intent of the user configuring the plugin, we could match against the regex |
|
@ssoroka well my fear is that you, with the change applied, cannot specify a URL if a file with that name exists. Let's make an example. Say a) you want to access a file named With the current implementation you can achieve this by specifying With the change you specify Sorry @akrantz01 if my comment was too harsh, but I think this kind of implicit behavior is cumbersome and might lead to unintended effects. |
|
Hmmm and after reading the code again I see that my example is wrong. :-) So currently specifying The team probably should discuss this as @Hipska said, but my preference would be to implement the handling of the func loadConfig(config string) ([]byte, error) {
if strings.HasPrefix(config, "file://") {
return ioutil.ReadFile(strings.TrimPrefix(config, "file://"))
}
u, err := url.Parse(config)
if err != nil {
return nil, err
}
switch u.Scheme {
case "https", "http":
return fetchConfig(u)
}
// If it isn't known scheme, try it as a file.
return ioutil.ReadFile(config)
} |
|
Isn't |
|
To the best of my knowledge, I don't think you can create files with forward slashes in the name on any platform, so I think it'd be best to go with @ssoroka's suggestion. It wouldn't require any changes from the user and would still handle actual URLs properly. Regarding @Hipska's point, we could still add a case for |
|
Actually, if we wanted to support |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
Hipska
left a comment
There was a problem hiding this comment.
I would do something like this: (pseudo code)
if u.Scheme in ["https", "http"] and u.Host not empty {
return fetchConfig(u)
}
|
We will get problems with parameters like |
|
@ssoroka and I decided that it would be simplest just to use the regex before parsing the URL, since then the implementation isn't dependent on the internals of |
config/config.go
Outdated
| default: | ||
| // If it isn't a https scheme, try it as a file |
There was a problem hiding this comment.
You can leave this one out as it does nothing and move the comment next to the last return. Just a minor comment though.
There was a problem hiding this comment.
I think the linter will complain then?
srebhan
left a comment
There was a problem hiding this comment.
@akrantz01 thanks for keep going with this persistent issue.
My only (very minor) comment is to remove the default clause, but this is not a blocker.
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
ssoroka
left a comment
There was a problem hiding this comment.
Looks good. left a suggestion on erroring if the requested scheme doesn't exist.
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
resolves #9218
Fixed an error where telegraf attempted to fetch files starting with
http:orhttps:over HTTP/S rather than read them from the filesystem.