Skip to content

Add static registration of AccessLog::Instance implementations.#1609

Merged
htuch merged 11 commits intoenvoyproxy:masterfrom
mrice32:access_log_registration
Sep 12, 2017
Merged

Add static registration of AccessLog::Instance implementations.#1609
htuch merged 11 commits intoenvoyproxy:masterfrom
mrice32:access_log_registration

Conversation

@mrice32
Copy link
Copy Markdown
Member

@mrice32 mrice32 commented Sep 7, 2017

This enables custom access log implementations to be substituted in place of the existing file access log. This feature is only available in the v2 api. For v1 api users, there should be no changes. This change increments the commit hash of envoy-api to get related api changes.

The implementation follows the static registration pattern for other components relatively closely.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Looks good, some code structure questions..


// Statically registered access logs are a v2-only feature, so use the standard internal file
// access log for json config conversion.
access_log.set_name("envoy.file_access_log");
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.

We should probably have a centralized list of well known names in the Envoy namespace. I started one for metadata in source/common/config/metadata.h, but we should probably expand to cover this.

ProtobufTypes::MessagePtr message = factory->createEmptyConfigProto();
if (config.has_config()) {
MessageUtil::jsonConvert(config.config(), *message);
}
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.

This pattern is now in at least 4 places. What do you think about refactoring?

* @param config the custom configuration for this access log type.
* @param filter filter to determine whether a particular request should be logged. If no filter
* was specified in the configuration, argument will be nullptr.
* @param log_manager interface through which filesystem access logs are created.
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.

Is this the only way to plumb this for the filesystem logs? Seems like a vestigial feature for everyone else.

Copy link
Copy Markdown
Member Author

@mrice32 mrice32 Sep 8, 2017

Choose a reason for hiding this comment

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

We could do something more general, like provide an "environment" or "context" to give general access to conditionally useful variables so that this api can be expanded with new use cases (for instance, we will likely need to provide the ability to access the cluster manager for RPC logs) as is done for http filters now. We could also make the log_manager a singleton, but that seems like it would be more troublesome for each additional object.

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.

+1 I think a context is good, it leaves room for future expansion without having to modify the filter interface, which causes breaking/deprecating changes.

@mrice32
Copy link
Copy Markdown
Member Author

mrice32 commented Sep 9, 2017

Added singleton of well known names and replaced uses with references to the class, used the FactoryContext object to provide a context for the AccessLogInstanceFactory, and generalized the factory lookup and config conversion.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

looks great. small doc nit.

* @param config the custom configuration for this access log type.
* @param filter filter to determine whether a particular request should be logged. If no filter
* was specified in the configuration, argument will be nullptr.
* @param log_manager interface through which filesystem access logs are created.
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.

nit: doc out of date.

class NetworkFilterNameValues {
public:
// Client ssl auth filter
const std::string CLIENT_SSL_AUTH = "client_ssl_auth";
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.

I'm wondering for the network/HTTP names whether we want to make it that we retain existing names without a envoy. prefix for v1, but for v2 make these envoy.ratelimit etc. We could just do the prefix step during the JSON -> proto translation steps and then we have a consistent naming scheme across all filters/pluggables for v2.

@@ -0,0 +1,96 @@
#pragma once
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.

Thanks for adding this. Can you merge https://github.com/lyft/envoy/blob/master/source/common/config/metadata.h#L43 into this as well?

const std::string ROUTER = "envoy.router";

HttpFilterNameValues() {
const std::vector<std::string> prefixed_v2_names = {
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.

This thing seems fragile to me but I can't really think of a better way to do it. Can we potentially at least share this code with above via some small helper class that takes an array of strings as part of the constructor?

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.

Yeah, my bad. Should've been done that way in the first place.

mattklein123
mattklein123 previously approved these changes Sep 12, 2017
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Nice LGTM pending @htuch final look.

htuch
htuch previously approved these changes Sep 12, 2017
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Thanks for the epic cleanup on filter namespace. A very minor nit (ENVOY_ROUTER redundancy), otherwise LGTM.

route: { host_rewrite: www.google.com, cluster: service_google }
http_filters:
- name: router
- name: envoy.router
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.

Really appreciate the cleanup here! :)

throw EnvoyException(fmt::format(
"Attempted to create a conversion for a v2 name that isn't prefixed by {}", prefix));
}
v1_to_v2_names_[name.substr(prefix.size())] = name;
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.

I think this could be done a bit simpler by just prefixing on ingest, but it seems alright, and will eventually be deprecated.

// Filter namespace for built-in load balancer.
const std::string ENVOY_LB = "envoy.lb";
// Filter namespace for built-in router opaque data.
const std::string ENVOY_ROUTER = "envoy.router";
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.

I think ENVOY_ROUTER is a dupe of ROUTER above. The idea in the metadata namespace is you use the filter name as key.

Copy link
Copy Markdown
Member Author

@mrice32 mrice32 Sep 12, 2017

Choose a reason for hiding this comment

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

Does this mean that these should all just be treated as filter names and we should remove this class altogether?

@mrice32 mrice32 dismissed stale reviews from htuch and mattklein123 via 95118bb September 12, 2017 14:21
@mattklein123 mattklein123 mentioned this pull request Sep 12, 2017
@htuch htuch merged commit be01fc2 into envoyproxy:master Sep 12, 2017
@mrice32 mrice32 deleted the access_log_registration branch September 12, 2017 16:20
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: Remove the designated initializer I used in `engine_builder.cc` and instead populate `null_logger` field-by-field. Turns out this syntax is one of this parts of C++ that's _not_ the same as C.
Risk Level: Low
Testing: `bazel test //test/...`
Docs Changes: N/A
Release Notes: N/A

Signed-off-by: Cerek Hillen <chillen@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: Remove the designated initializer I used in `engine_builder.cc` and instead populate `null_logger` field-by-field. Turns out this syntax is one of this parts of C++ that's _not_ the same as C.
Risk Level: Low
Testing: `bazel test //test/...`
Docs Changes: N/A
Release Notes: N/A

Signed-off-by: Cerek Hillen <chillen@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants