Skip to content

Commit

Permalink
IGNITE-20719 [ducktests] Allow CDC tests work with opencensus HTTP me…
Browse files Browse the repository at this point in the history
…trics exporter (#11010)
  • Loading branch information
skorotkov authored Nov 3, 2023
1 parent 27ed13a commit abdfc99
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ private StandaloneGridKernalContext startStandaloneKernal() throws IgniteChecked

return cfg;
}

/** {@inheritDoc} */
@Override public String igniteInstanceName() {
return config().getIgniteInstanceName();
}
};

kctx.resource().setSpringContext(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"""
This module contains Ignite CDC utility (ignite-cdc.sh) wrapper.
"""
import re
import signal
from copy import deepcopy

from ignitetest.services.utils.ignite_spec import envs_to_exports
from ignitetest.services.utils.jvm_utils import JvmProcessMixin
Expand All @@ -28,7 +30,7 @@ class IgniteCdcUtility(JvmProcessMixin):
Ignite CDC utility (ignite-cdc.sh) wrapper.
"""
BASE_COMMAND = "ignite-cdc.sh"
JAVA_CLASS = "org.apache.ignite.startup.cmdline.CdcCommandLineStartup"
APP_SERVICE_CLASS = "org.apache.ignite.startup.cmdline.CdcCommandLineStartup"

def __init__(self, cluster):
self.cluster = cluster
Expand All @@ -44,9 +46,10 @@ def __start(node):
raw_output = node.account.ssh_capture(
self.__form_cmd(f"{self.BASE_COMMAND} -v {self.cluster.config_file}"))

code, _ = self.__parse_output(raw_output)
code, output = self.__parse_output(raw_output)

self.logger.debug(f"{self.__service_node_id(node)}: {self.BASE_COMMAND} finished with exit code: {code}")
self.logger.debug(f"{self.__service_node_id(node)}: {self.BASE_COMMAND} finished with exit code: {code}"
f"; output: {output}" if code != 0 else "")

self.logger.info(f"{self.cluster.service_id}: starting {self.BASE_COMMAND} ...")

Expand All @@ -59,7 +62,7 @@ def stop(self, force_stop=False):
def __stop(node):
self.logger.info(f"{self.__service_node_id(node)}: stopping {self.BASE_COMMAND}")

pids = self.pids(node, self.JAVA_CLASS)
pids = self.pids(node, self.APP_SERVICE_CLASS)

for pid in pids:
node.account.signal(pid, signal.SIGKILL if force_stop else signal.SIGTERM, allow_fail=False)
Expand All @@ -68,13 +71,27 @@ def __stop(node):

self.cluster.exec_on_nodes_async(self.cluster.nodes, __stop)

@property
def nodes(self):
return self.cluster.nodes

def __service_node_id(self, node):
return f"{self.cluster.service_id} node {self.cluster.idx(node)} on {node.account.hostname}"

def __form_cmd(self, cmd):
envs = self.cluster.spec.envs()

envs["CDC_JVM_OPTS"] = f"\"{' '.join(self.cluster.spec.jvm_opts)}\""
jvm_opts = deepcopy(self.cluster.spec.jvm_opts)

def replace_ports(opt):
for port in ["opencensus.metrics.port", "com.sun.management.jmxremote.port"]:
opt = re.sub(f"-D{port}=(\\d+)", lambda x: f"-D{port}={int(x.group(1)) + 1}", opt)

return opt

cdc_jvm_opts = list(map(lambda opt: replace_ports(opt), jvm_opts))

envs["CDC_JVM_OPTS"] = f"\"{' '.join(cdc_jvm_opts)}\""

return f"{envs_to_exports(envs)} bash " + self.cluster.script(cmd)

Expand Down
13 changes: 10 additions & 3 deletions modules/ducktests/tests/ignitetest/services/utils/ignite_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,29 @@ def extend_config(self, config):
"""
if config.service_type == IgniteServiceType.NODE:
if is_opencensus_metrics_enabled(self.service):
config = configure_opencensus_metrics(config, self.service.context.globals)
config = configure_opencensus_metrics(config, self.service.context.globals, self)

if is_jmx_metrics_enabled(self.service):
config = configure_jmx_metrics(config)

if (is_opencensus_metrics_enabled(self.service) or
is_jmx_metrics_enabled(self.service)):
config = config._replace(ignite_instance_name=self._test_id)

ignite_instance_name = self._test_id

if config.ignite_instance_name:
ignite_instance_name = ignite_instance_name[:250 - 2 - len(config.ignite_instance_name)] +\
"--" + config.ignite_instance_name

config = config._replace(ignite_instance_name=ignite_instance_name)

config = config.prepare_ssl(self.service.globals, self.service.shared_root)

return config

@property
def _test_id(self):
return re.sub("^[0-9A-Fa-f]+@ignitetest\\.tests\\.", "", self.service.context.test_name).replace("=", ".")[:255]
return re.sub("^[0-9A-Fa-f]+@ignitetest\\.tests\\.", "", self.service.context.test_name).replace("=", ".")[:250]

def __home(self, product=None):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def is_opencensus_metrics_enabled(service):
service.context.globals[METRICS_KEY][OPENCENSUS_KEY_NAME].get(ENABLED, False)


def configure_opencensus_metrics(config, _globals):
def configure_opencensus_metrics(config, _globals, spec):
"""
Adds OpenCensus metrics exporter beans into the Ignite node configuration
Expand All @@ -72,7 +72,10 @@ def configure_opencensus_metrics(config, _globals):
period=metrics_params.period,
sendInstanceName=True))

if not any((bean[1].name and bean[1].name == OPENCENSUS_NAME) for bean in config.ext_beans):
if not any("opencensus.metrics.port" in jvm_opt for jvm_opt in spec.jvm_opts):
spec.jvm_opts.append("-Dopencensus.metrics.port=%d" % metrics_params.port)

if not any(bean[0] == OPENCENSUS_TEMPLATE_FILE for bean in config.ext_beans):
config.ext_beans.append((OPENCENSUS_TEMPLATE_FILE, metrics_params))

return config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"/>

{{ ignite_configuration.apply(config, service) }}

{{ misc_utils.ext_beans(config) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@

{% macro bean(bean_object) %}
{% if bean_object.properties | length > 0 or bean_object.constructor_args | length > 0 %}
{% if bean_object.id != "" %}
<bean id="{{ bean_object.id }}" class="{{ bean_object }}">
{% else %}
<bean class="{{ bean_object }}">
{% endif %}
{% for name, value in bean_object.properties.items() %}
{% if value is string or value is number or value is boolean %}
<property name="{{ name | snake_to_camel }}" value="{{ value }}"/>
Expand Down Expand Up @@ -86,6 +90,6 @@
{% endfor %}
</bean>
{% else %}
<bean class="{{ bean_object }}"/>
<bean id="{{ bean_object.id }}" class="{{ bean_object }}"/>
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<bean class="io.prometheus.client.exporter.HTTPServer">
<constructor-arg type="java.lang.String" value="{{ config.local_host }}"/>
<constructor-arg type="int" value="{{ metrics.port }}"/>
<constructor-arg type="int" value="${opencensus.metrics.port}"/>
<constructor-arg type="boolean" value="true"/>
</bean>

Expand Down
6 changes: 4 additions & 2 deletions modules/ducktests/tests/ignitetest/utils/bean.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class Bean:
Hashable to be stored in a set.
"""
def __init__(self, class_name, constructor_args=None, **kwargs):
def __init__(self, class_name, bean_id="", constructor_args=None, **kwargs):
"""
:param class_name: bean class name
:param bean_id: optional bean id
:param constructor_args: optional list of constructor parameters
:param kwargs: properties name / value pairs
"""
Expand All @@ -34,11 +35,12 @@ def __init__(self, class_name, constructor_args=None, **kwargs):
else:
self.constructor_args = constructor_args

self.id = bean_id
self.class_name = class_name
self.properties = kwargs

def __eq__(self, other):
return self.class_name == other.class_name
return other is not None and self.class_name == other.class_name

def __hash__(self):
return hash(self.class_name)
Expand Down

0 comments on commit abdfc99

Please sign in to comment.