This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 81ec3af923 [Feature] Redis slow log collection (#10825)
81ec3af923 is described below

commit 81ec3af923ea19157905ab8d9ee3d49e6315ad7b
Author: yswdqz <[email protected]>
AuthorDate: Tue May 23 00:31:00 2023 +0800

    [Feature] Redis slow log collection (#10825)
---
 .github/workflows/skywalking.yaml                  |   2 +-
 docs/en/changes/changes.md                         |   1 +
 docs/en/setup/backend/backend-redis-monitoring.md  |  33 ++++++
 .../src/main/resources/application.yml             |   2 +-
 .../src/main/resources/lal/redis-slowsql.yaml      |  35 ++++++
 .../redis/redis-service.json                       |  31 +++++
 test/e2e-v2/cases/redis/expected/db-has-value.yml  |  29 +++++
 .../redis/expected/metrics-has-value-label.yml     |  29 +++++
 test/e2e-v2/cases/redis/redis-cases.yaml           |   5 +
 .../cases/redis/redis-exporter/docker-compose.yml  |  23 ++++
 .../redis/redis-exporter/fluent-bit-parser.conf    |  19 +++
 .../redis/redis-exporter/fluent-bit-script.lua     | 132 +++++++++++++++++++++
 .../cases/redis/redis-exporter/fluent-bit.conf     |  40 +++++++
 test/e2e-v2/cases/redis/redis-exporter/mock.txt    |   1 +
 test/e2e-v2/cases/redis/redis-exporter/redis.conf  |   4 +-
 .../redis/redis-exporter/scripts/crontable.txt     |   2 +
 .../cases/redis/redis-exporter/scripts/slowlog.log |  16 +++
 .../cases/redis/redis-exporter/scripts/slowlog.sh  |  28 +++++
 .../cases/redis/redis-exporter/scripts/start.sh    |  24 ++++
 19 files changed, 452 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/skywalking.yaml 
b/.github/workflows/skywalking.yaml
index 8e2bfcc7bd..03d0c6d3b0 100644
--- a/.github/workflows/skywalking.yaml
+++ b/.github/workflows/skywalking.yaml
@@ -677,7 +677,7 @@ jobs:
             config: test/e2e-v2/cases/promql/e2e.yaml
           - name: AWS API Gateway
             config: test/e2e-v2/cases/aws/api-gateway/e2e.yaml
-          - name: Redis Prometheus
+          - name: Redis Prometheus and Log Collecting
             config: test/e2e-v2/cases/redis/redis-exporter/e2e.yaml
           - name: Elasticsearch
             config: test/e2e-v2/cases/elasticsearch/e2e.yaml
diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index 3b95fca657..7ac0d95e8d 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -45,6 +45,7 @@
 * Fix potential NPE in Zipkin receiver when the `Span` is missing some fields.
 * Filter out unknown_cluster metric data.
 * Support RabbitMQ Monitoring.
+* Support Redis slow logs collection.
 
 #### UI
 * Revert: cpm5d function. This feature is cancelled from backend.
diff --git a/docs/en/setup/backend/backend-redis-monitoring.md 
b/docs/en/setup/backend/backend-redis-monitoring.md
index 18c7652bce..ef5a2198bc 100644
--- a/docs/en/setup/backend/backend-redis-monitoring.md
+++ b/docs/en/setup/backend/backend-redis-monitoring.md
@@ -36,3 +36,36 @@ You can customize your own metrics/expression/dashboard 
panel.
 The metrics definition and expression rules are found in 
`/config/otel-rules/redis`.
 The Redis dashboard panel configurations are found in 
`/config/ui-initialized-templates/redis`.
 
+## Collect sampled slow commands
+SkyWalking leverages [fluentbit](https://fluentbit.io/) or other log agents 
for collecting slow commands from Redis.
+
+### Data flow
+1. Execute 
[commands](../../../../test/e2e-v2/cases/redis/redis-exporter/scripts/slowlog.sh)
 periodically to collect slow logs from Redis and save the result locally.
+2. Fluent-bit agent collects slow logs from local file.
+3. fluent-bit agent sends data to SkyWalking OAP Server using native meter 
APIs via HTTP.
+4. The SkyWalking OAP Server parses the expression with 
[LAL](../../concepts-and-designs/lal.md) to parse/extract and store the results.
+
+### Set up
+1. Set up [fluentbit](https://docs.fluentbit.io/manual/installation/docker).
+2. Config fluentbit from 
[here](../../../../test/e2e-v2/cases/redis/redis-exporter/fluent-bit.conf) for 
Redis.
+3. Config slow log from 
[here](../../../../test/e2e-v2/cases/redis/redis-exporter/redis.conf) for Redis.
+4. Periodically execute the 
[commands](../../../../test/e2e-v2/cases/redis/redis-exporter/scripts/slowlog.sh).
+
+**Notice:**
+
+1.The `slowlog-log-slower-than` and `slowlog-max-len` configuration items in 
the configuration file are for the slow log, the former indicating that 
execution time longer than the specified time (in milliseconds) will be logged 
to the slowlog, and the latter indicating the maximum number of slow logs that 
will be stored in the slow log file.
+2.In the e2e test, SkyWalking uses cron to periodically execute the redis 
command to fetch the slow logs and write them to a local file, which is then 
collected by fluent-bit to send the data to the OAP. You can see the relevant 
configuration files 
[here](../../../../test/e2e-v2/cases/redis/redis-exporter).You can also get 
slow logs periodically and send them to OAP in other ways than using cron and 
fluent-bit.
+
+### Slow Commands Monitoring
+Slow SQL monitoring provides monitoring of the slow commands of the Redis 
servers. Redis servers are cataloged as a `Layer: REDIS` `Service` in OAP.
+
+#### Supported Metrics
+| Monitoring Panel | Unit | Metric Name | Description                          
            | Data Source |
+|-----|------|-----|--------------------------------------------------|-----|
+|Slow Statements |   ms   | top_n_database_statement | The latency and 
statement of Redis slow commands | fluentbit|
+
+### Customizations
+You can customize your own metrics/expression/dashboard panel.
+The slowsql expression rules are found in `/config/lal/redis-slowsql.yaml`
+The Redis dashboard panel configurations are found in 
`/config/ui-initialized-templates/redis`.
+`
\ No newline at end of file
diff --git a/oap-server/server-starter/src/main/resources/application.yml 
b/oap-server/server-starter/src/main/resources/application.yml
index dd95e74ff1..0abb6ca834 100644
--- a/oap-server/server-starter/src/main/resources/application.yml
+++ b/oap-server/server-starter/src/main/resources/application.yml
@@ -238,7 +238,7 @@ agent-analyzer:
 log-analyzer:
   selector: ${SW_LOG_ANALYZER:default}
   default:
-    lalFiles: 
${SW_LOG_LAL_FILES:envoy-als,mesh-dp,mysql-slowsql,pgsql-slowsql,k8s-service,default}
+    lalFiles: 
${SW_LOG_LAL_FILES:envoy-als,mesh-dp,mysql-slowsql,pgsql-slowsql,redis-slowsql,k8s-service,default}
     malFiles: ${SW_LOG_MAL_FILES:""}
 
 event-analyzer:
diff --git 
a/oap-server/server-starter/src/main/resources/lal/redis-slowsql.yaml 
b/oap-server/server-starter/src/main/resources/lal/redis-slowsql.yaml
new file mode 100644
index 0000000000..b4873ad88c
--- /dev/null
+++ b/oap-server/server-starter/src/main/resources/lal/redis-slowsql.yaml
@@ -0,0 +1,35 @@
+# 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.
+
+rules:
+  - name: redis-slowsql
+    layer: REDIS
+    dsl: |
+      filter {
+        json{
+        }
+        extractor{
+          layer parsed.layer as String
+          service parsed.service as String
+          timestamp parsed.time as String
+          if (tag("LOG_KIND") == "SLOW_SQL") {
+             slowSql {
+               id parsed.id as String
+               statement parsed.statement as String
+               latency parsed.query_time as Long
+             }
+          }
+        }
+      }
diff --git 
a/oap-server/server-starter/src/main/resources/ui-initialized-templates/redis/redis-service.json
 
b/oap-server/server-starter/src/main/resources/ui-initialized-templates/redis/redis-service.json
index 1fb29209c0..d5a8422ab0 100644
--- 
a/oap-server/server-starter/src/main/resources/ui-initialized-templates/redis/redis-service.json
+++ 
b/oap-server/server-starter/src/main/resources/ui-initialized-templates/redis/redis-service.json
@@ -311,6 +311,37 @@
                   }
                 }
               ]
+            },
+            {
+              "name":"Slow Commands",
+              "children":[
+                {
+                  "x":0,
+                  "y":0,
+                  "w":24,
+                  "h":31,
+                  "i":"0",
+                  "type":"Widget",
+                  "metricTypes":[
+                    "readRecords"
+                  ],
+                  "metrics":[
+                    "top_n_database_statement"
+                  ],
+                  "graph":{
+                    "type":"TopList",
+                    "color":"purple"
+                  },
+                  "widget":{
+                    "title":"Slow Commands (ms)"
+                  },
+                  "metricConfig":[
+                    {
+                      "calculation":"msTos"
+                    }
+                  ]
+                }
+              ]
             }
           ]
         }
diff --git a/test/e2e-v2/cases/redis/expected/db-has-value.yml 
b/test/e2e-v2/cases/redis/expected/db-has-value.yml
new file mode 100644
index 0000000000..6acd70e6b3
--- /dev/null
+++ b/test/e2e-v2/cases/redis/expected/db-has-value.yml
@@ -0,0 +1,29 @@
+# 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.
+
+{{- contains . }}
+- key: 0
+  value:
+  {{- contains .value }}
+  - key: name
+    value: {{ notEmpty .value }}
+  - key: id
+    value: ""
+  - key: value
+    value: {{ notEmpty .value }}
+  - key: refid
+    value: ""
+  {{- end }}
+{{- end }}
diff --git a/test/e2e-v2/cases/redis/expected/metrics-has-value-label.yml 
b/test/e2e-v2/cases/redis/expected/metrics-has-value-label.yml
new file mode 100644
index 0000000000..fb38843650
--- /dev/null
+++ b/test/e2e-v2/cases/redis/expected/metrics-has-value-label.yml
@@ -0,0 +1,29 @@
+# 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.
+
+{{- contains . }}
+- key: {{ notEmpty .key }}
+  value:
+  {{- contains .value }}
+  - key: {{ notEmpty .key }}
+    value:
+      value: 0
+      isemptyvalue: true
+  - key: {{ notEmpty .key }}
+    value:
+      value: {{ ge .value.value 1 }}
+      isemptyvalue: false
+  {{- end }}
+{{- end }}
diff --git a/test/e2e-v2/cases/redis/redis-cases.yaml 
b/test/e2e-v2/cases/redis/redis-cases.yaml
index 7aad16d46f..62f42a0a46 100644
--- a/test/e2e-v2/cases/redis/redis-cases.yaml
+++ b/test/e2e-v2/cases/redis/redis-cases.yaml
@@ -63,3 +63,8 @@ cases:
   - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql metrics linear 
--name=meter_redis_instance_expired_keys_total --service-name=redis::root[root] 
--instance-name=redis_exporter_1:9121 |yq e 'to_entries' -
     expected: expected/metrics-has-value.yml
 
+    # slow sql
+  - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql records list 
--name=top_n_database_statement --service-name=redis::root[root] |yq e 
'to_entries | with(.[] ; .value=(.value | to_entries))' -
+    expected:  expected/db-has-value.yml
+
+
diff --git a/test/e2e-v2/cases/redis/redis-exporter/docker-compose.yml 
b/test/e2e-v2/cases/redis/redis-exporter/docker-compose.yml
index 6a75808385..4d56ef7006 100644
--- a/test/e2e-v2/cases/redis/redis-exporter/docker-compose.yml
+++ b/test/e2e-v2/cases/redis/redis-exporter/docker-compose.yml
@@ -24,6 +24,9 @@ services:
       - 12800
     networks:
       - e2e
+    environment:
+      - TZ=Asia/Shanghai
+      - SW_CORE_TOPN_REPORT_PERIOD=2
   redis_1: &redis
     image: redis:6.0
     networks:
@@ -88,6 +91,26 @@ services:
     depends_on:
       oap:
         condition: service_healthy
+  fluentbit:
+    image: fluent/fluent-bit:1.9
+    environment:
+      - TZ=Asia/Shanghai
+    volumes:
+      - ./scripts:/scripts
+      - ./fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
+      - ./fluent-bit-parser.conf:/fluent-bit/etc/fluent-bit-parser.conf
+      - ./fluent-bit-script.lua:/fluent-bit/etc/fluent-bit-script.lua
+    networks:
+      - e2e
+    depends_on:
+      - slowlog
+  slowlog:
+    image: redis:6.0
+    volumes:
+      - ./scripts:/scripts
+    networks:
+      - e2e
+    command: sh -c "chmod 777 /scripts/start.sh /scripts/slowlog.sh 
/scripts/slowlog.log && /scripts/start.sh"
 
 networks:
   e2e:
diff --git a/test/e2e-v2/cases/redis/redis-exporter/fluent-bit-parser.conf 
b/test/e2e-v2/cases/redis/redis-exporter/fluent-bit-parser.conf
new file mode 100644
index 0000000000..1a4ef38347
--- /dev/null
+++ b/test/e2e-v2/cases/redis/redis-exporter/fluent-bit-parser.conf
@@ -0,0 +1,19 @@
+# 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.
+
+[PARSER]
+    name   my-log-format
+    format regex
+    regex  ^\S+\s+\S+\s+\S+\s+([\S\s]+)\s+\S+:\S+$
\ No newline at end of file
diff --git a/test/e2e-v2/cases/redis/redis-exporter/fluent-bit-script.lua 
b/test/e2e-v2/cases/redis/redis-exporter/fluent-bit-script.lua
new file mode 100644
index 0000000000..be650d1650
--- /dev/null
+++ b/test/e2e-v2/cases/redis/redis-exporter/fluent-bit-script.lua
@@ -0,0 +1,132 @@
+--
+-- 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.
+--
+
+-- The following is an example of a simple Redis slow log
+--     102 1684379526 2691 flushall 192.168.150.29:42904
+function rewrite_body(tag, timestamp, record)
+  local log = record.log
+  if isStringOnlyWhitespace(log) then
+    return -1, timestamp, record
+  end
+
+  if log:sub(1, 1) == "#" then
+    return -1, timestamp, record
+  end
+  record.log = nil
+  record.tags = { data = { { key = "LOG_KIND", value = "SLOW_SQL" } } }
+
+  local trimmed = trim(log)
+  local splitResult = split(trimmed, " ")
+
+  inner_record = {}
+
+  inner_record.time = os.time() * 1000
+  inner_record.layer = "REDIS"
+
+  record.layer = "REDIS"
+
+  -- Here simply set the service name to `root[root] for e2e testing, you can 
also just set ip:port to service name
+  record.service = "redis::" .. "root[root]"
+  inner_record.service = "redis::" .. "root[root]"
+
+  local query_time = splitResult[3]
+  local qt = math.floor(query_time)
+  inner_record.query_time = qt
+  inner_record.statement = ""
+
+  inner_record.id = splitResult[1]
+
+
+  for i = 4, #splitResult - 1 do
+    inner_record.statement = inner_record.statement .. splitResult[i]
+    inner_record.statement = inner_record.statement .. " "
+  end
+  inner_record.statement = trim(inner_record.statement)
+  inner_record.statement = string.gsub(inner_record.statement, '"', '\\"')
+
+  local jsonstr = table2json(inner_record)
+  record.body = { json = { json = jsonstr } }
+
+  return 1, timestamp, record
+end
+
+function trim(str)
+  return str:gsub("^%s*(.-)%s*$", "%1")
+end
+
+function split(str, delimiter)
+  local result = {}
+  for match in (str..delimiter):gmatch("(.-)"..delimiter) do
+    table.insert(result, match)
+  end
+  return result
+end
+function isStringOnlyWhitespace(str)
+  return str:match("^%s*$") ~= nil
+end
+
+function table2json(t)
+  local function serialize(tbl, structure)
+    local tmp = {}
+    for k, v in pairs(tbl) do
+      local k_type = type(k)
+      local v_type = type(v)
+      local key
+      if k_type == "string" then
+        key = '"' .. k .. '":'
+      elseif k_type == "number" then
+        key = ""
+        if structure == "array" then
+          key = ""
+        else
+          key = '"' .. k .. '":'
+        end
+      else
+        key = '"' .. tostring(k) .. '":'
+      end
+      local value
+      if v_type == "table" then
+        if next(v) == nil then
+          value = "null"
+        else
+          value = serialize(v, structure)
+        end
+      elseif v_type == "boolean" then
+        value = tostring(v)
+      elseif v_type == "string" then
+        value = '"' .. v .. '"'
+      else
+        value = v
+      end
+      tmp[#tmp + 1] = key and value and tostring(key) .. tostring(value) or nil
+    end
+    if structure == "array" then
+      return "[" .. table.concat(tmp, ",") .. "]"
+    else
+      return "{" .. table.concat(tmp, ",") .. "}"
+    end
+  end
+  assert(type(t) == "table")
+  if next(t) == nil then
+    return "null"
+  elseif next(t, next(t)) == nil and type(next(t)) == "number" then
+    return serialize(t, "array")
+  else
+    return serialize(t, "table")
+  end
+end
+
diff --git a/test/e2e-v2/cases/redis/redis-exporter/fluent-bit.conf 
b/test/e2e-v2/cases/redis/redis-exporter/fluent-bit.conf
new file mode 100644
index 0000000000..39682804e6
--- /dev/null
+++ b/test/e2e-v2/cases/redis/redis-exporter/fluent-bit.conf
@@ -0,0 +1,40 @@
+# 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.
+
+[SERVICE]
+    flush          1
+    log_level      info
+    parsers_File   fluent-bit-parser.conf
+[INPUT]
+    name             tail
+    path             /scripts/slowlog.log
+    read_from_head   true
+    parser my-log-format
+[FILTER]
+    name           lua
+    match          *
+    script         fluent-bit-script.lua
+    call           rewrite_body
+[OUTPUT]
+    name            stdout
+    match           *
+    format          json
+[OUTPUT]
+    name            http
+    match           *
+    host            oap
+    port            12800
+    uri             /v3/logs
+    format          json
diff --git a/test/e2e-v2/cases/redis/redis-exporter/mock.txt 
b/test/e2e-v2/cases/redis/redis-exporter/mock.txt
index 81a6bba064..e4c374e34b 100644
--- a/test/e2e-v2/cases/redis/redis-exporter/mock.txt
+++ b/test/e2e-v2/cases/redis/redis-exporter/mock.txt
@@ -3,6 +3,7 @@ set c d
 get a
 set e f
 debug sleep 10
+debug sleep 3
 get a
 get b
 get c
diff --git a/test/e2e-v2/cases/redis/redis-exporter/redis.conf 
b/test/e2e-v2/cases/redis/redis-exporter/redis.conf
index aba474a8da..86236bc5e1 100644
--- a/test/e2e-v2/cases/redis/redis-exporter/redis.conf
+++ b/test/e2e-v2/cases/redis/redis-exporter/redis.conf
@@ -54,8 +54,8 @@ auto-aof-rewrite-min-size 64mb
 aof-load-truncated yes
 aof-use-rdb-preamble yes
 lua-time-limit 5000
-slowlog-log-slower-than 10000
-slowlog-max-len 128
+slowlog-log-slower-than 1000
+slowlog-max-len 1200
 latency-monitor-threshold 0
 notify-keyspace-events ""
 hash-max-ziplist-entries 512
diff --git a/test/e2e-v2/cases/redis/redis-exporter/scripts/crontable.txt 
b/test/e2e-v2/cases/redis/redis-exporter/scripts/crontable.txt
new file mode 100644
index 0000000000..92699e7b3d
--- /dev/null
+++ b/test/e2e-v2/cases/redis/redis-exporter/scripts/crontable.txt
@@ -0,0 +1,2 @@
+* * * * * /scripts/slowlog.sh
+
diff --git a/test/e2e-v2/cases/redis/redis-exporter/scripts/slowlog.log 
b/test/e2e-v2/cases/redis/redis-exporter/scripts/slowlog.log
new file mode 100644
index 0000000000..7a3a892903
--- /dev/null
+++ b/test/e2e-v2/cases/redis/redis-exporter/scripts/slowlog.log
@@ -0,0 +1,16 @@
+# 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.
+
+
diff --git a/test/e2e-v2/cases/redis/redis-exporter/scripts/slowlog.sh 
b/test/e2e-v2/cases/redis/redis-exporter/scripts/slowlog.sh
new file mode 100644
index 0000000000..ca9ef2c5e7
--- /dev/null
+++ b/test/e2e-v2/cases/redis/redis-exporter/scripts/slowlog.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# 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.
+
+len=$(/usr/local/bin/redis-cli -h redis_1 slowlog len)
+
+if [[ $len -gt 0 ]]; then
+   
+    result=$(/usr/local/bin/redis-cli -h redis_1 slowlog get $len)
+
+    single_line_log="$(echo "$result" | tr '\n' ' ')"
+    processed_result=$(echo "$single_line_log" | sed  
's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}:[0-9]\{1,5\}/&\n/g')
+    echo "$processed_result" >> /scripts/slowlog.log
+fi
+/usr/local/bin/redis-cli -h redis_1 slowlog reset
diff --git a/test/e2e-v2/cases/redis/redis-exporter/scripts/start.sh 
b/test/e2e-v2/cases/redis/redis-exporter/scripts/start.sh
new file mode 100644
index 0000000000..0356d6ae1f
--- /dev/null
+++ b/test/e2e-v2/cases/redis/redis-exporter/scripts/start.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+# 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.
+
+apt-get update && apt-get install -y cron
+
+crontab /scripts/crontable.txt
+
+service cron start
+
+tail -f /dev/null

Reply via email to