-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support Protocol Dubbo2 The changes of config.yaml 1. Remove http_payload_length 2. Add payload_length in protocol_config for all protocols 3. Add dubbo in protocol_parser Dubbo Request Output: 1. content_key 2. request_payload Dubbo Response Output: 1. dubbo_error_code 2. response_payload 3. is_error 4. error_type Signed-off-by: huxiangyuan <huxiangyuan@harmonycloud.cn> * feat(net-adapter): support to exporter dubbo metric info Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * test: add testcase of label_converter for dubbo Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * docs: update prometheus_metrics about dubbo info Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * docs: update prometheus metrics document Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * docs: update prometheus metrics document Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * test: update testcase for code change Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * style(dubbo-parser): Using camel case instead of snake case. Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * docs: add comments on payload_length Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * docs: add comments on payload_length Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> * refactor(procotol): Set default protocol length to 80 and extract a method `GetPayloadLength(protocol string)` Signed-off-by: niejiangang <niejiangang@harmonycloud.cn> Co-authored-by: niejiangang <niejiangang@harmonycloud.cn> Co-authored-by: Daxin Wang <daxinwang@harmonycloud.cn>
- Loading branch information
1 parent
8a2b600
commit 1a2ead6
Showing
24 changed files
with
713 additions
and
47 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
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,48 @@ | ||
package dubbo | ||
|
||
import "github.com/Kindling-project/kindling/collector/analyzer/network/protocol" | ||
|
||
const ( | ||
// Zero : byte zero | ||
Zero = byte(0x00) | ||
|
||
// magic header | ||
MagicHigh = byte(0xda) | ||
MagicLow = byte(0xbb) | ||
|
||
// message flag. | ||
FlagRequest = byte(0x80) | ||
FlagTwoWay = byte(0x40) | ||
FlagEvent = byte(0x20) // for heartbeat | ||
SerialMask = 0x1f | ||
|
||
AsciiLow = byte(0x20) | ||
AsciiHigh = byte(0x7e) | ||
AsciiReplace = byte(0x2e) // . | ||
) | ||
|
||
func NewDubboParser() *protocol.ProtocolParser { | ||
requestParser := protocol.CreatePkgParser(fastfailDubboRequest(), parseDubboRequest()) | ||
responseParser := protocol.CreatePkgParser(fastfailDubboResponse(), parseDubboResponse()) | ||
return protocol.NewProtocolParser(protocol.DUBBO, requestParser, responseParser, nil) | ||
} | ||
|
||
/** | ||
Get the ascii readable string, replace other value to '.', like wireshark. | ||
*/ | ||
func getAsciiString(data []byte) string { | ||
length := len(data) | ||
if length == 0 { | ||
return "" | ||
} | ||
|
||
newData := make([]byte, length) | ||
for i := 0; i < length; i++ { | ||
if data[i] > AsciiHigh || data[i] < AsciiLow { | ||
newData[i] = AsciiReplace | ||
} else { | ||
newData[i] = data[i] | ||
} | ||
} | ||
return string(newData) | ||
} |
67 changes: 67 additions & 0 deletions
67
collector/analyzer/network/protocol/dubbo/dubbo_request.go
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,67 @@ | ||
package dubbo | ||
|
||
import ( | ||
"github.com/Kindling-project/kindling/collector/analyzer/network/protocol" | ||
"github.com/Kindling-project/kindling/collector/model/constlabels" | ||
) | ||
|
||
func fastfailDubboRequest() protocol.FastFailFn { | ||
return func(message *protocol.PayloadMessage) bool { | ||
return len(message.Data) < 16 || message.Data[0] != MagicHigh || message.Data[1] != MagicLow | ||
} | ||
} | ||
|
||
func parseDubboRequest() protocol.ParsePkgFn { | ||
return func(message *protocol.PayloadMessage) (bool, bool) { | ||
contentKey := getContentKey(message.Data) | ||
if contentKey == "" { | ||
return false, true | ||
} | ||
|
||
message.AddStringAttribute(constlabels.ContentKey, contentKey) | ||
message.AddStringAttribute(constlabels.DubboRequestPayload, getAsciiString(message.GetData(16, protocol.GetDubboPayLoadLength()))) | ||
return true, true | ||
} | ||
} | ||
|
||
func getContentKey(requestData []byte) string { | ||
serialID := requestData[2] & SerialMask | ||
if serialID == Zero { | ||
return "" | ||
} | ||
if (requestData[2] & FlagEvent) != Zero { | ||
return "Heartbeat" | ||
} | ||
if (requestData[2] & FlagRequest) == Zero { | ||
// Invalid Data | ||
return "" | ||
} | ||
if (requestData[2] & FlagTwoWay) == Zero { | ||
// Ignore Oneway Data | ||
return "Oneway" | ||
} | ||
|
||
serializer := GetSerializer(serialID) | ||
if serializer == serialUnsupport { | ||
// Unsupport Serial. only support hessian and fastjson. | ||
return "UnSupportSerialFormat" | ||
} | ||
|
||
var ( | ||
service string | ||
method string | ||
) | ||
// version | ||
offset := serializer.eatString(requestData, 16) | ||
|
||
// service name | ||
offset, service = serializer.getStringValue(requestData, offset) | ||
|
||
// service version | ||
offset = serializer.eatString(requestData, offset) | ||
|
||
// method name | ||
_, method = serializer.getStringValue(requestData, offset) | ||
|
||
return service + "#" + method | ||
} |
45 changes: 45 additions & 0 deletions
45
collector/analyzer/network/protocol/dubbo/dubbo_response.go
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,45 @@ | ||
package dubbo | ||
|
||
import ( | ||
"github.com/Kindling-project/kindling/collector/analyzer/network/protocol" | ||
"github.com/Kindling-project/kindling/collector/model/constlabels" | ||
) | ||
|
||
func fastfailDubboResponse() protocol.FastFailFn { | ||
return func(message *protocol.PayloadMessage) bool { | ||
return len(message.Data) < 16 || message.Data[0] != MagicHigh || message.Data[1] != MagicLow | ||
} | ||
} | ||
|
||
func parseDubboResponse() protocol.ParsePkgFn { | ||
return func(message *protocol.PayloadMessage) (bool, bool) { | ||
errorCode := getErrorCode(message.Data) | ||
if errorCode == -1 { | ||
return false, true | ||
} | ||
|
||
message.AddIntAttribute(constlabels.DubboErrorCode, errorCode) | ||
if errorCode > 20 { | ||
message.AddBoolAttribute(constlabels.IsError, true) | ||
message.AddIntAttribute(constlabels.ErrorType, int64(constlabels.ProtocolError)) | ||
} | ||
message.AddStringAttribute(constlabels.DubboResponsePayload, getAsciiString(message.GetData(16, protocol.GetDubboPayLoadLength()))) | ||
return true, true | ||
} | ||
} | ||
|
||
func getErrorCode(responseData []byte) int64 { | ||
SerialID := responseData[2] & SerialMask | ||
if SerialID == Zero { | ||
return -1 | ||
} | ||
if (responseData[2] & FlagEvent) != Zero { | ||
return 20 | ||
} | ||
if (responseData[2] & FlagRequest) != Zero { | ||
// Invalid Data | ||
return -1 | ||
} | ||
|
||
return int64(responseData[3]) | ||
} |
Oops, something went wrong.