Skip to content

fix envoy.filters.http.lua metadata empty - #17359

Merged
mattklein123 merged 20 commits into
envoyproxy:mainfrom
chrisxrepo:fix_filter_lua_metadata
Jul 29, 2021
Merged

mattklein123 merged 20 commits into
envoyproxy:mainfrom
chrisxrepo:fix_filter_lua_metadata

Conversation

@chrisxrepo

@chrisxrepo chrisxrepo commented Jul 15, 2021 •

Copy link
Copy Markdown
Contributor

Signed-off-by: Chris Xin [email protected]

// in source/common/router/config_impl.cc
const RouteEntry* RouteEntryImplBase::routeEntry() const {
  if (isDirectResponse()) {
    return nullptr;
  } else {
    return this;
  }
}

// in source/extensions/filters/http/lua/lua_filter.cc
const ProtobufWkt::Struct& getMetadata(Http::StreamFilterCallbacks* callbacks) {
  if (callbacks->route() == nullptr || callbacks->route()->routeEntry() == nullptr) {
    return ProtobufWkt::Struct::default_instance();
  }
  const auto& metadata = callbacks->route()->routeEntry()->metadata();
  .....
}

if route set direct response, callbacks->route()->routeEntry() will return nullptr. request_handle:metadata() will return empty in filter:filter.http.lua inline lua script,

Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #17166]
[Optional Deprecated:]
[Optional API Considerations:]

@chrisxrepo
chrisxrepo force-pushed the fix_filter_lua_metadata branch from d9a64fc to 93b6ef9 Compare July 15, 2021 11:54
@chrisxrepo

Copy link
Copy Markdown
Contributor Author

i will add unit test later

@snowp

snowp commented Jul 15, 2021

Copy link
Copy Markdown
Contributor

Can you elaborate on the issue a bit more? If the problem is just around the metadata entry not being set can we just gate on what instead of having to rely on dynamic casts?

@snowp snowp self-assigned this Jul 15, 2021
@chrisxrepo

chrisxrepo commented Jul 16, 2021 •

Copy link
Copy Markdown
Contributor Author

yeah, i think so, i will add metadata() interface in Envoy::Router::Router

@chrisxrepo
chrisxrepo force-pushed the fix_filter_lua_metadata branch from 8b1296c to 9be2873 Compare July 16, 2021 09:20
@snowp

snowp commented Jul 16, 2021

Copy link
Copy Markdown
Contributor

Looks like CI is broken, and this will need a test case as well

/wait

Signed-off-by: chris.xin <[email protected]>
Signed-off-by: chris.xin <[email protected]>
@chrisxrepo
chrisxrepo force-pushed the fix_filter_lua_metadata branch from 23745c6 to 6aacda9 Compare July 19, 2021 11:47
Comment thread envoy/router/router.h Outdated
* @return const envoy::config::core::v3::Metadata& return the metadata provided in the config for
* this route.
*/
virtual const envoy::config::core::v3::Metadata& metadata() const { return empty_metadata_; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know why we don't just return a RouteEntry for direct response entries? I'm a bit concerned that exposing metadata on both Route and RouteEntry leaves the API in an odd state where it's not clear why one would use on over the other. Thoughts?

@chrisxrepo chrisxrepo Jul 20, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, it will be odd state. but how can it get the metadatas int http filter for direct response entries?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it probably would be populated on the RouteEntryImplBase already, we just somehow refuse to give the caller a RouteEntry when it's a direct response. @mattklein123 @alyssawilk any idea why we special case direct response in this way?

The current proposed implementation seems incomplete as well, seems like we'd always return empty metadata in this case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah seems weird to me, I'd rather (runtime guard) expose the route entry on direct response but maybe git blame who special cased it and ask them?

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.

From looking at the code, I suspect the original intention is that a direction response != an upstream route entry, and that is why the interface/code is broken down that way. I have 2 comments:

  1. Personally, I would remove metadata() from RouteEntry and add it to Route as this PR does. Then it can be grabbed in all cases.
  2. I don't understand how always returning empty metadata here makes sense. Don't you want to return the configured route metadata?

@chrisxrepo chrisxrepo Jul 21, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i try to remove metadata() from Router::RouteEntry, so many files will be change. i think it will take another problems.

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.

Yes, it will be a larger change, but that is the change we need to do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, i will do it

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 still not sure why this is returning empty metadata. I would keep this as a PURE virtual function and let the implementation return the right thing.

/wait

Signed-off-by: chris.xin <[email protected]>
Signed-off-by: chris.xin <[email protected]>
@chrisxrepo
chrisxrepo force-pushed the fix_filter_lua_metadata branch from aa5fcd0 to 6f0ce39 Compare July 21, 2021 10:43
@mattklein123 mattklein123 self-assigned this Jul 21, 2021
@chrisxrepo
chrisxrepo force-pushed the fix_filter_lua_metadata branch 3 times, most recently from c45afb5 to e5a8fba Compare July 22, 2021 10:12
Signed-off-by: chris.xin <[email protected]>
@chrisxrepo
chrisxrepo force-pushed the fix_filter_lua_metadata branch from 51a67ac to 7dbfacf Compare July 26, 2021 07:00
Signed-off-by: chris.xin <[email protected]>

@mattklein123 mattklein123 left a comment

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 this looks like great progress.

/wait

Comment thread envoy/stream_info/stream_info.h Resolved
Comment on lines +36 to +37
const envoy::config::core::v3::Metadata metadata_;
const Envoy::Config::TypedMetadataImpl<Envoy::Config::TypedMetadataFactory> typed_metadata_;

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 should be calling the parent methods, not returning empty.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I accidentally ignored it.

@chrisxrepo
chrisxrepo force-pushed the fix_filter_lua_metadata branch from 4bb0d58 to 9a6096f Compare July 27, 2021 08:21
Signed-off-by: Chris Xin <[email protected]>
Signed-off-by: Chris Xin <[email protected]>
@mattklein123

Copy link
Copy Markdown
Member

@chrisxrepo please do not force push as it makes reviews much more difficult. Just merge main and add commits. Thanks!

@mattklein123 mattklein123 left a comment

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 this is a great change. A small comment. Thank you!

/wait

#include "source/common/config/datasource.h"
#include "source/common/crypto/utility.h"
#include "source/common/http/message_impl.h"
#include "source/common/router/config_impl.h"

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.

No need to include the impl here or in the BUILD file above, same elsewhere if I missed it.

@chrisxrepo

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

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

🐱

Caused by: a #17359 (comment) was created by @chrisxrepo.

see: more, trace.

@mattklein123 mattklein123 left a comment

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 LGTM with another small change. @snowp any further comments?

/wait

"//source/common/config:datasource_lib",
"//source/common/crypto:utility_lib",
"//source/common/http:message_lib",
"//source/common/router:config_lib",

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.

revert

snowp
snowp previously approved these changes Jul 28, 2021

@snowp snowp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just one small comment

Comment thread envoy/stream_info/stream_info.h Outdated

namespace Router {
class Route;
class RouteEntry;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we still need this forward declaration?

Signed-off-by: Chris Xin <[email protected]>

@mattklein123 mattklein123 left a comment

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!

@mattklein123
mattklein123 merged commit f17c47e into envoyproxy:main Jul 29, 2021
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 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.

filter_metadata is always empty when working with direct_response

4 participants