diff --git a/tests/scenario/test_enabled_receivers.py b/tests/scenario/test_enabled_receivers.py new file mode 100644 index 0000000..d12be15 --- /dev/null +++ b/tests/scenario/test_enabled_receivers.py @@ -0,0 +1,80 @@ +import json +import socket + +from charms.tempo_k8s.v2.tracing import ( + ProtocolType, + Receiver, + TracingProviderAppData, + TracingRequirerAppData, +) +from scenario import Relation, State + +from charm import TempoCoordinatorCharm + + +def test_receivers_with_no_relations_or_config(context, s3, all_worker): + + state = State(leader=True, relations=[s3, all_worker]) + state_out = context.run_action("list-receivers", state) + assert state_out.results == {"otlp-http": f"http://{socket.getfqdn()}:4318"} + + +def test_receivers_with_relations(context, s3, all_worker): + tracing = Relation( + "tracing", + remote_app_data=TracingRequirerAppData(receivers=["otlp_grpc"]).dump(), + ) + state = State(leader=True, relations=[s3, all_worker, tracing]) + with context.manager(tracing.changed_event, state) as mgr: + charm: TempoCoordinatorCharm = mgr.charm + # extra receivers should only include default otlp_http + assert charm.enabled_receivers == set(["otlp_http"]) + out = mgr.run() + + tracing_out = out.get_relations(tracing.endpoint)[0] + assert tracing_out.remote_app_data == TracingRequirerAppData(receivers=["otlp_grpc"]).dump() + # provider app data should include endpoints for otlp_grpc and otlp_http + provider_data = json.loads(tracing_out.local_app_data.get("receivers")) + assert len(provider_data) == 2 + + # run action + action_out = context.run_action("list-receivers", state) + assert action_out.results == { + "otlp-http": f"http://{socket.getfqdn()}:4318", + "otlp-grpc": f"http://{socket.getfqdn()}:4317", + } + + +def test_receivers_with_relations_and_config(context, s3, all_worker): + tracing = Relation( + "tracing", + local_app_data=TracingProviderAppData( + receivers=[ + Receiver( + protocol=ProtocolType(name="otlp_grpc", type="grpc"), + url=f"{socket.getfqdn()}:4317", + ), + Receiver( + protocol=ProtocolType(name="otlp_http", type="http"), + url=f"{socket.getfqdn()}:4318", + ), + ] + ).dump(), + remote_app_data=TracingRequirerAppData(receivers=["otlp_grpc"]).dump(), + ) + # start with a state that has config changed + state = State( + config={"always_enable_zipkin": True}, leader=True, relations=[s3, all_worker, tracing] + ) + with context.manager("config-changed", state) as mgr: + charm: TempoCoordinatorCharm = mgr.charm + # extra receivers should only include default otlp_http + assert charm.enabled_receivers == set(["otlp_http", "zipkin"]) + + # run action + action_out = context.run_action("list-receivers", state) + assert action_out.results == { + "otlp-http": f"http://{socket.getfqdn()}:4318", + "zipkin": f"http://{socket.getfqdn()}:9411", + "otlp-grpc": f"http://{socket.getfqdn()}:4317", + } diff --git a/tests/scenario/test_tempo_clustered.py b/tests/scenario/test_tempo_clustered.py index ef5d20e..e914ad2 100644 --- a/tests/scenario/test_tempo_clustered.py +++ b/tests/scenario/test_tempo_clustered.py @@ -78,7 +78,6 @@ def test_certs_ready(context, state_with_certs): def test_cluster_relation(context, state_with_certs, all_worker): clustered_state = state_with_certs.replace(relations=state_with_certs.relations + [all_worker]) - state_out = context.run(all_worker.joined_event, clustered_state) cluster_out = state_out.get_relations(all_worker.endpoint)[0] local_app_data = TempoClusterProviderAppData.load(cluster_out.local_app_data)