From ab4439f31462ef2f2936af207c883ef9c449a861 Mon Sep 17 00:00:00 2001 From: Otto van der Schaaf Date: Tue, 2 Mar 2021 10:28:06 +0100 Subject: [PATCH 1/3] Examples: a place to stash practical use cases This captures something I used and for which I had to dig a bit in the codebase to get it set up. Stashing it here may help others and lower the bar for consumption. I anticipate there may be more examples like this that we could add over time. So ideally this PR will be assessed both on structure of the initiative (/examples) and contents (MULTIPLE_ENDPOINTS.md) Signed-off-by: Otto van der Schaaf --- examples/MULTIPLE_ENDPOINTS.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/MULTIPLE_ENDPOINTS.md diff --git a/examples/MULTIPLE_ENDPOINTS.md b/examples/MULTIPLE_ENDPOINTS.md new file mode 100644 index 000000000..65f03ebed --- /dev/null +++ b/examples/MULTIPLE_ENDPOINTS.md @@ -0,0 +1,29 @@ +# Hitting multiple endpoints with a traffic profile + +## Description + +Below is an example which will send requests to two endpoints `127.0.0.1:80` and `127.0.0.2:80`, while alternating over two request headers, which contain different paths and hosts. + +## Define a traffic profile + +Place a file called `traffic-profile.yaml` in your current working directory. + +```yaml +options: + - request_method: 1 + request_headers: + - { header: { key: ":path", value: "/foo" } } + - { header: { key: ":authority", value: "foo.com" } } + - request_method: 1 + request_headers: + - { header: { key: ":path", value: "/bar" } } + - { header: { key: ":authority", value: "bar.com" } } +``` + +## Configuring the CLI + +Below is a CLI examples which will consume the traffic profile created above, and send it to multiple endpoints. + +```bash +bazel-bin/nighthawk_client --request-source-plugin-config "{name:\"nighthawk.file-based-request-source-plugin\",typed_config:{\"@type\":\"type.googleapis.com/nighthawk.request_source.FileBasedOptionsListRequestSourceConfig\",file_path:\"traffic-profile.yaml\",}}" -v trace --multi-target-endpoint 127.0.0.1:80 --multi-target-endpoint 127.0.0.2:80 --multi-target-path / --duration 1 +``` From e83f61507fdee3d55a0b2ec2477dabc813ab0cd1 Mon Sep 17 00:00:00 2001 From: Otto van der Schaaf Date: Wed, 3 Mar 2021 10:30:16 +0100 Subject: [PATCH 2/3] Review feedback & some more polish Signed-off-by: Otto van der Schaaf --- docs/root/examples/MULTIPLE_ENDPOINTS.md | 43 ++++++++++++++++++++++++ examples/MULTIPLE_ENDPOINTS.md | 29 ---------------- 2 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 docs/root/examples/MULTIPLE_ENDPOINTS.md delete mode 100644 examples/MULTIPLE_ENDPOINTS.md diff --git a/docs/root/examples/MULTIPLE_ENDPOINTS.md b/docs/root/examples/MULTIPLE_ENDPOINTS.md new file mode 100644 index 000000000..22db63302 --- /dev/null +++ b/docs/root/examples/MULTIPLE_ENDPOINTS.md @@ -0,0 +1,43 @@ +# Hitting multiple endpoints with a traffic profile + +## Description + +Below is an example which will send requests to two endpoints (`127.0.0.1:80` and `127.0.0.2:80`), while alternating between two request headers which contain different paths and hosts. + +## Practical use + +This example has been useful to test a mesh that exposed multiple endpoints, which in turn would offer access to multiple applications via different hosts/paths. + +## Features used + +This example illustrates the following features: + +- [Request Source](https://github.com/envoyproxy/nighthawk/blob/261abb62c40afbdebb317f320fe67f1a1da1838f/api/request_source/request_source_plugin.proto#L15) (specifically the file-based implementation). +- [Multi-targetting](https://github.com/envoyproxy/nighthawk/blob/261abb62c40afbdebb317f320fe67f1a1da1838f/api/client/options.proto#L84) + +## Steps + +### Configure the file based request source + +Place a file called `traffic-profile.yaml` in your current working directory. This will act as your configuration for the file-based request source. + + +```yaml +options: + - request_method: 1 + request_headers: + - { header: { key: ":path", value: "/foo" } } + - { header: { key: ":authority", value: "foo.com" } } + - request_method: 1 + request_headers: + - { header: { key: ":path", value: "/bar" } } + - { header: { key: ":authority", value: "bar.com" } } +``` + +### Configure the CLI + +Below is a minimal CLI example which will consume the file based request source configuration created above, and hit multiple endpoints. + +```bash +bazel-bin/nighthawk_client --request-source-plugin-config "{name:\"nighthawk.file-based-request-source-plugin\",typed_config:{\"@type\":\"type.googleapis.com/nighthawk.request_source.FileBasedOptionsListRequestSourceConfig\",file_path:\"traffic-profile.yaml\",}}" --multi-target-endpoint 127.0.0.1:80 --multi-target-endpoint 127.0.0.2:80 --multi-target-path / +``` diff --git a/examples/MULTIPLE_ENDPOINTS.md b/examples/MULTIPLE_ENDPOINTS.md deleted file mode 100644 index 65f03ebed..000000000 --- a/examples/MULTIPLE_ENDPOINTS.md +++ /dev/null @@ -1,29 +0,0 @@ -# Hitting multiple endpoints with a traffic profile - -## Description - -Below is an example which will send requests to two endpoints `127.0.0.1:80` and `127.0.0.2:80`, while alternating over two request headers, which contain different paths and hosts. - -## Define a traffic profile - -Place a file called `traffic-profile.yaml` in your current working directory. - -```yaml -options: - - request_method: 1 - request_headers: - - { header: { key: ":path", value: "/foo" } } - - { header: { key: ":authority", value: "foo.com" } } - - request_method: 1 - request_headers: - - { header: { key: ":path", value: "/bar" } } - - { header: { key: ":authority", value: "bar.com" } } -``` - -## Configuring the CLI - -Below is a CLI examples which will consume the traffic profile created above, and send it to multiple endpoints. - -```bash -bazel-bin/nighthawk_client --request-source-plugin-config "{name:\"nighthawk.file-based-request-source-plugin\",typed_config:{\"@type\":\"type.googleapis.com/nighthawk.request_source.FileBasedOptionsListRequestSourceConfig\",file_path:\"traffic-profile.yaml\",}}" -v trace --multi-target-endpoint 127.0.0.1:80 --multi-target-endpoint 127.0.0.2:80 --multi-target-path / --duration 1 -``` From baf7a5eb8b126f9a78cb852010dce076da6d9407 Mon Sep 17 00:00:00 2001 From: Otto van der Schaaf Date: Sat, 6 Mar 2021 13:58:14 +0100 Subject: [PATCH 3/3] Fix a typo Signed-off-by: Otto van der Schaaf --- docs/root/examples/MULTIPLE_ENDPOINTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/root/examples/MULTIPLE_ENDPOINTS.md b/docs/root/examples/MULTIPLE_ENDPOINTS.md index 22db63302..0d50aedc0 100644 --- a/docs/root/examples/MULTIPLE_ENDPOINTS.md +++ b/docs/root/examples/MULTIPLE_ENDPOINTS.md @@ -13,7 +13,7 @@ This example has been useful to test a mesh that exposed multiple endpoints, whi This example illustrates the following features: - [Request Source](https://github.com/envoyproxy/nighthawk/blob/261abb62c40afbdebb317f320fe67f1a1da1838f/api/request_source/request_source_plugin.proto#L15) (specifically the file-based implementation). -- [Multi-targetting](https://github.com/envoyproxy/nighthawk/blob/261abb62c40afbdebb317f320fe67f1a1da1838f/api/client/options.proto#L84) +- [Multi-targeting](https://github.com/envoyproxy/nighthawk/blob/261abb62c40afbdebb317f320fe67f1a1da1838f/api/client/options.proto#L84) ## Steps