Skip to content

Commit

Permalink
config: config load check tool (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
junr03 authored May 24, 2017
1 parent 20bf9e8 commit d568919
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/configuration/tools/router_check.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ the route returned by a :ref:`router <config_http_conn_man_route_table>` matches
The tool can be used to check cluster name, virtual cluster name,
virtual host name, manual path rewrite, manual host rewrite, path redirect, and
header field matches. Extensions for other test cases can be added. Details about installing the tool
and sample tool input/output can be found at :ref:`installation <install_tools>`.
and sample tool input/output can be found at :ref:`installation <install_tools_route_table_check_tool>`.

The route table check tool config is composed of an array of json test objects. Each test object is composed of
three parts.
Expand Down
2 changes: 1 addition & 1 deletion docs/install/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Building and installation
installation
ref_configs
sandboxes/sandboxes.rst
tools
tools/tools
28 changes: 28 additions & 0 deletions docs/install/tools/config_load_check_tool.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Config load check tool
======================

The config load check tool checks that a configuration file in JSON format is written using valid JSON
and conforms to the Envoy JSON schema. This tool leverages the configuration test in
``test/config_test/config_test.cc``. The test loads the JSON configuration file and runs server configuration
initialization with it.

Input
The tool expects a PATH to the root of a directory that holds JSON Envoy configuration files. The tool
will recursively go through the filesystem tree and run a configuration test for each file found. Keep in mind that
the tool will try to load all files found in the path.

Output
The tool will output Envoy logs as it initializes the server configuration with the config it is currently testing.
If there are configuration files where the JSON file is malformed or is does not conform to the Envoy JSON schema, the
tool will exit with status EXIT_FAILURE. If the tool successfully loads all configuration files found it will
exit with status EXIT_SUCCESS.

Building
The tool can be built locally using Bazel. ::

bazel build //test/tools/config_load_check:config_load_check_tool

Running
The tool takes a path as described above. ::

bazel-bin/test/tools/config_load_check/config_load_check_tool PATH
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. _install_tools:
.. _install_tools_route_table_check_tool:

Route Table Check Tool
Route table check tool
=======================

The route table check tool checks whether the route parameters returned by a router match what is expected.
Expand Down
8 changes: 8 additions & 0 deletions docs/install/tools/tools.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Tools
=====

.. toctree::
:maxdepth: 2

config_load_check_tool
route_table_check_tool
2 changes: 1 addition & 1 deletion docs/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Version history
* The CPU profiler output path is now :ref:`configurable <config_admin>`.
* A :ref:`watchdog system <config_overview>` has been added that can kill the server if a deadlock
is detected.
* A :ref:`route table checking tool <install_tools>` has been added that can be used to test route
* A :ref:`route table checking tool <install_tools_route_table_check_tool>` has been added that can be used to test route
tables before use.
* We have added an :ref:`example repo <extending>` that shows how to compile/link a custom filter.
* Added additional cluster wide information related to outlier detection to the :ref:`/clusters
Expand Down
1 change: 0 additions & 1 deletion test/config_test/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ uint32_t run(const std::string& directory) {
ConfigTest config(filename);
num_tested++;
}

return num_tested;
}

Expand Down
1 change: 1 addition & 0 deletions test/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ envoy_cc_test_library(
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:environment_lib",
"//test/test_common:network_utility_lib",
"//test/test_common:printers_lib",
"//test/test_common:utility_lib",
],
)
Expand Down
16 changes: 16 additions & 0 deletions test/tools/config_load_check/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_binary",
"envoy_package",
)

envoy_package()

envoy_cc_binary(
name = "config_load_check_tool",
testonly = 1,
srcs = ["config_load_check.cc"],
deps = ["//test/config_test:config_test_lib"],
)
34 changes: 34 additions & 0 deletions test/tools/config_load_check/config_load_check.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// NOLINT(namespace-envoy)
#include <iostream>
#include <stdexcept>
#include <string>

#include "test/config_test/config_test.h"

#include "gtest/gtest.h"
#include "spdlog/spdlog.h"

int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: config_load_check PATH\n"
"\nValidate configuration files against json schema\n"
"\n\tPATH - root of the path that holds the json files to verify."
" The tool recursively searches for json files to validate." << std::endl;
return EXIT_FAILURE;
}
try {
const uint32_t num_tested = Envoy::ConfigTest::run(std::string(argv[1]));
std::cout << fmt::format("Configs tested: {}. ", num_tested);
if (testing::Test::HasFailure()) {
std::cerr << "There were failures. Please Fix your configuration files." << std::endl;
return EXIT_FAILURE;
} else {
std::cout << "No failures." << std::endl;
return EXIT_SUCCESS;
}
} catch (const std::runtime_error& e) {
// catch directory not found runtime exception.
std::cerr << e.what() << std::endl;
}
return EXIT_FAILURE;
}

0 comments on commit d568919

Please sign in to comment.