Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eng 1512 otel integration tests #2867

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Then fill in the correct values:
- Bool
- If true, uses orb_address as base to api and mqtt address using orb.live pattern. If false, requires you to add the corresponding addresses.
- Default value: `true`
- **backend_type**:
- **sink_backend_type**:
- Str
- Sink backend type
- Default value: `prometheus`
Expand Down
321 changes: 321 additions & 0 deletions python-test/features/integration_config_file_otel.feature

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@integration_config_files @AUTORETRY
Feature: Integration tests using agent provided via config file
Feature: Integration tests using agent with pktvisor as backend provided via config file


@private @auto_provision
Expand Down Expand Up @@ -79,7 +79,7 @@ Scenario: provisioning agent without specify pktvisor path to config file (confi
And the container logs contain the message "policy applied successfully" referred to each policy within 30 seconds
And remove the agent .yaml generated on each scenario

@smoke @config_file @pktvisor_configs @bla
@smoke @config_file @pktvisor_configs
Scenario: provisioning agent without specify pktvisor binary path and path to config file (config file - auto_provision=false)
Given the Orb user has a registered account
And the Orb user logs in
Expand Down
8 changes: 5 additions & 3 deletions python-test/features/steps/agent_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
return_api_put_response)
from behave import given, then, step
from hamcrest import *
import requests
from random import sample
import json
import random
from logger import Logger

log = Logger().logger_instance()
configs = TestConfig.configs()
agent_group_name_prefix = 'test_group_name_'
agent_group_description = "This is an agent group"
Expand Down Expand Up @@ -46,8 +47,8 @@ def create_agent_group_matching_agent(context, amount_of_agent_groups, amount_of
f"Agent:{context.agent}")
for group in range(int(amount_of_agent_groups)):
agent_group_name = agent_group_name_prefix + random_string()
agent_group_data = generate_group_with_valid_json(context.token, agent_group_name, group_description,
tags_to_group, context.agent_groups)
generate_group_with_valid_json(context.token, agent_group_name, group_description,
tags_to_group, context.agent_groups)


