forked from elastic/integrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MySQL] Add replica status data stream (elastic#10344)
* add replica status data stream * update data stream * update changelog * Address review comment * address review comments * address review comment * address review comments
- Loading branch information
1 parent
2867e89
commit 8b03fbf
Showing
31 changed files
with
2,731 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM mysql:8.0.35 | ||
ENV MYSQL_ROOT_PASSWORD=111 | ||
COPY entrypoint-master.sh /entrypoint-master.sh | ||
RUN chmod +x /entrypoint-master.sh | ||
ENTRYPOINT ["/entrypoint-master.sh"] | ||
CMD ["mysqld"] |
14 changes: 14 additions & 0 deletions
14
packages/mysql/_dev/deploy/docker/master/conf/mysql.conf.cnf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[mysqld] | ||
|
||
skip-name-resolve | ||
default_authentication_plugin = mysql_native_password | ||
|
||
server-id = 1 | ||
log_bin = mysql-bin | ||
binlog_format = ROW | ||
binlog_do_db = mysql | ||
|
||
gtid_mode = ON | ||
enforce_gtid_consistency = ON | ||
log_slave_updates = ON | ||
tls_version = TLSv1.2,TLSv1.3 |
30 changes: 30 additions & 0 deletions
30
packages/mysql/_dev/deploy/docker/master/entrypoint-master.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo "Starting MySQL master..." | ||
|
||
# Initialize and start MySQL server using the default entrypoint script | ||
docker-entrypoint.sh mysqld & | ||
|
||
# Wait for the master database to be ready | ||
echo "Waiting for MySQL to be ready..." | ||
while ! mysqladmin ping -h "127.0.0.1" --silent; do | ||
echo "MySQL master is not up yet..." | ||
sleep 2 | ||
done | ||
echo "MySQL master is ready." | ||
|
||
# Create replication user on the master | ||
# Check if the replication user already exists | ||
user_exists=$(mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "SELECT 1 FROM mysql.user WHERE user = 'mydb_replica_user';" -ss) | ||
if [ -z "$user_exists" ]; then | ||
echo "Creating replication user..." | ||
priv_stmt='CREATE USER "mydb_replica_user"@"%" IDENTIFIED BY "mydb_replica_pwd"; GRANT REPLICATION SLAVE ON *.* TO "mydb_replica_user"@"%"; FLUSH PRIVILEGES;' | ||
# docker-compose exec mysql_master mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "$priv_stmt" | ||
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "$priv_stmt" | ||
else | ||
echo "Replication user already exists. Skipping user creation." | ||
fi | ||
|
||
# Now, keep the script running to prevent the container from exiting | ||
wait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
# Health check script for MySQL | ||
|
||
# Use the MYSQL_ROOT_PASSWORD environment variable or a default password | ||
MYSQL_PWD=${MYSQL_ROOT_PASSWORD:-defaultpassword} | ||
|
||
# Check if MySQL is ready | ||
mysqladmin ping -h localhost -u root --silent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Note, by default mysql root does not have a password. You need to restart a server to bring MYSQL_ROOT_PASSWORD working. Use "docker-compose restart" command. | ||
MYSQL_ROOT_PASSWORD=111 | ||
MYSQL_PORT=3306 | ||
MYSQL_USER=mydb_user | ||
MYSQL_PASSWORD=mydb_pwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM mysql:8.0.35 | ||
ENV MYSQL_ROOT_PASSWORD=111 | ||
COPY entrypoint-replica.sh /entrypoint-replica.sh | ||
COPY grant-permissions.sql /docker-entrypoint-initdb.d/ | ||
COPY healthcheck.sh /healthcheck.sh | ||
RUN chmod +x /healthcheck.sh | ||
RUN chmod +x /entrypoint-replica.sh | ||
ENTRYPOINT ["/entrypoint-replica.sh"] | ||
CMD ["mysqld"] |
13 changes: 13 additions & 0 deletions
13
packages/mysql/_dev/deploy/docker/replica/conf/mysql.conf.cnf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[mysqld] | ||
|
||
skip-name-resolve | ||
default_authentication_plugin = mysql_native_password | ||
|
||
server-id = 2 | ||
log_bin = mysql-bin | ||
binlog_do_db = mysql | ||
|
||
gtid_mode = ON | ||
enforce_gtid_consistency = ON | ||
log_slave_updates = ON | ||
tls_version = TLSv1.2,TLSv1.3 |
63 changes: 63 additions & 0 deletions
63
packages/mysql/_dev/deploy/docker/replica/entrypoint-replica.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo "Starting MySQL slave..." | ||
|
||
# Start the MySQL server in the background | ||
docker-entrypoint.sh mysqld & | ||
|
||
# Wait for the slave database to be ready | ||
echo "Waiting for MySQL to be ready..." | ||
while ! mysqladmin ping -h "127.0.0.1" --silent; do | ||
echo "MySQL slave is not up yet..." | ||
sleep 2 | ||
done | ||
echo "MySQL slave is ready." | ||
|
||
# Configure the slave to start replication | ||
echo "Configuring slave to start replication..." | ||
# Wait for the master to be ready and for its logs to be available | ||
MASTER_LOGS_AVAILABLE=false | ||
for i in {1..30}; do | ||
MS_STATUS=$(mysql -h "$MYSQL_MASTER_HOST" -P 3306 -u root -p"$MYSQL_ROOT_PASSWORD" -e "SHOW MASTER STATUS;") | ||
CURRENT_LOG=$(echo "$MS_STATUS" | awk 'NR==2 {print $1}') | ||
CURRENT_POS=$(echo "$MS_STATUS" | awk 'NR==2 {print $2}') | ||
if [ -n "$CURRENT_LOG" ] && [ -n "$CURRENT_POS" ]; then | ||
MASTER_LOGS_AVAILABLE=true | ||
break | ||
else | ||
echo "Waiting for master logs to be available..." | ||
sleep 2 | ||
fi | ||
done | ||
|
||
if [ "$MASTER_LOGS_AVAILABLE" = false ]; then | ||
echo "Failed to obtain master log file and position." | ||
exit 1 | ||
fi | ||
|
||
echo "Master status obtained. Current log: $CURRENT_LOG, Current position: $CURRENT_POS." | ||
|
||
# Reset the slave to ensure a clean replication setup | ||
echo "Resetting the slave..." | ||
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "STOP SLAVE; RESET SLAVE ALL;" | ||
|
||
# Prepare the CHANGE MASTER TO command | ||
start_slave_stmt="CHANGE MASTER TO MASTER_HOST='$MYSQL_MASTER_HOST', MASTER_USER='mydb_replica_user', MASTER_PASSWORD='mydb_replica_pwd', MASTER_LOG_FILE='$CURRENT_LOG', MASTER_LOG_POS=$CURRENT_POS; START SLAVE;" | ||
|
||
# Display the command that will be executed | ||
echo "Running the following command to start replication: $start_slave_stmt" | ||
|
||
# Run the CHANGE MASTER TO command | ||
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "$start_slave_stmt" || { | ||
echo "Failed to start replication. Entering sleep mode for debugging." | ||
tail -f /dev/null # This will keep the container running indefinitely | ||
} | ||
|
||
# Verify slave status | ||
echo "Verifying slave status..." | ||
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "GRANT REPLICATION CLIENT ON *.* TO 'mydb_replica_user'@'%'; FLUSH PRIVILEGES;" | ||
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "SHOW SLAVE STATUS \G" | ||
|
||
# Now, keep the script running to prevent the container from exiting | ||
wait |
2 changes: 2 additions & 0 deletions
2
packages/mysql/_dev/deploy/docker/replica/grant-permissions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GRANT REPLICATION CLIENT ON *.* TO 'mydb_replica_user'@'%'; | ||
FLUSH PRIVILEGES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
# Health check script for MySQL | ||
|
||
# Use the MYSQL_ROOT_PASSWORD environment variable or a default password | ||
MYSQL_PWD=${MYSQL_ROOT_PASSWORD:-defaultpassword} | ||
|
||
# Check if MySQL is ready | ||
mysqladmin ping -h localhost -u root --silent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Note, by default mysql root does not have a password. You need to restart a server to bring MYSQL_ROOT_PASSWORD working. Use "docker-compose restart" command. | ||
MYSQL_ROOT_PASSWORD=111 | ||
MYSQL_PORT=3306 | ||
MYSQL_USER=mydb_replica_user | ||
MYSQL_PASSWORD=mydb_replica_pwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file modified
0
packages/mysql/data_stream/galera_status/_dev/test/system/test-default-config.yml
100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions
2
packages/mysql/data_stream/replica_status/_dev/test/pipeline/test-common-config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dynamic_fields: | ||
"event.ingested": ".*" |
Oops, something went wrong.