Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldmitry committed Jul 30, 2024
1 parent 3c389ec commit c98827d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
7 changes: 7 additions & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
S3_INTEGRATOR = "s3-integrator"
WORKER_NAME = "tempo-worker"
APP_NAME = "tempo"
protocols_endpoints = {
"jaeger_thrift_http": "https://{}:14268/api/traces?format=jaeger.thrift",
"zipkin": "https://{}:9411/v1/traces",
"jaeger_grpc": "{}:14250",
"otlp_http": "https://{}:4318/v1/traces",
"otlp_grpc": "{}:4317",
}

logger = logging.getLogger(__name__)

Expand Down
65 changes: 37 additions & 28 deletions tests/integration/test_ingressed_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

import pytest
import yaml
from helpers import deploy_cluster, emit_trace, get_traces_patiently
from helpers import (
deploy_cluster,
emit_trace,
get_traces_patiently,
protocols_endpoints,
)
from juju.application import Application
from pytest_operator.plugin import OpsTest

Expand All @@ -20,7 +25,7 @@
logger = logging.getLogger(__name__)


async def get_ingress_proxied_endpoint(ops_test: OpsTest):
async def get_ingress_proxied_hostname(ops_test: OpsTest):
status = await ops_test.model.get_status()
app = status["applications"][TRAEFIK_APP_NAME]
status_msg = app["status"]["info"]
Expand All @@ -31,6 +36,13 @@ async def get_ingress_proxied_endpoint(ops_test: OpsTest):
return status_msg.replace("Serving at", "").strip()


async def get_tempo_ingressed_endpoint(hostname, protocol):
protocol_endpoint = protocols_endpoints.get(protocol)
if protocol_endpoint is None:
assert False, f"Invalid {protocol}"
return protocol_endpoint.format(hostname)


@pytest.mark.setup
@pytest.mark.abort_on_fail
async def test_build_and_deploy(ops_test: OpsTest):
Expand Down Expand Up @@ -68,7 +80,8 @@ async def test_push_tracegen_script_and_deps(ops_test: OpsTest):
await ops_test.juju(
"ssh",
f"{APP_NAME}/0",
"python3 -m pip install opentelemetry-exporter-otlp-proto-grpc opentelemetry-exporter-otlp-proto-http",
"python3 -m pip install opentelemetry-exporter-otlp-proto-grpc opentelemetry-exporter-otlp-proto-http"
+ " opentelemetry-exporter-zipkin opentelemetry-exporter-jaeger",
)


Expand Down Expand Up @@ -104,38 +117,34 @@ async def test_relate(ops_test: OpsTest):


@pytest.mark.abort_on_fail
async def test_verify_ingressed_trace_http_tls(ops_test: OpsTest, nonce, server_cert):
tempo_host = await get_ingress_proxied_endpoint(ops_test)

await emit_trace(
f"https://{tempo_host}:4318/v1/traces", nonce=nonce, ops_test=ops_test, use_cert=True
)
# THEN we can verify it's been ingested
assert await get_traces_patiently(tempo_host)
@pytest.mark.parametrize("protocol", list(protocols_endpoints.keys()))
async def test_verify_traces_force_enabled_protocols_tls(ops_test: OpsTest, nonce, protocol):


@pytest.mark.abort_on_fail
async def test_verify_ingressed_traces_grpc_tls(ops_test: OpsTest, nonce, server_cert):
# enable otlp grpc receiver
tempo_app: Application = ops_test.model.applications[APP_NAME]
await tempo_app.set_config(
{
"always_enable_otlp_grpc": "True",
}
)
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
timeout=1000,
)

tempo_host = await get_ingress_proxied_endpoint(ops_test)
# enable each protocol receiver
# otlp_http should be enabled by default
if protocol != "otlp_http":
await tempo_app.set_config(
{
f"always_enable_{protocol}": "True",
}
)
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
timeout=1000,
)

tempo_host = await get_ingress_proxied_hostname(ops_test)
tempo_endpoint = await get_tempo_ingressed_endpoint(tempo_host, protocol=protocol)
# WHEN we emit a trace secured with TLS

await emit_trace(
f"{tempo_host}:4317", nonce=nonce, proto="otlp_grpc", ops_test=ops_test, use_cert=True
tempo_endpoint, ops_test, nonce=nonce, verbose=1, proto=protocol, use_cert=True
)
# THEN we can verify it's been ingested
assert await get_traces_patiently(tempo_host, service_name="tracegen-otlp_grpc")
await get_traces_patiently(tempo_host, service_name=f"tracegen-{protocol}")


@pytest.mark.teardown
Expand Down
11 changes: 2 additions & 9 deletions tests/integration/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get_application_ip,
get_traces,
get_traces_patiently,
protocols_endpoints,
)
from juju.application import Application
from pytest_operator.plugin import OpsTest
Expand All @@ -19,13 +20,7 @@
SSC = "self-signed-certificates"
SSC_APP_NAME = "ssc"
TRACEGEN_SCRIPT_PATH = Path() / "scripts" / "tracegen.py"
protocols_endpoints = {
"jaeger_thrift_http": "https://{}:14268/api/traces?format=jaeger.thrift",
"zipkin": "https://{}:9411/v1/traces",
"jaeger_grpc": "{}:14250",
"otlp_http": "https://{}:4318/v1/traces",
"otlp_grpc": "{}:4317",
}


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -107,8 +102,6 @@ async def test_verify_traces_force_enabled_protocols_tls(ops_test: OpsTest, nonc
tempo_app: Application = ops_test.model.applications[APP_NAME]

# enable each protocol receiver
# for protocol in protocols_endpoints:

# otlp_http should be enabled by default
if protocol != "otlp_http":
await tempo_app.set_config(
Expand Down

0 comments on commit c98827d

Please sign in to comment.