Skip to content

Commit b643e8f

Browse files
committed
Fix ProxySQL rule sanity check to support username-based routing
Kolla Ansible now generates ProxySQL query rules not only based on the schema name (schemaname), but also on the username. This is needed to properly route queries that are executed before a database schema is selected, such as `SET AUTOCOMMIT` or `ROLLBACK`. To support this, the ProxySQL config sanity check must correctly deduplicate rules based on both `schemaname` and `username`, and avoid false positives when both types are used simultaneously. This change adjusts the logic in `kolla_proxysql_config_sync` to: - recognize rules by key `schema:<schemaname>` or `user:<username>` - assign unique rule IDs only to truly distinct rules - log and skip exact duplicates with appropriate context This fix is required to support the Kolla Ansible patch below. Needed-By: https://review.opendev.org/c/openstack/kolla-ansible/+/951599 Change-Id: I99acd1984ee555a5b6c731e6ee460a33677060d0
1 parent 9a5315e commit b643e8f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

docker/proxysql/kolla_proxysql_config_sync

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,24 @@ class ProxySQLConfig:
9393
rules = list()
9494
rule_id = 1
9595
for rule in self.config['mysql_query_rules']:
96-
if rule['schemaname'] not in rules_added:
97-
rules_added.append(rule['schemaname'])
96+
if 'schemaname' in rule:
97+
key = f"schema:{rule['schemaname']}"
98+
elif 'username' in rule:
99+
key = f"user:{rule['username']}"
100+
else:
101+
LOG.warning(
102+
f"Rule without schemaname or username found, skipping: {rule}"
103+
)
104+
continue
105+
106+
if key not in rules_added:
107+
rules_added.append(key)
98108
rule['rule_id'] = rule_id
99109
rules.append(rule)
100110
rule_id += 1
101111
else:
102-
LOG.warning("Rule witch schemaname {} already exist, ignoring."
103-
.format(rule['schemaname']))
112+
LOG.warning("Duplicate rule for {}, ignoring.".format(key))
113+
104114
self.config['mysql_query_rules'] = rules
105115

106116
def _write_dict(self, key, value):

0 commit comments

Comments
 (0)