Skip to content

daemon/logger: remove uses of pkg/urlutil, fix fluentd validation and parsing#43476

Merged
thaJeztah merged 9 commits intomoby:masterfrom
thaJeztah:split_urlutil
Apr 11, 2022
Merged

daemon/logger: remove uses of pkg/urlutil, fix fluentd validation and parsing#43476
thaJeztah merged 9 commits intomoby:masterfrom
thaJeztah:split_urlutil

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented Apr 10, 2022

daemon/logger/gelf: remove uses of pkg/urlutil.IsTransportURL()

pkg/urlutil (despite its poorly chosen name) is not really intended as a generic utility to handle URLs, and should only be used by the builder to handle (remote) build contexts.

This patch:

  • removes a redundant use of urlutil.IsTransportURL(); code further below already checked if the given scheme (protocol) was supported.
  • renames some variables that collided with imported packages.

daemon/logger/splunk: remove uses of pkg/urlutil.IsURL()

pkg/urlutil (despite its poorly chosen name) is not really intended as a generic utility to handle URLs, and should only be used by the builder to handle (remote) build contexts.

This patch removes the use of urlutil.IsURL(), in favor of just checking if the provided scheme (protocol) is supported.

daemon/logger/syslog: remove uses of pkg/urlutil.IsTransportURL()

pkg/urlutil (despite its poorly chosen name) is not really intended as a generic utility to handle URLs, and should only be used by the builder to handle (remote) build contexts.

This patch:

  • removes a redundant use of urlutil.IsTransportURL(); instead adding some code to check if the given scheme (protocol) is supported.
  • define a defaultPort const for the default port.
  • use net.JoinHostPort() instead of string concatenating, to account for possible issues with IPv6 addresses.
  • renames a variable that collided with an imported package.

daemon/logger/fluentd: add coverage for ValidateLogOpt(), parseAddress()

This exposed a bug where host is ignored on some valid cases (to be fixed).

daemon/logger/fluentd: rename var that collided with import

daemon/logger/fluentd: make error-handling less DRY

daemon/logger/fluentd: validate path element

fix some missing validation: the driver was silently ignoring path elements in some cases, and expecting a host (not an URL), and for unix sockets did not validate if a path was specified.

For the latter case, we should have a fix in the upstream driver, as it uses an empty path as default path for the socket (defaultSocketPath), and performs no validation.

daemon/logger/fluentd: fix missing host, remove urlutil.IsTransportURL()

pkg/urlutil (despite its poorly chosen name) is not really intended as a generic utility to handle URLs, and should only be used by the builder to handle (remote) build contexts.

This patch:

  • fix some cases where the host was ignored for valid addresses.
  • removes a redundant use of urlutil.IsTransportURL(); instead adding code to check if the given scheme (protocol) is supported.
  • improve port validation for out of range ports.
  • fix some missing validation: the driver was silently ignoring path elements, but expected a host (not an URL)

daemon/logger/fluentd: remove udp, tcp+tls, unixgram, add tls scheme

