From 011c8f5ec0f9cc653389629711da08226acc13bb Mon Sep 17 00:00:00 2001 From: alyssawilk Date: Thu, 30 Nov 2017 12:52:38 -0500 Subject: [PATCH] Adding priority to lb stats, making all priorities uint32 (#298) Part of implementing priorities, issue #1929 See TODO in #2088 Signed-off-by: Alyssa Wilk --- .clang-format | 14 ++++++ api/eds.proto | 8 ++- ci/do_ci.sh | 10 ++++ tools/check_format.py | 113 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 .clang-format create mode 100644 tools/check_format.py diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..c5146cdd --- /dev/null +++ b/.clang-format @@ -0,0 +1,14 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +ColumnLimit: 100 +DerivePointerAlignment: false +PointerAlignment: Left +SortIncludes: false +... + +--- +Language: Proto +ColumnLimit: 100 +... + diff --git a/api/eds.proto b/api/eds.proto index 12495854..9f944daa 100644 --- a/api/eds.proto +++ b/api/eds.proto @@ -134,7 +134,7 @@ message LocalityLbEndpoints { // next highest priority group. // // Priorities should range from 0 (highest) to N (lowest) without skipping. - google.protobuf.UInt32Value priority = 5; + uint32 priority = 5; } message EndpointLoadMetricStats { @@ -154,7 +154,7 @@ message EndpointLoadMetricStats { // :ref:`LoadStatsResponse.load_reporting_interval`. // Stats per upstream region/zone and optionally per subzone. message UpstreamLocalityStats { - // Name of zone, region and optionally endpoint group this metrics was + // Name of zone, region and optionally endpoint group these metrics were // collected from. Zone and region names could be empty if unknown. Locality locality = 1; @@ -191,6 +191,10 @@ message UpstreamLocalityStats { // Stats for multi-dimensional load balancing. repeated EndpointLoadMetricStats load_metric_stats = 5; + + // [#not-implemented-hide:] The priority of the endpoint group these metrics + // were collected from. + uint32 priority = 6; } // Per cluster load stats. Envoy reports these stats a management server in a diff --git a/ci/do_ci.sh b/ci/do_ci.sh index fa21e44d..0cdd094f 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -21,6 +21,16 @@ if [[ "$1" == "bazel.test" ]]; then elif [[ "$1" == "bazel.docs" ]]; then echo "generating docs..." ./docs/build.sh +elif [[ "$1" == "fix_format" ]]; then + echo "fix_format..." + cd "${ENVOY_SRCDIR}" + ./tools/check_format.py fix + exit 0 +elif [[ "$1" == "check_format" ]]; then + echo "check_format..." + cd "${ENVOY_SRCDIR}" + ./tools/check_format.py check + exit 0 else echo "Invalid do_ci.sh target. The only valid targets are bazel.{docs,test}." exit 1 diff --git a/tools/check_format.py b/tools/check_format.py new file mode 100644 index 00000000..bccc81dd --- /dev/null +++ b/tools/check_format.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python + +import argparse +import fileinput +import re +import os +import os.path +import sys + +EXCLUDED_PREFIXES = ("./generated/", "./bazel-", "./bazel/external") +SUFFIXES = (".cc", ".h", "BUILD", ".proto") + +CLANG_FORMAT_PATH = os.getenv("CLANG_FORMAT", "clang-format-5.0") +BUILDIFIER_PATH = os.getenv("BUILDIFIER", "/usr/lib/go/bin/buildifier") + +found_error = False + + +def printError(error): + global found_error + found_error = True + print "ERROR: %s" % (error) + + +def isBuildFile(file_path): + basename = os.path.basename(file_path) + if basename in {"BUILD", "BUILD.bazel"} or basename.endswith(".BUILD"): + return True + return False + + +def checkFileContents(file_path): + with open(file_path) as f: + text = f.read() + if re.search('\. ', text, re.MULTILINE): + printError("%s has over-enthusiastic spaces" % file_path) + return False + return True + + +def fixFileContents(file_path): + for line in fileinput.input(file_path, inplace=True): + # Strip double space after '.' This may prove overenthusiastic and need to + # be restricted to comments and metadata files but works for now. + print "%s" % (line.replace('. ', '. ').rstrip()) + + +def checkFilePath(file_path): + if isBuildFile(file_path): + if os.system("cat %s | %s -mode=fix | diff -q %s - > /dev/null" % + (file_path, BUILDIFIER_PATH, file_path)) != 0: + printError("buildifier check failed for file: %s" % file_path) + return + checkFileContents(file_path) + command = ("%s %s | diff -q %s - > /dev/null" % (CLANG_FORMAT_PATH, file_path, + file_path)) + if os.system(command) != 0: + printError("clang-format check failed for file: %s" % (file_path)) + + +def fixFilePath(file_path): + if isBuildFile(file_path): + if os.system("%s -mode=fix %s" % (BUILDIFIER_PATH, file_path)) != 0: + printError("buildifier rewrite failed for file: %s" % file_path) + return + fixFileContents(file_path) + command = "%s -i %s" % (CLANG_FORMAT_PATH, file_path) + if os.system(command) != 0: + printError("clang-format rewrite error: %s" % (file_path)) + + +def checkFormat(file_path): + if file_path.startswith(EXCLUDED_PREFIXES): + return + + if not file_path.endswith(SUFFIXES): + return + + if operation_type == "check": + checkFilePath(file_path) + + if operation_type == "fix": + fixFilePath(file_path) + + +def checkFormatVisitor(arg, dir_name, names): + for file_name in names: + checkFormat(dir_name + "/" + file_name) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Check or fix file format.') + parser.add_argument('operation_type', type=str, choices=['check', 'fix'], + help="specify if the run should 'check' or 'fix' format.") + parser.add_argument('target_path', type=str, nargs="?", default=".", help="specify the root directory" + " for the script to recurse over. Default '.'.") + parser.add_argument('--add-excluded-prefixes', type=str, nargs="+", help="exclude additional prefixes.") + args = parser.parse_args() + + operation_type = args.operation_type + target_path = args.target_path + if args.add_excluded_prefixes: + EXCLUDED_PREFIXES += tuple(args.add_excluded_prefixes) + + if os.path.isfile(target_path): + checkFormat("./" + target_path) + else: + os.chdir(target_path) + os.path.walk(".", checkFormatVisitor, None) + + if found_error: + print "ERROR: check format failed. run 'tools/check_format.py fix'" + sys.exit(1)