예제 #1
0
    def run_agent(self, agent_yaml):
        with start_fake_backend() as backend:
            with self.run_tunnels(backend) as pod_ip:
                agent = Agent(
                    agent_image_name=self.agent_image_name,
                    cluster=self,
                    namespace=self.test_namespace,
                    fake_services=backend,
                    fake_services_pod_ip=pod_ip,
                )
                with agent.deploy(agent_yaml):
                    try:
                        yield agent
                    finally:
                        print("\nDatapoints received:")
                        for dp in backend.datapoints or []:
                            print_dp_or_event(dp)

                        print("\nEvents received:")
                        for event in backend.events or []:
                            print_dp_or_event(event)
                        print(f"\nDimensions set: {backend.dims}")
                        print("\nTrace spans received:")
                        for span in backend.spans or []:
                            print(span)
예제 #2
0
    def run_agent(self,
                  agent_image,
                  config=None,
                  observer=None,
                  monitors=None,
                  namespace="default"):
        """
        Start the fake backend services and configure/create the k8s agent resources within the minikube container.

        Required Argument:
        agent_image:    Object returned from the agent_image fixture containing the agent image's name, tag, and id.

        Optional Arguments:
        config:         Configuration YAML for the agent (overwrites the configmap agent.yaml).
                        If not None, takes precedence over `observer` and `monitors` arguments (default: None).
        observer:       Name of the observer to set in the configmap agent.yaml (default: None).
        monitors:       List of monitors to set in the configmap agent.yaml (default: []).
        namespace:      Namespace for the agent (default: "default").
        """

        if not monitors:
            monitors = []
        with start_fake_backend(ip_addr=get_host_ip()) as backend:
            options = dict(
                image_name=agent_image["name"],
                image_tag=agent_image["tag"],
                observer=observer,
                monitors=monitors,
                config=config,
                cluster_name=self.cluster_name,
                namespace=namespace,
                backend=backend,
            )
            with self.agent.deploy(**options):
                try:
                    yield self.agent, backend
                finally:
                    if backend.datapoints:
                        print("\nDatapoints received:")
                        for dp in backend.datapoints:
                            print_dp_or_event(dp)
                    if backend.events:
                        print("\nEvents received:")
                        for event in backend.events:
                            print_dp_or_event(event)