@step("{amount_of_agent_groups} Agent Group(s) is created with {orb_tags} orb tag(s) (lower case)")
Expand Down Expand Up @@ -535,6 +536,7 @@ def generate_group_with_valid_json(token, agent_group_name, group_description, t
"""
agent_group_data = create_agent_group(token, agent_group_name, group_description,
tags_to_group)
log.debug(f"Created agent group data: {agent_group_data}")
group_id = agent_group_data['id']
agent_groups[group_id] = agent_group_name

Expand Down
113 changes: 39 additions & 74 deletions python-test/features/steps/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,72 +385,20 @@ def provision_agent_using_config_file(context, backend_type, settings, provision
context.container_id = run_agent_config_file(context.agent_file_name, overwrite_default, paste_only_file)
if context.container_id not in context.containers_id.keys():
context.containers_id[context.container_id] = str(context.port)
log = f"web server listening on localhost:{context.port}"
agent_started, logs = get_logs_and_check(context.container_id, log, element_to_check="log")
assert_that(agent_started, equal_to(True), f"Log {log} not found on agent logs. Agent Name: {agent_name}.\n"
f"Logs:{logs}")
context.agent, is_agent_created = check_agent_exists_on_backend(context.token, agent_name, timeout=60)
logs = get_orb_agent_logs(context.container_id)
assert_that(is_agent_created, equal_to(True), f"Agent {agent_name} not found in /agents route."
f"\n Config File (json converted): {safe_config_file}."
f"\nLogs: {logs}.")
context.agent, are_tags_correct = get_agent_tags(context.token, context.agent['id'], tags_on_agent)
assert_that(are_tags_correct, equal_to(True), f"Agent tags created does not match with the required ones. Agent:"
f"{context.agent}. Tags that would be present: {tags_on_agent}.\n"
f"Agent Logs: {logs}")
assert_that(context.agent, is_not(None), f"Agent {agent_name} not correctly created. Logs: {logs}")
agent_id = context.agent['id']
existing_agents = get_agent(context.token, agent_id)
assert_that(len(existing_agents), greater_than(0), f"Agent not created. Logs: {logs}")
agent_status, context.agent = wait_until_expected_agent_status(context.token, agent_id, status)
assert_that(agent_status, is_(equal_to(status)),
f"Agent did not get '{status}' after 30 seconds, but was '{agent_status}'. \n"
f"Agent: {json.dumps(context.agent, indent=4)}. \n Logs: {logs}")


@step("an agent with otel backend is {provision} via a configuration file on port {port} "
"with {agent_tags} agent tags and has status {status}. [Overwrite default: {overwrite_default}. Paste only "
"file: {paste_only_file}]")
def provision_otel_backend_agent_using_config_file(context, provision, port, agent_tags, status, overwrite_default,
paste_only_file, **kwargs):
assert_that(provision, any_of(equal_to("self-provisioned"), equal_to("provisioned")), "Unexpected provision "
"attribute")
overwrite_default = overwrite_default.title()
paste_only_file = paste_only_file.title()
assert_that(overwrite_default, any_of("True", "False"), "Unexpected value for overwrite_default parameter.")
assert_that(paste_only_file, any_of("True", "False"), "Unexpected value for overwrite_default parameter.")
overwrite_default = eval(overwrite_default)
paste_only_file = eval(paste_only_file)
if provision == "provisioned":
auto_provision = "false"
orb_cloud_mqtt_id = context.agent['id']
orb_cloud_mqtt_key = context.agent['key']
orb_cloud_mqtt_channel_id = context.agent['channel_id']
agent_name = context.agent['name']
if backend_type == "pktvisor":
log_message = f"web server listening on localhost:{context.port}"
agent_started, logs, log_line = get_logs_and_check(context.container_id, log_message, element_to_check="log")
assert_that(agent_started, equal_to(True), f"Log {log_message} not found on agent logs."
f" Agent Name: {agent_name}. Logs:{logs}")
else:
auto_provision = "true"
orb_cloud_mqtt_id = None
orb_cloud_mqtt_key = None
orb_cloud_mqtt_channel_id = None
agent_name = f"{agent_name_prefix}{random_string(10)}"
orb_url = configs.get('orb_url')
context.port = return_port_by_availability(context, True)
otel_configs = {"config_file": "default"}
if 'otel_config' in kwargs.keys():
if "config_file" in kwargs['pkt_config'].keys():
otel_configs["config_file"] = kwargs['pkt_config']["config_file"]
context.agent_file_name, tags_on_agent, safe_config_file = \
create_agent_with_otel_backend_config_file(context.token, agent_name, agent_tags, orb_url, context.port,
context.agent_groups, auto_provision,
orb_cloud_mqtt_id, orb_cloud_mqtt_key, orb_cloud_mqtt_channel_id,
overwrite_default, paste_only_file, otel_configs['config_file'])
context.container_id = run_agent_config_file(context.agent_file_name, overwrite_default, paste_only_file)
if context.container_id not in context.containers_id.keys():
context.containers_id[context.container_id] = str(context.port)
msg = f"Starting GRPC server"
agent_started, logs = get_logs_and_check(context.container_id, msg, element_to_check="msg")
assert_that(agent_started, equal_to(True), f"Log {msg} not found on agent logs. Agent Name: {agent_name}.\n"
f"Logs:{logs}")
log_message = f"Started receiver for OTLP in orb-agent"
agent_started, logs, log_line = get_logs_and_check(context.container_id, log_message, element_to_check="msg")
assert_that(agent_started, equal_to(True), f"Log {log_message} not found on agent logs."
f" Agent Name: {agent_name}. Logs:{logs}")
assert_that(str(log_line.get("port", "")), equal_to(str(context.port)), f"Log {log_message} related to port "
f"{context.port} not found on agent "
f"logs. Logs: {logs}")

context.agent, is_agent_created = check_agent_exists_on_backend(context.token, agent_name, timeout=60)
logs = get_orb_agent_logs(context.container_id)
assert_that(is_agent_created, equal_to(True), f"Agent {agent_name} not found in /agents route."
Expand Down Expand Up @@ -626,8 +574,7 @@ def wait_until_expected_backend_state(token, agent_id, backend, state, event=Non
:param (obj) event: threading.event
"""

agent = get_agent(token, agent_id)
backend_state = agent["last_hb_data"]["backend_state"][backend]['state']
backend_state, agent = get_backend_info(token, agent_id, backend, "state")
if backend_state == state:
event.set()
return backend_state, agent
Expand All @@ -647,17 +594,35 @@ def wait_until_expected_backend_error(token, agent_id, backend, error, event=Non
:param (obj) event: threading.event
"""

agent = get_agent(token, agent_id)
if 'error' in agent["last_hb_data"]["backend_state"][backend].keys():
backend_error = agent["last_hb_data"]["backend_state"][backend]['error']
if backend_error == error:
event.set()
return backend_error, agent
backend_error, agent = get_backend_info(token, agent_id, backend, "error")
if backend_error == error:
event.set()
return backend_error, agent
else:
return None, agent


def get_backend_info(token, agent_id, backend, info):
"""
Get the backend state for a specific agent.

:param str token: Access token for authentication
:param str agent_id: ID of the agent
:param str backend: Name of the agent backend
:param str info: Info requested
:return: The agent backend required info
:rtype: str or None
"""
agent = get_agent(token, agent_id)
try:
last_hb_data = agent.get("last_hb_data", {})
backend_info = last_hb_data.get("backend_state", {}).get(backend, {}).get(info)
return backend_info, agent
except Exception as e:
log.error(f"Error getting backend {info}: {e}. Agent: {agent}")
return None, agent


def get_agent(token, agent_id, expected_status_code=200):
"""
Gets an agent from Orb control plane
Expand Down Expand Up @@ -783,7 +748,7 @@ def edit_agent(token, agent_id, name, tags, expected_status_code=200):

json_request = {"name": name, "orb_tags": tags, "validate_only": False}
status_code, response = return_api_put_response(orb_url + '/api/v1/agents/' + agent_id, request_body=json_request,
token=token, verify=verify_ssl_bool)
token=token, verify=verify_ssl_bool)

assert_that(status_code, equal_to(expected_status_code),
'Request to edit agent failed with status=' + str(status_code) + ":" + str(response))
Expand Down
4 changes: 2 additions & 2 deletions python-test/features/steps/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def _read_configs():
assert_that(configs.get('password'), has_length(greater_than_or_equal_to(8)),
'Orb password must be at least 8 digits')

configs['backend_type'] = configs.get("backend_type", "prometheus")
if configs['backend_type'] == "otlphttp":
configs['sink_backend_type'] = configs.get("sink_backend_type", "prometheus")
if configs['sink_backend_type'] == "otlphttp":
assert_that(configs.get('otlp_publisher_username'), not_none(), 'No otlp_publisher username was provided!')
assert_that(configs.get('otlp_publisher_username'), not_(""), 'No otlp_publisher username was provided!')

Expand Down
Loading
Loading