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

Refactor[BMQ,MQB,CI]: various improvements #604

Merged
merged 1 commit into from
Feb 10, 2025
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
5 changes: 3 additions & 2 deletions .github/workflows/ext/check_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
import glob
from pathlib import Path
import re
from typing import List


def load_license_template(path: str) -> list[re.Pattern]:
def load_license_template(path: str) -> List[re.Pattern]:
with open(path, "r") as f:
lines = f.readlines()

return [re.compile(line) for line in lines]


def check_license(fpath: str, expressions: list[re.Pattern]) -> bool:
def check_license(fpath: str, expressions: List[re.Pattern]) -> bool:
with open(fpath, "r") as f:
ln = f.readline()
if ln.startswith("#!"): # skip possible shebang at the beginning of the file
Expand Down
1 change: 0 additions & 1 deletion docker/cluster/config/bmqbrkrcfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"BMQ*:INFO:green",
"MQB*:INFO:green",
"SIM*:INFO:gray",
"DMC*:INFO:yellow",
"BAEA.PERFORMANCEMONITOR:INFO:white"
],
"syslog": {
Expand Down
1 change: 0 additions & 1 deletion docker/single-node/config/bmqbrkrcfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"BMQ*:INFO:green",
"MQB*:INFO:green",
"SIM*:INFO:gray",
"DMC*:INFO:yellow",
"BAEA.PERFORMANCEMONITOR:INFO:white"
],
"syslog": {
Expand Down
1 change: 0 additions & 1 deletion src/applications/bmqbrkr/etc/bmqbrkrcfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"BMQ*:INFO:green",
"MQB*:INFO:green",
"SIM*:INFO:gray",
"DMC*:INFO:yellow",
"BAEA.PERFORMANCEMONITOR:INFO:white"
],
"syslog": {
Expand Down
1 change: 0 additions & 1 deletion src/applications/bmqtool/m_bmqtool_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ void Application::setUpLog()
// logged, so the console observer should print any logs it receives.

d_consoleObserver.setLogFormat(logFormat)
.setCategoryColor("DMC*", "gray")
.setCategoryColor("BMQ*", "green")
.setCategoryColor("MQB*", "green")
.setCategoryColor("APPLICATION", "yellow")
Expand Down
18 changes: 9 additions & 9 deletions src/groups/bmq/bmqu/bmqu_stringutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ namespace {
/// Rearrange characters in place within the contiguous sequence indicated
/// by the specified `[begin, end)` such that all repeated runs of any
/// characters belonging to the set indicated by the specified
/// `[whitelistBegin, whitelistEnd)` are reduced to one appearance of the
/// character. Return a pointer to the new end of the sequence. Note that
/// `[allowlistBegin, allowlistEnd)` are reduced to one appearance of the
/// character. Return a pointer to the new end of the sequence. Note that
/// this function is similar to `bsl::remove_if` with a special predicate.
char* removeIfPrecededBySame(char* begin,
char* end,
const char* whitelistBegin,
const char* whitelistEnd)
const char* allowlistBegin,
const char* allowlistEnd)
{
bsl::bitset<UCHAR_MAX + 1> whitelist;
for (const char* iter = whitelistBegin; iter != whitelistEnd; ++iter) {
whitelist[static_cast<unsigned char>(*iter)] = true;
bsl::bitset<UCHAR_MAX + 1> allowlist;
for (const char* iter = allowlistBegin; iter != allowlistEnd; ++iter) {
allowlist[static_cast<unsigned char>(*iter)] = true;
}

char* result = begin;
for (; begin != end; ++begin) {
// If this is *not* a repeated item from the whitelist, then copy it
// If this is *not* a repeated item from the allowlist, then copy it
// into its final place.
if (!whitelist[static_cast<unsigned char>(*begin)] ||
if (!allowlist[static_cast<unsigned char>(*begin)] ||
*begin != *(begin - 1)) {
*result++ = *begin;
}
Expand Down
6 changes: 3 additions & 3 deletions src/groups/mqb/mqba/mqba_sessionnegotiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
// mode waits for incoming connection; when one is established, it will
// schedule a read with a short timeout ('k_NEGOTIATION_READTIMEOUT' below).
// If a valid negotiation message is received, it will reply with its identity
// and create a session. If either the read timesout, the received negotiation
// message is invalid, or the received identity is marked as blacklisted, the
// negotiation will fail and the connection will be closed.
// and create a session. If either the read times out, the received
// negotiation message is invalid, or the received identity is marked as not
// allowed, the negotiation will fail and the connection will be closed.
//
/// Session creation logic
///----------------------
Expand Down
2 changes: 1 addition & 1 deletion src/integration-tests/test_admin_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def post_n_msgs(
for _ in range(task.num):
res = producer.post(task.uri, payload=["msg"], wait_ack=True)
assert Client.e_SUCCESS == res
producer.close(task.uri)
producer.close(task.uri, succeed=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This close was nonblocking, it was possible to execute the next command before producer was actually closed


if posted is not None:
if task.uri in posted:
Expand Down
1 change: 0 additions & 1 deletion src/python/blazingmq/dev/configurator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ class Proto:
"BMQ*:INFO:green",
"MQB*:INFO:green",
"SIM*:INFO:gray",
"DMC*:INFO:yellow",
"BAEA.PERFORMANCEMONITOR:INFO:white",
],
syslog=mqbcfg.SyslogConfig(
Expand Down
51 changes: 28 additions & 23 deletions src/python/blazingmq/dev/it/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

logger = logging.getLogger(__name__)

CORE_PATTERN_PATH = "/proc/sys/kernel/core_pattern"


def _match_broker(broker, **kw):
datacenter = kw.get("datacenter", None)
Expand Down Expand Up @@ -205,29 +207,7 @@ def stop(self):

self.last_known_leader = None
bad_exit = False
cores_dir = None

if self.copy_cores is not None:
try:
with open("/proc/sys/kernel/core_pattern") as core_pattern_file:
pattern = core_pattern_file.readline().strip()
if "%p" in pattern:
cores_dir = Path(pattern).parent
if not cores_dir.is_absolute():
self._logger.warning(
"core pattern '%s' is not an absolute path, cores will not be saved",
pattern,
)
cores_dir = None
else:
self._logger.warning(
"core pattern '%s' does not contain process id, cores will not be saved",
pattern,
)
except FileExistsError:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a wrong type of error

self._logger.warning(
"/proc/sys/kernel/core_pattern does not exist, cores will not be saved"
)
cores_dir = None if self.copy_cores is None else self._find_cores_dir()

for process in processes:
process.wait()
Expand Down Expand Up @@ -685,6 +665,31 @@ def reconfigure_domain(
###########################################################################
# Internals

def _find_cores_dir(self) -> Optional[Path]:
try:
with open(CORE_PATTERN_PATH) as core_pattern_file:
pattern = core_pattern_file.readline().strip()
if "%p" in pattern:
cores_dir = Path(pattern).parent
if cores_dir.is_absolute():
return cores_dir

self._logger.warning(
"core pattern '%s' is not an absolute path, cores will not be saved",
pattern,
)
else:
self._logger.warning(
"core pattern '%s' does not contain process id, cores will not be saved",
pattern,
)
except FileNotFoundError:
self._logger.warning(
"%s does not exist, cores will not be saved", CORE_PATTERN_PATH
)

return None

def _start_broker(self, broker: cfg.Broker, array, cluster_name):
if broker.name in self._processes:
raise RuntimeError(f'node "{broker.name}" is already running')
Expand Down
3 changes: 1 addition & 2 deletions src/python/blazingmq/dev/it/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
import tempfile
from enum import IntEnum
from pathlib import Path
from typing import Callable, List, Optional, Tuple
from collections.abc import Generator, Iterator
from typing import Callable, List, Optional, Tuple, Iterator
import psutil

import pytest
Expand Down
2 changes: 1 addition & 1 deletion src/python/blazingmq/dev/it/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def close(self, *args, **kwargs):
_T = TypeVar("_T")


class ListContextManager(list[_T]):
class ListContextManager(List[_T]):
def __enter__(self):
return self

Expand Down
Loading