Skip to content

Commit

Permalink
tools: (mostly) enforcing flag alpha order (#16182)
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk authored Apr 29, 2021
1 parent 9ae397e commit 5e35ac6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tools/code_format/check_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
# :ref:`panic mode. <arch_overview_load_balancing_panic_threshold>`
REF_WITH_PUNCTUATION_REGEX = re.compile(".*\. <[^<]*>`\s*")
DOT_MULTI_SPACE_REGEX = re.compile("\\. +")
FLAG_REGEX = re.compile(" \"(.*)\",")

# yapf: disable
PROTOBUF_TYPE_ERRORS = {
Expand Down Expand Up @@ -250,6 +251,15 @@
"extensions/filters/network/common",
"extensions/filters/network/common/redis",
}

UNSORTED_FLAGS = {
"envoy.reloadable_features.activate_timers_next_event_loop",
"envoy.reloadable_features.check_ocsp_policy",
"envoy.reloadable_features.grpc_json_transcoder_adhere_to_buffer_limits",
"envoy.reloadable_features.http2_skip_encoding_empty_trailers",
"envoy.reloadable_features.upstream_http2_flood_checks",
"envoy.reloadable_features.header_map_correctly_coalesce_cookies",
}
# yapf: enable


Expand Down Expand Up @@ -494,6 +504,30 @@ def has_invalid_angle_bracket_directory(self, line):
subdir = path[0:slash]
return subdir in SUBDIR_SET

# simple check that all flags between "Begin alphabetically sorted section."
# and the end of the struct are in order (except the ones that already aren't)
def check_runtime_flags(self, file_path, error_messages):
in_flag_block = False
previous_flag = ""
for line_number, line in enumerate(self.read_lines(file_path)):
if "Begin alphabetically" in line:
in_flag_block = True
continue
if not in_flag_block:
continue
if "}" in line:
break

match = FLAG_REGEX.match(line)
if not match:
error_messages.append("%s does not look like a reloadable flag" % line)
break

if previous_flag:
if line < previous_flag and match.groups()[0] not in UNSORTED_FLAGS:
error_messages.append("%s and %s are out of order\n" % (line, previous_flag))
previous_flag = line

def check_current_release_notes(self, file_path, error_messages):
first_word_of_prior_line = ''
next_word_to_check = '' # first word after :
Expand Down Expand Up @@ -580,6 +614,9 @@ def check_file_contents(self, file_path, checker):
# This only validates entries for the current release as very old release
# notes have a different format.
self.check_current_release_notes(file_path, error_messages)
if file_path.endswith("source/common/runtime/runtime_features.cc"):
# Do runtime alphabetical order checks.
self.check_runtime_flags(file_path, error_messages)

def check_format_errors(line, line_number):

Expand Down

0 comments on commit 5e35ac6

Please sign in to comment.