Skip to content

Bazel: add define flag for exporting symbols#2331

Merged
mattklein123 merged 1 commit intoenvoyproxy:masterfrom
taion809:bugfix-lua-linking
Jan 17, 2018
Merged

Bazel: add define flag for exporting symbols#2331
mattklein123 merged 1 commit intoenvoyproxy:masterfrom
taion809:bugfix-lua-linking

Conversation

@taion809
Copy link
Copy Markdown
Contributor

@taion809 taion809 commented Jan 9, 2018

Bazel: add define flag for exporting symbols

Description:
The current problem with lua is that it is unable to use external
libraries such as lrexlib installed via luarocks.

The solution is to export the symbols needed by those libraries.

Risk Level: Low

Testing:
I tested this manually. Here is an example lua script and envoy configuration.

{
    "listeners": [
      {
        "address": "tcp://0.0.0.0:5555",
        "filters": [
          {
            "name": "http_connection_manager", 
            "config": {
              "codec_type": "auto", 
              "add_user_agent": true, 
              "use_remote_address": true,
              "idle_timeout_s": 840,
              "stat_prefix": "frontrouter",
              "route_config": {
                "virtual_hosts": [
                  {
                    "name": "backend",
                    "domains": ["*"],
                    "routes": [
                      {
                        "prefix": "",
                        "cluster": "echoer-backend",
                        "auto_host_rewrite": false
                      }
                    ]
                  }
                ]
              }, 
              "filters": [
                  {
                    "name": "lua",
                    "config": {
                        "inline_code": "dofile(\"script.lua\")"
                    }
                  },
                {
                  "name": "router", 
                  "config": {}
                }
              ]
            }
          }
        ]
      }
    ], 
    "cluster_manager": {
      "clusters": [
        {
          "name": "echoer-backend",
          "connect_timeout_ms": 250,
          "type": "static",
          "lb_type": "round_robin",
          "hosts": [
            {
              "url": "tcp://127.0.0.1:3000"
            }
          ]
        }
      ]
    }
  }
function envoy_on_request(request)
    local rex = require "rex_pcre"
    headers = request:headers()
    referrerHeader = headers:get("Referrer")

    if referrerHeader ~= nil then
        match = rex.match(referrerHeader, '^\\/search\\?.*category=.*')
        request:logInfo("Match: "..match)
    end
end

function envoy_on_response(response)
end

Docs Changes:
envoyproxy/data-plane-api#405

Fixes issue #2251

Signed-off-by: Nicholas J nicholas.a.johns5@gmail.com

@taion809 taion809 force-pushed the bugfix-lua-linking branch from 6e667f4 to b4dca3e Compare January 9, 2018 17:08
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 contribution.

# See note here: http://luajit.org/install.html
"-pagezero_size 10000", "-image_base 100000000",
],
"//bazel:enable_exported_symbols": [
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 a separate select statement which is + with the existing one. You can actually factor out a bunch of common list entries into a separate item that is + with this as well.

"-pagezero_size 10000", "-image_base 100000000",
],
"//bazel:enable_exported_symbols": [
'-L/usr/local/lib/lua/5.1/',
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 won't work in many environments. Is there a more generic way to handle this?

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.

oops, Let me relook into this I was doing a lot of troubleshooting before and this just slipped by me :|

# --build-id and avoid doing the following.
'-Wl,--build-id=md5',
'-Wl,--hash-style=gnu',
'-Wl,-E',
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.

Can you add a comment above this line also explaining what it does and why needed?

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.

Thank you for doing this! Few comments. @jmillikin-stripe or @htuch do you mind taking a look also?

"-static-libgcc",
],
"//conditions:default": [
'-L/usr/local/lib/lua/5.1/',
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 needed in the default static linking case?

"-pagezero_size 10000", "-image_base 100000000",
],
"//bazel:enable_exported_symbols": [
'-L/usr/local/lib/lua/5.1/',
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 path going to be consistent across machines? Does it also need to be configurable?

# --build-id and avoid doing the following.
'-Wl,--build-id=md5',
'-Wl,--hash-style=gnu',
'-Wl,-E',
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.

Instead of replicating the entire block just to add -E could we possibly have this be the output of a function that keys off of whether this feature is enabled or not? Then we can just call the function below?

bazel/README.md Outdated

The following optional features can be enabled on the Bazel build command-line:

* Exported symbols during linking with `--define exported_symbols=enabled`
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: Could we add a brief description of why someone would want to do this?

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.

LGTM modulo minor comments.

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 comment isn't very descriptive :) Probably best to say what exported symbols are..

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.

embarrassing, i did some work on this and pushed it up before i left the office 😱

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.

More Pythonic to write if not linkopts: here.

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: s/envoy/Envoy/

@htuch
Copy link
Copy Markdown
Member

htuch commented Jan 10, 2018

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 believe you can use a hardcoded @envoy for the repository -- the only place where that wouldn't work (the Google internal fork) rewrites this file entirely (per htuch).

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'll give that a shot thanks

htuch
htuch previously approved these changes Jan 12, 2018
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.

@taion809
Copy link
Copy Markdown
Contributor Author

Just an update to this, while testing i ran into an error so i'll be doing some more work on this before its ready to go.

@taion809 taion809 force-pushed the bugfix-lua-linking branch 2 times, most recently from 8fb4876 to c1778c6 Compare January 17, 2018 16:05
@htuch
Copy link
Copy Markdown
Member

htuch commented Jan 17, 2018

@taion809 this looks good to merge. Are you suggesting we hold back or GTG?

@taion809
Copy link
Copy Markdown
Contributor Author

@htuch good to go, i did some more manual tests to make sure it was working as expected 👍

@htuch
Copy link
Copy Markdown
Member

htuch commented Jan 17, 2018

@taion809 looks like it needs to be merged again with master.

The current problem with lua is that it is unable to use external
libraries such as lrexlib installed via luarocks.

The solution is to export the symbols needed by those libraries.

Signed-off-by: Nicholas J <nicholas.a.johns5@gmail.com>
@mattklein123 mattklein123 merged commit 61b3852 into envoyproxy:master Jan 17, 2018
@taion809 taion809 deleted the bugfix-lua-linking branch January 18, 2018 14:11
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
* initial commit

* Add common as a dep

* add common context

* WIP3

* WIP5

* WIP7

* WIP3

* unblock client config

* write mapper

* add mapper

* added all 4 http metrics

* fix fast cache key

* Temporarily disable test

* enable common test

* review comments

* add explicit initialization to mappings

* more review comments

* more comments2

* make cache return reference instead of a pointer

* remove copy

* WIP direct mapping

* more direct code

* more simplification

* refactor common, and StatsGen

* add httbin backend for testing, add better logging

* fix test namespace

* prepare to add custom hash

* add trivial local httpbin impl for testing

* which to absl:hashValue

* add missing test file

* fix nits

* add license header

* fix function name

* set max cache size

* make istio_dimensions_ a member of rootContext. The mappings are overwritten before evaluation

* elimiate Node abstraction from NodeInfoCache

* try V4 only testing for prow

* Fix getMetadataStruct return values
jpsim added a commit that referenced this pull request Nov 28, 2022
Signed-off-by: GitHub Action <noreply@github.com>

Co-authored-by: jpsim <jpsim@users.noreply.github.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Nov 29, 2022
Signed-off-by: GitHub Action <noreply@github.com>

Co-authored-by: jpsim <jpsim@users.noreply.github.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.

4 participants