Skip to content

Commit 2c819c8

Browse files
committed
Review update
1 parent 51c729d commit 2c819c8

File tree

10 files changed

+36
-67
lines changed

10 files changed

+36
-67
lines changed

docker/test/integration/resources/reverse-proxy/Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

docker/test/integration/resources/reverse-proxy/nginx-basic-auth.conf

Lines changed: 0 additions & 12 deletions
This file was deleted.

docker/test/integration/resources/reverse-proxy/run.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

extensions/grafana-loki/tests/features/resources/check_log_lines_on_grafana.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def wait_for(action, timeout_seconds, *args, **kwargs) -> bool:
2424
result = action(*args, **kwargs)
2525
if result:
2626
return result
27-
time.sleep(1)
2827
if timeout_seconds < (time.perf_counter() - start_time):
2928
break
29+
time.sleep(1)
3030
return False
3131

3232

33-
def veify_log_lines_on_grafana_loki(host: str, lines: list[str], ssl: bool, tenant_id: str) -> bool:
33+
def verify_log_lines_on_grafana_loki(host: str, lines: list[str], ssl: bool, tenant_id: str) -> bool:
3434
labels = '{job="minifi"}'
3535
prefix = "http://"
3636
if ssl:
@@ -61,7 +61,7 @@ def veify_log_lines_on_grafana_loki(host: str, lines: list[str], ssl: bool, tena
6161

6262

6363
def wait_for_lines_on_grafana_loki(host: str, lines: list[str], timeout_seconds: int, ssl: bool, tenant_id: str) -> bool:
64-
return wait_for(lambda: veify_log_lines_on_grafana_loki(host, lines, ssl, tenant_id), timeout_seconds)
64+
return wait_for(lambda: verify_log_lines_on_grafana_loki(host, lines, ssl, tenant_id), timeout_seconds)
6565

6666

6767
if __name__ == "__main__":
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# Source: https://gist.github.com/laurentbel/c4c7696890fc71c8061172a932eb52e4
2-
FROM nginx:1.25.3
1+
FROM nginx:1.29.4
32

4-
RUN apt-get update -y && apt-get install -y apache2-utils && rm -rf /var/lib/apt/lists/*
3+
COPY nginx.conf.template /nginx.conf.template
4+
COPY run.sh /run.sh
55

6-
WORKDIR /
7-
COPY nginx-basic-auth.conf nginx-basic-auth.conf
6+
RUN apt update -y && apt install -y apache2-utils && rm /etc/nginx/conf.d/default.conf && chmod 0755 /run.sh
87

9-
COPY run.sh ./
10-
RUN chmod 0755 ./run.sh
11-
CMD [ "./run.sh" ]
8+
ENTRYPOINT [ "/run.sh" ]

extensions/grafana-loki/tests/features/resources/reverse-proxy/nginx-basic-auth.conf

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
server {
2+
listen 3030;
3+
server_name default_server;
4+
5+
location / {
6+
proxy_pass http://${FORWARD_HOST}:${FORWARD_PORT};
7+
auth_basic "Administrator’s Area";
8+
auth_basic_user_file /etc/nginx/.htpasswd;
9+
}
10+
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#!/bin/sh
2-
# Source: https://gist.github.com/laurentbel/c4c7696890fc71c8061172a932eb52e4
3-
envsubst < nginx-basic-auth.conf > /etc/nginx/conf.d/default.conf
4-
htpasswd -c -b /etc/nginx/.htpasswd "${BASIC_USERNAME}" "${BASIC_PASSWORD}"
5-
exec nginx -g "daemon off;"
1+
#!/bin/bash
2+
3+
htpasswd -bc /etc/nginx/.htpasswd "${BASIC_USERNAME}" "${BASIC_PASSWORD}"
4+
5+
envsubst '${FORWARD_HOST} ${FORWARD_PORT}' < /nginx.conf.template > /etc/nginx/conf.d/default.conf
6+
7+
nginx -g "daemon off;"

extensions/grafana-loki/tests/features/steps/grafana_loki_container.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from minifi_test_framework.containers.file import File
2222
from minifi_test_framework.core.minifi_test_context import MinifiTestContext
2323
from minifi_test_framework.core.ssl_utils import make_server_cert
24+
from docker.errors import ContainerError
2425

2526

2627
class GrafanaLokiOptions:
@@ -140,6 +141,11 @@ def are_lines_present(self, lines: str, timeout: int, ssl: bool, tenant_id: str
140141
self.client.containers.run("minifi-grafana-loki-helper:latest", ["python", "/scripts/check_log_lines_on_grafana.py", self.container_name, lines, str(timeout), str(ssl), tenant_id],
141142
remove=True, stdout=True, stderr=True, network=self.network.name)
142143
return True
144+
except ContainerError as e:
145+
stdout = e.stdout.decode("utf-8", errors="replace") if e.stdout else ""
146+
stderr = e.stderr.decode("utf-8", errors="replace") if e.stderr else ""
147+
logging.error(f"Failed to run python command in grafana loki helper docker with error: '{e}', stdout: '{stdout}', stderr: '{stderr}'")
148+
return False
143149
except Exception as e:
144-
logging.error(f"Failed to run python command in grafana loki helper docker: {e}")
150+
logging.error(f"Unexpected error while running python command in grafana loki helper docker: '{e}'")
145151
return False

extensions/grafana-loki/tests/features/steps/steps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ def step_impl(context: MinifiTestContext):
4242
@then("\"{lines}\" lines are published to the Grafana Loki server in less than {timeout_seconds:d} seconds")
4343
@then("\"{lines}\" line is published to the Grafana Loki server in less than {timeout_seconds:d} seconds")
4444
def step_impl(context, lines: str, timeout_seconds: int):
45-
assert context.containers["grafana-loki-server"].are_lines_present(lines, timeout_seconds, False) or log_due_to_failure(context)
45+
assert context.containers["grafana-loki-server"].are_lines_present(lines, timeout_seconds, ssl=False) or log_due_to_failure(context)
4646

4747

4848
@then("\"{lines}\" lines are published to the \"{tenant_id}\" tenant on the Grafana Loki server in less than {timeout_seconds:d} seconds")
4949
@then("\"{lines}\" line is published to the \"{tenant_id}\" tenant on the Grafana Loki server in less than {timeout_seconds:d} seconds")
5050
def step_impl(context, lines: str, timeout_seconds: int, tenant_id: str):
51-
assert context.containers["grafana-loki-server"].are_lines_present(lines, timeout_seconds, False, tenant_id) or log_due_to_failure(context)
51+
assert context.containers["grafana-loki-server"].are_lines_present(lines, timeout_seconds, ssl=False, tenant_id=tenant_id) or log_due_to_failure(context)
5252

5353

5454
@then("\"{lines}\" lines are published using SSL to the Grafana Loki server in less than {timeout_seconds:d} seconds")
5555
@then("\"{lines}\" line is published using SSL to the Grafana Loki server in less than {timeout_seconds:d} seconds")
5656
def step_impl(context, lines: str, timeout_seconds: int):
57-
assert context.containers["grafana-loki-server"].are_lines_present(lines, timeout_seconds, True) or log_due_to_failure(context)
57+
assert context.containers["grafana-loki-server"].are_lines_present(lines, timeout_seconds, ssl=True) or log_due_to_failure(context)
5858

5959

6060
# Nginx reverse proxy
61-
@step(u'a reverse proxy is set up to forward requests to the Grafana Loki server')
61+
@step('a reverse proxy is set up to forward requests to the Grafana Loki server')
6262
def step_impl(context):
6363
context.containers["reverse-proxy"] = ReverseProxyContainer(context)

0 commit comments

Comments
 (0)