This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-showcase.git
The following commit(s) were added to refs/heads/main by this push:
new 442c1aa Optimize the mysql case by using sidecar for metrics exporter
and fluent bit (#81)
442c1aa is described below
commit 442c1aaabc71a8fbfce60e34b8295199fc2d3ae7
Author: kezhenxu94 <[email protected]>
AuthorDate: Fri Sep 30 13:22:57 2022 +0800
Optimize the mysql case by using sidecar for metrics exporter and fluent
bit (#81)
---
.../fluent-bit.yaml | 164 +--------------------
.../platform/kubernetes/feature-mysql/mysql.yaml | 110 +++++++++-----
.../kubernetes/feature-mysql/open-telemetry.yaml | 3 +-
docs/readme.md | 3 +-
4 files changed, 77 insertions(+), 203 deletions(-)
diff --git a/deploy/platform/kubernetes/feature-slowsql-mysql/fluent-bit.yaml
b/deploy/platform/kubernetes/feature-mysql/fluent-bit.yaml
similarity index 57%
rename from deploy/platform/kubernetes/feature-slowsql-mysql/fluent-bit.yaml
rename to deploy/platform/kubernetes/feature-mysql/fluent-bit.yaml
index b2a6743..6a48c40 100644
--- a/deploy/platform/kubernetes/feature-slowsql-mysql/fluent-bit.yaml
+++ b/deploy/platform/kubernetes/feature-mysql/fluent-bit.yaml
@@ -21,9 +21,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
- name: fluent-bit-slowsql-mysql
+ name: slowsql-mysql-fluent-bit
labels:
- app: fluent-bit-slowsql-mysql
+ app: slowsql-mysql-fluent-bit
data:
fluent-bit-conf: |
[SERVICE]
@@ -89,7 +89,7 @@ data:
re1["layer"] = "MYSQL"
record["layer"] = "MYSQL"
id1,_ = string.find(arr[2],"Id:")
- service = os.getenv("SW_SERVICE")
+ service = "mysql::"..os.getenv("SW_SERVICE")
record["service"]=service
re1["service"]= service
@@ -170,161 +170,3 @@ data:
rule "second_state" "^(# User@Host.*)" "third_state"
rule "third_state" "^(# Query_time: .*)" "statement"
rule "statement" "^\w+.*" "statement"
-
- mysqld-config-file: |
- [mysqld]
- init_connect='SET NAMES utf8'
- slow_query_log=ON
- event_scheduler=ON
- long_query_time=1
- slow_query_log_file=/data/slow.log
- [client]
- default-character-set=utf8
- [mysql]
- default-character-set=utf8
-
----
-apiVersion: v1
-kind: ConfigMap
-metadata:
- name: mock-sql-slowsql-mysql
- labels:
- app: mysql-load
-data:
- mock-sql: |
- CREATE DATABASE IF NOT EXISTS test;
- USE test;
- CREATE TABLE IF NOT EXISTS `t1`(
- `te1` VARCHAR(100) NOT NULL
- )ENGINE=InnoDB DEFAULT CHARSET=utf8;
- SET GLOBAL event_scheduler = 1;
-
- CREATE EVENT `event_1`
- ON SCHEDULE EVERY 1 SECOND
- DO INSERT INTO t1 values('test');
-
- CREATE EVENT `event_2`
- ON SCHEDULE EVERY 1 SECOND
- DO UPDATE t1 SET `te1` = 1;
-
- CREATE EVENT `event_3`
- ON SCHEDULE EVERY 1 SECOND
- DO DELETE FROM t1;
-
- CREATE EVENT `event_4`
- ON SCHEDULE EVERY 1 SECOND
- DO COMMIT;
-
- CREATE EVENT `event_5`
- ON SCHEDULE EVERY 1 SECOND
- DO SELECT SLEEP(3);
-
----
-apiVersion: v1
-kind: Service
-metadata:
- name: slowsql-mysql
-spec:
- selector:
- app: slowsql-mysql
- ports:
- - protocol: TCP
- port: 3306
-
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
- name: slowsql-mysql
- labels:
- app: slowsql-mysql
-spec:
- replicas: 1
- selector:
- matchLabels:
- app: slowsql-mysql
- template:
- metadata:
- labels:
- app: slowsql-mysql
- annotations:
- sidecar.istio.io/inject: "false"
- spec:
- containers:
- - name: fluent-bit
- image: fluent/fluent-bit:1.9
- env:
- - name: SW_SERVICE
- valueFrom:
- fieldRef:
- fieldPath: metadata.name
- volumeMounts:
- - name: fluent-bit-slowsql-mysql
- mountPath: /fluent-bit/etc/
- - name: shared-data
- mountPath: /data/
- - name: mysql
- image: mysql:8.0.30
- env:
- - name: MYSQL_ROOT_PASSWORD
- value: password
- ports:
- - containerPort: 3306
- volumeMounts:
- - name: mysqld-config
- mountPath: /etc/mysql/conf.d/
- - name: shared-data
- mountPath: /data/
- volumes:
- - name: shared-data
- emptyDir: {}
- - name: fluent-bit-slowsql-mysql
- configMap:
- name: fluent-bit-slowsql-mysql
- items:
- - key: fluent-bit-conf
- path: fluent-bit.conf
- - key: fluent-bit-parser-conf
- path: fluent-bit-parser.conf
- - key: fluent-bit-script-lua
- path: fluent-bit-script.lua
- - name: mysqld-config
- configMap:
- name: fluent-bit-slowsql-mysql
- items:
- - key: mysqld-config-file
- path: config-file.cnf
----
-apiVersion: batch/v1
-kind: Job
-metadata:
- name: slowsql-mysql-load-generator # @feature: slowsql-mysql; set up job to
trigger mysql slow commands, you don't need this in production env.
-spec:
- template:
- metadata:
- name: mysql-load-deployment-slowsql
- annotations:
- sidecar.istio.io/inject: "false"
- spec:
- restartPolicy: Never
- initContainers:
- - name: wait-for-mysql
- image: busybox
- command: ["sh", "-c", "until nc -z slowsql-mysql 3306 > /dev/null;
do echo Waiting for slowsql-mysql.; sleep 2; done;"]
- containers:
- - name: mysql-load-slowsql
- image: mysql:8.0.30
- command:
- - bash
- - -c
- - mysql -hslowsql-mysql -uroot -ppassword < /conf/mock.sql
- volumeMounts:
- - name: mock-sql-vol-slowsql-mysql
- mountPath: /conf
- volumes:
- - name: mock-sql-vol-slowsql-mysql
- configMap:
- name: mock-sql-slowsql-mysql
- items:
- - key: mock-sql
- path: mock.sql
diff --git a/deploy/platform/kubernetes/feature-mysql/mysql.yaml
b/deploy/platform/kubernetes/feature-mysql/mysql.yaml
index 63f3677..795cdca 100644
--- a/deploy/platform/kubernetes/feature-mysql/mysql.yaml
+++ b/deploy/platform/kubernetes/feature-mysql/mysql.yaml
@@ -16,6 +16,25 @@
# under the License.
#
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: mysqld-config
+ labels:
+ app: mysqld-config
+data:
+ mysqld-config-file: |
+ [mysqld]
+ init_connect='SET NAMES utf8'
+ slow_query_log=ON
+ event_scheduler=ON
+ long_query_time=1
+ slow_query_log_file=/data/slow.log
+ [client]
+ default-character-set=utf8
+ [mysql]
+ default-character-set=utf8
+
---
apiVersion: v1
kind: ConfigMap
@@ -48,6 +67,10 @@ data:
ON SCHEDULE EVERY 1 SECOND
DO COMMIT;
+ CREATE EVENT `event_5`
+ ON SCHEDULE EVERY 1 SECOND
+ DO SELECT SLEEP(3);
+
---
apiVersion: v1
kind: Service
@@ -59,6 +82,10 @@ spec:
ports:
- protocol: TCP
port: 3306
+ name: mysqld
+ - protocol: TCP
+ port: 9104
+ name: mysqld-exporter
---
apiVersion: apps/v1
@@ -80,46 +107,19 @@ spec:
sidecar.istio.io/inject: "false"
spec:
containers:
- - name: mysql
- image: mysql:8.0.30
+ - name: fluent-bit
+ image: fluent/fluent-bit:1.9
env:
- - name: MYSQL_ROOT_PASSWORD
- value: password
- ports:
- - containerPort: 3306
----
-apiVersion: v1
-kind: Service
-metadata:
- name: mysql-service
-spec:
- selector:
- app: mysql-service
- ports:
- - protocol: TCP
- port: 9104
-
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
- name: mysql-service-deployment
- labels:
- app: mysql-service
-spec:
- replicas: 1
- selector:
- matchLabels:
- app: mysql-service
- template:
- metadata:
- labels:
- app: mysql-service
- annotations:
- sidecar.istio.io/inject: "false"
- spec:
- containers:
- - name: mysql
+ - name: SW_SERVICE
+ valueFrom:
+ fieldRef:
+ fieldPath: metadata.name
+ volumeMounts:
+ - name: slowsql-mysql-fluent-bit
+ mountPath: /fluent-bit/etc/
+ - name: shared-data
+ mountPath: /data/
+ - name: mysqld-exporter
image: prom/mysqld-exporter:v0.14.0
env:
- name: DATA_SOURCE_NAME
@@ -131,6 +131,38 @@ spec:
ports:
- containerPort: 9104
name: metrics
+ - name: mysql
+ image: mysql:8.0.30
+ env:
+ - name: MYSQL_ROOT_PASSWORD
+ value: password
+ ports:
+ - containerPort: 3306
+ volumeMounts:
+ - name: mysqld-config
+ mountPath: /etc/mysql/conf.d/
+ - name: shared-data
+ mountPath: /data/
+ volumes:
+ - name: shared-data
+ emptyDir: {}
+ - name: slowsql-mysql-fluent-bit
+ configMap:
+ name: slowsql-mysql-fluent-bit
+ items:
+ - key: fluent-bit-conf
+ path: fluent-bit.conf
+ - key: fluent-bit-parser-conf
+ path: fluent-bit-parser.conf
+ - key: fluent-bit-script-lua
+ path: fluent-bit-script.lua
+ - name: mysqld-config
+ configMap:
+ name: mysqld-config
+ items:
+ - key: mysqld-config-file
+ path: config-file.cnf
+
---
apiVersion: batch/v1
kind: Job
diff --git a/deploy/platform/kubernetes/feature-mysql/open-telemetry.yaml
b/deploy/platform/kubernetes/feature-mysql/open-telemetry.yaml
index f26b750..8ec063c 100644
--- a/deploy/platform/kubernetes/feature-mysql/open-telemetry.yaml
+++ b/deploy/platform/kubernetes/feature-mysql/open-telemetry.yaml
@@ -38,7 +38,7 @@ data:
relabel_configs:
- source_labels: [__meta_kubernetes_pod_container_name,
__meta_kubernetes_pod_container_port_name]
action: keep
- regex: mysql;metrics # @feature: mysql; reference the name
of the metrics port
+ regex: mysqld-exporter;metrics # @feature: mysql; reference
the name of the metrics port
- source_labels: [__meta_kubernetes_pod_name]
target_label: host_name
regex: (.+)
@@ -62,6 +62,7 @@ data:
- batch
exporters:
- otlp
+ - logging
---
apiVersion: apps/v1
diff --git a/docs/readme.md b/docs/readme.md
index f1de27d..d502676 100644
--- a/docs/readme.md
+++ b/docs/readme.md
@@ -97,8 +97,7 @@ Currently, the features supported are:
| `function` | Deploy [OpenFunction](https://openfunction.dev/) and
export trace to SkyWalking.
| Command [ofn](https://github.com/OpenFunction/cli) is required to run
this feature. |
| `trace-profiling` | Deploy tools to submit trace profiling tasks.
| Only support deployment with SkyWalking agents installed, currently
Java agent and Python agent support trace profiling. |
| `rover` | Deploy SkyWalking Rover and detect the processes in
the Kubernetes environment.
| Only support deployment in the Kubernetes environment, docker is not
supported. |
-| `mysql` | Start a MySQL server, execute the sample SQLs
periodically, and export their metrics to SkyWalking.
|
|
-| `slowsql-mysql` | Start a MySQL server and load generator to execute
the sample SQLs periodically; set up fluent bit to fetch slow logs and export
to OAP. |
|
+| `mysql` | Start a MySQL server and load generator to execute
the sample SQLs periodically, set up fluent bit to fetch slow logs and export
to OAP, and export their metrics to SkyWalking.
|
|
| `postgresql` | Start a PostgreSQL server, execute the sample SQLs
periodically, and export their metrics to SkyWalking.
|
|
### Kubernetes