maksaska commented on code in PR #13575: URL: https://github.com/apache/ignite/pull/13575#discussion_r4145041571
########## modules/ducktests/tests/checks/utils/check_jmx_utils.py: ########## @@ -0,0 +1,124 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Checks the MBean name pattern of a metric registry. + +The pattern is grepped against the MBean list of a node, so it is checked here the same way: +the match has to cover the WHOLE object name, since that name is what the following +'get -b <name>' is issued against. Every case runs through Python's re and, where a grep is +installed, through 'grep -E' itself - the pattern is an ERE, not a Python regular expression. +""" +import re +import shutil +import subprocess + +import pytest + +from ignitetest.services.utils.jmx_utils import metric_registry_pattern + +# MBean names as a node prints them: the properties are ordered alphabetically, which puts +# the instance name between the group and the name. +PREFIX = "org.apache:clsLdr=3e2a56ab,group=%s,igniteInstanceName=ducker01,name=%s" +NO_GROUP_PREFIX = "org.apache:clsLdr=3e2a56ab,igniteInstanceName=ducker01,name=%s" + +GREP = shutil.which("grep") + + +def python_grep(pattern, negative_pattern, mbean_name): + """ + :return: The part of the name the patterns leave, as 'grep -E -o | grep -E -v' would return it. + """ + match = re.search(pattern, mbean_name) + + if not match or (negative_pattern and re.search(negative_pattern, match.group())): + return None + + return match.group() + + +def real_grep(tmp_path, pattern, negative_pattern, mbean_name): + """ + :return: The same as :func:`python_grep`, but produced by 'grep -E' itself. The patterns go + through files, since a quote in a command line argument does not survive Windows. + """ + def grep(flag, grep_pattern, text): + pattern_file = tmp_path / f"pattern{flag}" + pattern_file.write_bytes((grep_pattern + "\n").encode()) + + return subprocess.run([GREP, "-E", flag, "-f", str(pattern_file)], input=text.encode(), + capture_output=True).stdout.decode() + + out = grep("-o", pattern, mbean_name + "\n") + + if out and negative_pattern: + out = grep("-v", negative_pattern, out) + + return out.strip() or None + + +# (registry, MBean name, whether the registry's pattern must match that name) +CASES = [ Review Comment: Nope. It's just a list of different bean formats. I don't expect to update CASES for each unique cache name. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
