Skip to content

Commit 80e9655

Browse files
committed
fix: limit the bytes of redis args
Signed-off-by: rfyiamcool <[email protected]>
1 parent 7135bd2 commit 80e9655

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

Diff for: docs/en/agent/plugin-configurations.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
|--------------------------------|-------------------------------------------------------|---------------|----------------------------------------------------------------|
55
| http.server_collect_parameters | SW_AGENT_PLUGIN_CONFIG_HTTP_SERVER_COLLECT_PARAMETERS | false | Collect the parameters of the HTTP request on the server side. |
66
| mongo.collect_statement | SW_AGENT_PLUGIN_CONFIG_MONGO_COLLECT_STATEMENT | false | Collect the statement of the MongoDB request. |
7+
| redis.max_args_bytes | SW_AGENT_PLUGIN_CONFIG_REDIS_MAX_ARGS_BYTES | 1024 | Limit the bytes size of redis args request. |
78
| sql.collect_parameter | SW_AGENT_PLUGIN_CONFIG_SQL_COLLECT_PARAMETER | false | Collect the parameter of the SQL request. |
89
| reporter.discard | SW_AGENT_REPORTER_DISCARD | false | Discard the reporter. |

Diff for: plugins/go-redisv9/config.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package goredisv9
19+
20+
//skywalking:config redis
21+
var config struct {
22+
MaxArgsBytes int `config:"max_args_bytes"`
23+
}

Diff for: plugins/go-redisv9/hook.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (r *redisHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
9999
tracing.WithTag(tracing.TagCacheOp, getCacheOp(cmd.FullName())),
100100
tracing.WithTag(tracing.TagCacheCmd, cmd.FullName()),
101101
tracing.WithTag(tracing.TagCacheKey, getKey(cmd.Args())),
102-
tracing.WithTag(tracing.TagCacheArgs, cmd.String()),
102+
tracing.WithTag(tracing.TagCacheArgs, maxString(cmd.String(), config.MaxArgsBytes)),
103103
)
104104

105105
if err != nil {
@@ -187,3 +187,15 @@ func getKey(args []interface{}) string {
187187
}
188188
return key
189189
}
190+
191+
// maxString limit the bytes length of the redis args.
192+
func maxString(s string, length int) string {
193+
if length <= 0 { // no define or no limit
194+
return s
195+
}
196+
197+
if len(s) > length {
198+
return s[:length]
199+
}
200+
return s
201+
}

Diff for: test/plugins/scenarios/go-redisv9/bin/startup.sh

+2
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919
home="$(cd "$(dirname $0)"; pwd)"
2020
go build ${GO_BUILD_OPTS} -o goredisv9
2121

22+
export SW_AGENT_PLUGIN_CONFIG_REDIS_MAX_ARGS_BYTES=1024
23+
2224
./goredisv9

Diff for: tools/go-agent/config/agent.default.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ plugin:
9292
sql:
9393
# Collect the parameter of the SQL request
9494
collect_parameter: ${SW_AGENT_PLUGIN_CONFIG_SQL_COLLECT_PARAMETER:false}
95+
redis:
96+
# Limit the bytes size of redis args request
97+
max_args_bytes: ${SW_AGENT_PLUGIN_CONFIG_REDIS_MAX_ARGS_BYTES:1024}

0 commit comments

Comments
 (0)