Skip to content
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

matching: add support for generic inputs and add environment variable input #15410

Merged
merged 16 commits into from
Apr 1, 2021

Conversation

snowp
Copy link
Contributor

@snowp snowp commented Mar 10, 2021

Adds support for a "generic input" extension point that allows specifying inputs that are not dependent on protocol data.

Adds an environment variable generic input that allows matching on the value of an environment variable.

Risk Level: Medium
Testing: UTs for extension and generic input creation
Docs Changes: n/a
Release Notes:
Platform Specific Features:
Fixes #14781

Signed-off-by: Snow Pettersen <[email protected]>
Signed-off-by: Snow Pettersen <[email protected]>
Signed-off-by: Snow Pettersen <[email protected]>
Signed-off-by: Snow Pettersen <[email protected]>
@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
API shepherd assignee is @lizan
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #15410 was opened by snowp.

see: more, trace.

Signed-off-by: Snow Pettersen <[email protected]>
// [#extension: envoy.matching.generic_inputs.environment]

// Reads an environment variable to provide an input for matching.
message Environment {
Copy link
Contributor

Choose a reason for hiding this comment

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

Environment sounds ambiguous, something more descriptive, perhaps EnvironmentVariable, would be clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea agreed, will update

@dmitri-d
Copy link
Contributor

Could you add some docs/examples demonstrating how this DataInput is configured/used?

Signed-off-by: Snow Pettersen <[email protected]>
@snowp
Copy link
Contributor Author

snowp commented Mar 11, 2021

@dmitri-d I think I would want this to be covered by docs just as an extension of the match API, so just I figured I'd just update the docs that will be added in #14864 (either in this PR or follow up, depending on merge order)

explicit Input(absl::string_view name) {
// We read the env variable at construction time to avoid repeat lookups.
// This assumes that the environment remains stable during the process lifetime.
auto* value = getenv(name.data());
Copy link
Contributor

Choose a reason for hiding this comment

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

Mostly curious what you think: if this side-effect was moved out of the constructor (into the factory perhaps?), this class would become a trivial wrapper around absl::optional<std::string>. This would make tests simpler, I think: GenericTestInput wouldn't be needed, and TestGenericDataInputFactory would only need to overload the method that retrieves env var with one that returns something expected in the test. Even though getenv() is pretty benign, side-effects in constructors always catch my attention...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that, let me give that a go!

@dmitri-d
Copy link
Contributor

Looks good, other than a small nits re: naming.

Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

/lgtm api

Signed-off-by: Snow Pettersen <[email protected]>
Signed-off-by: Snow Pettersen <[email protected]>
Signed-off-by: Snow Pettersen <[email protected]>
@dmitri-d
Copy link
Contributor

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #15410 (comment) was created by @dmitri-d.

see: more, trace.

@dmitri-d
Copy link
Contributor

lgtm, not sure why precheck docs is failing; perhaps try merging in the latest from the main branch?

@lizan
Copy link
Member

lizan commented Mar 16, 2021

@dmitri-d the doc fails because:

2021-03-15T19:24:09.4627982Z looking for now-outdated files... none found
2021-03-15T19:24:09.4630549Z pickling environment... /source/generated/rst/api-v3/common_messages/common_messages.rst:4: WARNING: toctree contains reference to nonexisting document 'api-v3/extensions/matching/generic_inputs/environment/v3/environment.proto'
2021-03-15T19:24:09.5144597Z done

Signed-off-by: Snow Pettersen <[email protected]>
Signed-off-by: Snow Pettersen <[email protected]>
Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

/lgtm api

can you check CI?

Signed-off-by: Snow Pettersen <[email protected]>
@snowp
Copy link
Contributor Author

snowp commented Mar 23, 2021

This should be ready for another pass

@snowp
Copy link
Contributor Author

snowp commented Mar 31, 2021

@htuch @mattklein123 either of you want to review this?

@mattklein123 mattklein123 self-assigned this Mar 31, 2021
@mattklein123
Copy link
Member

Sure I can take a look.

mattklein123
mattklein123 previously approved these changes Mar 31, 2021
Copy link
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.

LGTM!

@phlax
Copy link
Member

phlax commented Mar 31, 2021

this needs to merge main - it would fail linting on postsubmit if merged as is

/wait

Signed-off-by: Snow Pettersen <[email protected]>
@snowp snowp merged commit 758a9a9 into envoyproxy:main Apr 1, 2021
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.

Add environment variable DataInput extension
6 participants