style: automate and enforce header ordering guidelines.#793
Merged
mattklein123 merged 3 commits intoenvoyproxy:masterfrom Apr 20, 2017
Merged
style: automate and enforce header ordering guidelines.#793mattklein123 merged 3 commits intoenvoyproxy:masterfrom
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
Conversation
Script to automate header ordering check/fix (tools/header_order.py) and resulting reorderings. See the comment at the top of header_order.py for why the header order looks the way it does. Also made check_format.py standalone and introduced a check_format CI target in addition to fix_format in anticipation of removing the old CI targets. There is considerable overlap with what this does and clang-format's IncludeCategories (see https://clang.llvm.org/docs/ClangFormatStyleOptions.html). But, clang-format doesn't seem smart enough to handle block splitting and correctly detecting the main header subject to the Envoy canonical paths.
tools/header_order.py
Outdated
| with open(path, 'w') as f: | ||
| f.write(reorderd_source) | ||
| sys.exit(0) | ||
| print 'Usage: %s [--rewrite] <.h path>' % sys.argv[0] |
Member
There was a problem hiding this comment.
nit: .h path is kind of confusing. It's just a source file path right?
|
|
||
| after_includes_lines += list(all_lines) | ||
|
|
||
| def file_header_filter(): |
Member
There was a problem hiding this comment.
nit: it took me 60s to figure out that this is figuring out the associated files header, add comment?
mattklein123
approved these changes
Apr 20, 2017
htuch
added a commit
to htuch/envoy
that referenced
this pull request
Apr 20, 2017
Since Bazel doesn't support precompiled headers (bazelbuild/bazel#1215), we actually suffer a slowdown rather than speedup by having all files implicitly include precompiled.h in the Bazel build. I found ~10% performance improvement on my workstation, going from 181s to 163s for a "bazel build //test/..." from a "bazel clean" state. This patch makes all includes now explicit. This will slowdown the cmake build, but since this is not long for this world it seems alright. The header reordering in this patch was achieved using envoyproxy#793. The addition of the missing headers in each file was done using a modified version of the tool in envoyproxy#793, which substituted in headers based on simple substring matches (e.g. whenever it saw std::string in a file, it added #include <string>). Here's the patterns I ended up using that seemed to work: sys_extra_includes = [ ('std::runtime_error', 'stdexcept'), ('strcmp', 'string.h'), ('strcasecmp', 'strings.h'), ('std::unique_ptr', 'memory'), ('std::shared_ptr', 'memory'), ('std::unordered_set', 'unordered_set'), ('std::transform', 'algorithm'), ('std::vector', 'vector'), ('std::regex', 'regex'), ('spdlog::', 'spdlog/spdlog.h'), ('fmt::format', 'spdlog/spdlog.h'), ('std::string', 'string'), ('uint32_t', 'cstdint'), ('uint64_t', 'cstdint'), ('std::array', 'array'), ('sockaddr_un', 'sys/un.h'), ('sockaddr_in', 'netinet/ip.h'), ('std::chrono', 'chrono'), ('std::list', 'list'), ('std::multimap', 'map'), ('std::unordered_map', 'unordered_map'), ('std::stringstream', 'sstream'), ('std::condition_variable', 'condition_variable'), ('std::mutex', 'mutex'), (' ::close', 'unistd.h'), ('inet_ntop', 'arpa/inet.h'), ('inet_pton', 'arpa/inet.h'), ('htonl', 'arpa/inet.h'), ('setsockopt', 'sys/types.h'), ('setsockopt', 'sys/socket.h'), ('TCP_NODELAY', 'netinet/tcp.h'), ('SIGTERM', 'signal.h'), ('SIGPIPE', 'signal.h'), ('std::function', 'functional'), ('std::ifstream', 'fstream'), ('std::ofstream', 'fstream'), ('std::forward_list', 'forward_list'), ('std::atomic', 'atomic'), ('std::cerr', 'iostream'), ('hostent', 'netdb.h'), (' bind(', 'sys/types.h'), (' bind(', 'sys/socket.h'), ('std::ostream', 'iostream'), ] extra_includes = [ ('MOCK_METHOD', 'gmock/gmock.h'), ('MOCK_CONST_METHOD', 'gmock/gmock.h'), ('MATCHER_P', 'gmock/gmock.h'), ('ON_CALL', 'gmock/gmock.h'), ('using testing::_', 'gmock/gmock.h'), ('testing::Test', 'gtest/gtest.h'), ('EXPECT_', 'gtest/gtest.h'), ('\nTEST(', 'gtest/gtest.h'), ('\nTEST_F(', 'gtest/gtest.h'), ('\nTEST_P(', 'gtest/gtest.h'), ('HeaderMapImpl', 'test/test_common/printers.h'), ('Buffer::', 'test/test_common/printers.h'), ('RespValue', 'test/test_common/printers.h'), ]
htuch
added a commit
to htuch/envoy
that referenced
this pull request
Apr 20, 2017
Since Bazel doesn't support precompiled headers (bazelbuild/bazel#1215), we actually suffer a slowdown rather than speedup by having all files implicitly include precompiled.h in the Bazel build. I found ~10% performance improvement on my workstation, going from 181s to 163s for a "bazel build //test/..." from a "bazel clean" state. This patch makes all includes now explicit. This will slowdown the cmake build, but since this is not long for this world it seems alright. The header reordering in this patch was achieved using envoyproxy#793. The addition of the missing headers in each file was done using a modified version of the tool in envoyproxy#793, which substituted in headers based on simple substring matches (e.g. whenever it saw std::string in a file, it added #include <string>). Here's the patterns I ended up using that seemed to work: sys_extra_includes = [ ('std::runtime_error', 'stdexcept'), ('strcmp', 'string.h'), ('strcasecmp', 'strings.h'), ('std::unique_ptr', 'memory'), ('std::shared_ptr', 'memory'), ('std::unordered_set', 'unordered_set'), ('std::transform', 'algorithm'), ('std::vector', 'vector'), ('std::regex', 'regex'), ('spdlog::', 'spdlog/spdlog.h'), ('fmt::format', 'spdlog/spdlog.h'), ('std::string', 'string'), ('uint32_t', 'cstdint'), ('uint64_t', 'cstdint'), ('std::array', 'array'), ('sockaddr_un', 'sys/un.h'), ('sockaddr_in', 'netinet/ip.h'), ('std::chrono', 'chrono'), ('std::list', 'list'), ('std::multimap', 'map'), ('std::unordered_map', 'unordered_map'), ('std::stringstream', 'sstream'), ('std::condition_variable', 'condition_variable'), ('std::mutex', 'mutex'), (' ::close', 'unistd.h'), ('inet_ntop', 'arpa/inet.h'), ('inet_pton', 'arpa/inet.h'), ('htonl', 'arpa/inet.h'), ('setsockopt', 'sys/types.h'), ('setsockopt', 'sys/socket.h'), ('TCP_NODELAY', 'netinet/tcp.h'), ('SIGTERM', 'signal.h'), ('SIGPIPE', 'signal.h'), ('std::function', 'functional'), ('std::ifstream', 'fstream'), ('std::ofstream', 'fstream'), ('std::forward_list', 'forward_list'), ('std::atomic', 'atomic'), ('std::cerr', 'iostream'), ('hostent', 'netdb.h'), (' bind(', 'sys/types.h'), (' bind(', 'sys/socket.h'), ('std::ostream', 'iostream'), ] extra_includes = [ ('MOCK_METHOD', 'gmock/gmock.h'), ('MOCK_CONST_METHOD', 'gmock/gmock.h'), ('MATCHER_P', 'gmock/gmock.h'), ('ON_CALL', 'gmock/gmock.h'), ('using testing::_', 'gmock/gmock.h'), ('testing::Test', 'gtest/gtest.h'), ('EXPECT_', 'gtest/gtest.h'), ('\nTEST(', 'gtest/gtest.h'), ('\nTEST_F(', 'gtest/gtest.h'), ('\nTEST_P(', 'gtest/gtest.h'), ('HeaderMapImpl', 'test/test_common/printers.h'), ('Buffer::', 'test/test_common/printers.h'), ('RespValue', 'test/test_common/printers.h'), ]
mathetake
added a commit
that referenced
this pull request
Mar 3, 2026
**Description** This commit removes the handwritten header matching code from the extproc, and instead starts utilizing the hardened envoy native router. Historically, we had only one giant extproc filter where we did all logics including model name extraction, routing and then body transformation & upstream authorization. Since #599, we split into two external processor filters; one sits at the normal HTTP router and the other is configured at the per-cluster upstream HTTP filter. In theory, the one at HTTP router has only one job on request path: extracting model name from the request body. However, due to the historical reason, the handwritten router logic component remained, and that comes with not only a maintenance cost (forcing a complex extproc & control plane orchestration) but also a potential security vulnerability. In fact, writing header matching logic can be an easy attack surface, so if it's possible, we should avoid writing our own header matching (routing logic) but should rely on the battle-tested hardened envoy native router. With this commit, now a regex matching is available as well as there's no difference between HTTPRoute's matching and AIGatewayRoute's matching implementation. This also opens up a possibility to support path matching in our rule. **Related Issues/PRs (if applicable)** Ref #612 Ref #73 --------- Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
mathetake
added a commit
that referenced
this pull request
Mar 3, 2026
**Description** Before #793, the case where no matching route found was handled in the extproc and the 404 immediate response was returned from there, but after that, it naturally results in the "unreachable" default route and swallowed the indication of no matching and it made it impossible to reason about the 500 error on that case. In other words, this fixes the regression in #793 to return the proper 404 response. --------- Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Script to automate header ordering check/fix (tools/header_order.py) and resulting reorderings. See
the comment at the top of header_order.py for why the header order looks the way it does.
Also made check_format.py standalone and introduced a check_format CI target in addition to
fix_format in anticipation of removing the old CI targets.
There is considerable overlap with what this does and clang-format's IncludeCategories (see
https://clang.llvm.org/docs/ClangFormatStyleOptions.html). But, clang-format doesn't seem smart
enough to handle block splitting and correctly detecting the main header subject to the Envoy
canonical paths.