-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Redis protocol to use ECS fields #10126
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import ( | |
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/monitoring" | ||
|
||
"github.com/elastic/beats/packetbeat/pb" | ||
"github.com/elastic/beats/packetbeat/procs" | ||
"github.com/elastic/beats/packetbeat/protos" | ||
"github.com/elastic/beats/packetbeat/protos/applayer" | ||
|
@@ -275,55 +276,45 @@ func (redis *redisPlugin) correlate(conn *redisConnectionData) { | |
} | ||
|
||
func (redis *redisPlugin) newTransaction(requ, resp *redisMessage) beat.Event { | ||
error := common.OK_STATUS | ||
if resp.isError { | ||
error = common.ERROR_STATUS | ||
} | ||
|
||
var returnValue map[string]common.NetString | ||
if resp.isError { | ||
returnValue = map[string]common.NetString{ | ||
"error": resp.message, | ||
} | ||
} else { | ||
returnValue = map[string]common.NetString{ | ||
"return_value": resp.message, | ||
} | ||
} | ||
|
||
source, destination := common.MakeEndpointPair(requ.tcpTuple.BaseTuple, requ.cmdlineTuple) | ||
src, dst := &source, &destination | ||
if requ.direction == tcp.TCPDirectionReverse { | ||
src, dst = dst, src | ||
} | ||
|
||
// resp_time in milliseconds | ||
responseTime := int32(resp.ts.Sub(requ.ts).Nanoseconds() / 1e6) | ||
|
||
fields := common.MapStr{ | ||
"type": "redis", | ||
"status": error, | ||
"responsetime": responseTime, | ||
"redis": returnValue, | ||
"method": common.NetString(bytes.ToUpper(requ.method)), | ||
"resource": requ.path, | ||
"query": requ.message, | ||
"bytes_in": uint64(requ.size), | ||
"bytes_out": uint64(resp.size), | ||
"src": src, | ||
"dst": dst, | ||
evt, pbf := pb.NewBeatEvent(requ.ts) | ||
pbf.SetSource(src) | ||
pbf.SetDestination(dst) | ||
pbf.Source.Bytes = int64(requ.size) | ||
pbf.Destination.Bytes = int64(resp.size) | ||
pbf.Event.Dataset = "redis" | ||
pbf.Event.Start = requ.ts | ||
pbf.Event.End = resp.ts | ||
pbf.Network.Transport = "tcp" | ||
pbf.Network.Protocol = pbf.Event.Dataset | ||
|
||
fields := evt.Fields | ||
fields["type"] = pbf.Event.Dataset | ||
fields["method"] = common.NetString(bytes.ToUpper(requ.method)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're actually going with lowercase, to normalize text in general. Even though this isn't an ECS field, I think it would make sense to lowercase instead of uppercasing here as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hesitant to change this now because it's not strictly required for ECS. It was already doing a ToUpper so this isn't a change I introduced. It probably would make sense to normalize the common fields from all the protocols (method, status, path, query). If we do that it would be nice to have it done is a single place in the code path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, since it was already like this, and ECS doesn't cover that field, I'm fine if you prefer to leave it for now. However as ECS continues to cover more areas, I think we will continue suggesting normalizing to lowercase. |
||
fields["resource"] = requ.path | ||
fields["query"] = requ.message | ||
|
||
if resp.isError { | ||
evt.PutValue("status", common.ERROR_STATUS) | ||
evt.PutValue("error.message", resp.message) | ||
} else { | ||
evt.PutValue("status", common.OK_STATUS) | ||
evt.PutValue("redis.return_value", resp.message) | ||
} | ||
|
||
if redis.sendRequest { | ||
fields["request"] = requ.message | ||
} | ||
if redis.sendResponse { | ||
fields["response"] = resp.message | ||
} | ||
|
||
return beat.Event{ | ||
Timestamp: requ.ts, | ||
Fields: fields, | ||
} | ||
return evt | ||
} | ||
|
||
func (redis *redisPlugin) GapInStream(tcptuple *common.TCPTuple, dir uint8, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same minor heads up as for Thrift error messages. Ingest Node suggests outputting IN errors in
error.message
. If Pb doesn't use IN at all, I think we're good.What you're doing here is the correct usage for
error.message
, IN example is what will have to change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to undo the
error.message
change I did here. It doesn't align well with the other protocols and makes the value of the field confusing because you are not sure if it's a protocol error (bad SQL query) or a Packetbeat error (packet loss detected).