unix and unixgram were added in cb176c8 (#26088), but at the time, the driver only supported "tcp" and "unix": see vendor/src/github.com/fluent/fluent-logger-golang/fluent/fluent.go#L243-L2610

support for tls was added in github.com/fluent/fluent-logger-golang v1.8.0, which was vendored in e24d61b (#42979).

the list of currently supported schemes by the driver is: tcp, tls and unix: see vendor/github.com/fluent/fluent-logger-golang/fluent/fluent.go#L435-L463

@thaJeztah thaJeztah added area/logging status/2-code-review area/daemon Core Engine kind/bugfix PR's that fix bugs kind/refactor PR's that refactor, or clean-up code labels Apr 10, 2022
@thaJeztah thaJeztah added this to the 22.04.0 milestone Apr 10, 2022
@thaJeztah thaJeztah force-pushed the split_urlutil branch 2 times, most recently from 743a528 to 305c087 Compare April 10, 2022 15:09
@thaJeztah

This comment was marked as outdated.

Copy link
Copy Markdown
Member

@samuelkarp samuelkarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits/suggestions, but LGTM otherwise.

pkg/urlutil (despite its poorly chosen name) is not really intended as a generic
utility to handle URLs, and should only be used by the builder to handle (remote)
build contexts.

This patch:

- removes a redundant use of urlutil.IsTransportURL(); code further below already
  checked if the given scheme (protocol) was supported.
- renames some variables that collided with imported packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
pkg/urlutil (despite its poorly chosen name) is not really intended as a generic
utility to handle URLs, and should only be used by the builder to handle (remote)
build contexts.

This patch removes the use of urlutil.IsURL(), in favor of just checking if the
provided scheme (protocol) is supported.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
pkg/urlutil (despite its poorly chosen name) is not really intended as a generic
utility to handle URLs, and should only be used by the builder to handle (remote)
build contexts.

This patch:

- removes a redundant use of urlutil.IsTransportURL(); instead adding some code
  to check if the given scheme (protocol) is supported.
- define a `defaultPort` const for the default port.
- use `net.JoinHostPort()` instead of string concatenating, to account for possible
  issues with IPv6 addresses.
- renames a variable that collided with an imported package.
- improves test coverage, and moves an integration test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This exposed a bug where host is ignored on some valid cases (to be fixed).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
fix some missing validation: the driver was silently ignoring path elements
in some cases, and expecting a host (not an URL), and for unix sockets did
not validate if a path was specified.

For the latter case, we should have a fix in the upstream driver, as it
uses an empty path as default path for the socket (`defaultSocketPath`),
and performs no validation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
pkg/urlutil (despite its poorly chosen name) is not really intended as a generic
utility to handle URLs, and should only be used by the builder to handle (remote)
build contexts.

This patch:

- fix some cases where the host was ignored for valid addresses.
- removes a redundant use of urlutil.IsTransportURL(); instead adding code to
  check if the given scheme (protocol) is supported.
- improve port validation for out of range ports.
- fix some missing validation: the driver was silently ignoring path elements,
  but expected a host (not an URL)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
unix and unixgram were added in cb176c8, but at
the time, the driver only supported "tcp" and "unix":
https://github.com/moby/moby/blob/cb176c848e0731f77fa48b4e1a90ae74d1f2deae/vendor/src/github.com/fluent/fluent-logger-golang/fluent/fluent.go#L243-L261

support for tls was added in github.com/fluent/fluent-logger-golang v1.8.0, which
was vendored in e24d61b.

the list of currently supported schemes by the driver is: tcp, tls and unix:
https://github.com/moby/moby/blob/5179299b98a37ac2ba6eb8aefe8bf211f33f7dcc/vendor/github.com/fluent/fluent-logger-golang/fluent/fluent.go#L435-L463

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link
Copy Markdown
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return nil, fmt.Errorf("gelf-address should be in form proto://address, got %v", address)
}
url, err := url.Parse(address)
addr, err := url.Parse(address)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, are there cases where url.Parse might infer or assign a scheme that we didn't intend? The check in urlutil.IsTransportURL is prefix-based, so should be pretty performant (and feels safer than trusting url.Parse, IMO).

I guess I'd be more worried about it inferring file:// than udp:// or tcp://, so this is probably fine. 🙈

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be fine; couple of lines down we check if the scheme is supported;

if addr.Scheme != "udp" && addr.Scheme != "tcp" {

I can't come up with cases where it could invalidate a valid address (at most one that's specified without scheme, but that should produce an error message, helping the user to find the problem)

@thaJeztah
Copy link
Copy Markdown
Member Author

Thanks for review! I'll bring this one in and rebase #43477 (moving it out of draft)

@thaJeztah thaJeztah merged commit 6f8bc7e into moby:master Apr 11, 2022
@thaJeztah thaJeztah deleted the split_urlutil branch April 11, 2022 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/daemon Core Engine area/logging kind/bugfix PR's that fix bugs kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants