-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E test environment for Teleport (#17815)
* Add caddy e2e test environment * add helper script to randomize the mocks for e2e testing * add metrics mocks randomizer helper script + lint * skip integration tests on caddy env, skip e2e tests on non-caddy env * add conditions to docker_run to fix flakiness * use port 3000 in caddy env as well * fix e2e env setup * fmt * fix port number in docker setup file * fix yielded config in docker setup * lint * remove unused const * change e2e setup
- Loading branch information
1 parent
926ba8e
commit f4eabe9
Showing
13 changed files
with
1,767 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: "3" | ||
|
||
services: | ||
teleport-caddy: | ||
image: caddy:2.6.2-alpine | ||
build: . | ||
container_name: teleport-caddy | ||
volumes: | ||
- ./fixtures:/usr/share/caddy | ||
- ./etc/caddy/teleport-service:/etc/caddy/ | ||
ports: | ||
- "3000:80" |
35 changes: 35 additions & 0 deletions
35
teleport/tests/docker/caddy/etc/caddy/teleport-service/Caddyfile
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
debug | ||
admin :2019 | ||
} | ||
:80 { | ||
root * /usr/share/caddy/ | ||
@metrics { | ||
method GET | ||
path /metrics | ||
} | ||
route @metrics { | ||
rewrite * /{http.request.uri.path}/get.txt | ||
file_server | ||
} | ||
|
||
@healthz { | ||
method GET | ||
path /healthz | ||
} | ||
route @healthz { | ||
rewrite * /{http.request.uri.path}/get.json | ||
file_server | ||
} | ||
|
||
@readyz { | ||
method GET | ||
path /readyz | ||
} | ||
route @readyz { | ||
rewrite * /{http.request.uri.path}/get.json | ||
file_server | ||
} | ||
|
||
file_server browse | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "status": "ok" } |
1,574 changes: 1,574 additions & 0 deletions
1,574
teleport/tests/docker/caddy/fixtures/metrics/get.txt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "status": "ok" } |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import random | ||
import sys | ||
import time | ||
|
||
|
||
def main(): | ||
if len(sys.argv) < 2: | ||
sys.exit(0) | ||
|
||
metrics_file = sys.argv[1] | ||
|
||
while True: | ||
read_and_get_new_metrics(metrics_file) | ||
sleep_time = random.randint(1, 30) | ||
time.sleep(sleep_time) | ||
|
||
|
||
def read_and_get_new_metrics(metrics_file): | ||
new_content = [] | ||
|
||
with open(metrics_file, "r") as metrics: | ||
for line in metrics.readlines(): | ||
line = line.rstrip('\n') | ||
if line == "": | ||
new_content.append(line) | ||
continue | ||
if line.startswith("#"): | ||
new_content.append(line) | ||
continue | ||
|
||
fields = line.split(" ") | ||
|
||
metric_name = fields[0] | ||
value_str = fields[-1] | ||
|
||
is_percentage = "percentage" in metric_name | ||
|
||
value = None | ||
is_float = False | ||
|
||
if "." in value_str: | ||
is_float = True | ||
value = float(value_str) | ||
else: | ||
value = int(value_str) | ||
|
||
new_value = modify_value(value, is_percentage, is_float) | ||
new_line = fields[:-1] | ||
if metric_name == "process_state": | ||
new_value = random.choice([0, 1, 2, 3]) | ||
|
||
if "bytes" in metric_name: | ||
new_value *= random.choice([10, 1000, 10000]) | ||
new_value = new_value % 686047984 | ||
new_line.append(str(new_value)) | ||
new_content.append(" ".join(new_line)) | ||
|
||
with open(metrics_file, "w") as metrics: | ||
new_file_content = "\n".join(new_content) | ||
metrics.write(new_file_content) | ||
|
||
|
||
def modify_value(value, is_percentage, is_float): | ||
if is_float and value == 0.0: | ||
value = random.uniform(0.0, 0.2) | ||
if not is_float and value == 0: | ||
value = random.randint(0, 20) | ||
change_percent = random.uniform(0.05, 0.1) | ||
change_direction = random.choice([1, -1]) | ||
change = value * (change_percent * change_direction) | ||
new_value = value + change | ||
|
||
if is_percentage: | ||
new_value = min(new_value, 1.0) | ||
new_value = max(new_value, 0.0) | ||
|
||
if not is_float: | ||
return int(new_value) | ||
return new_value | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
File renamed without changes.
This file contains 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
This file contains 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