You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "mrproliu (via GitHub)" <gi...@apache.org> on 2023/08/05 09:54:24 UTC

[GitHub] [skywalking-go] mrproliu commented on a diff in pull request #88: plugin grpc Unary

mrproliu commented on code in PR #88:
URL: https://github.com/apache/skywalking-go/pull/88#discussion_r1285009724


##########
docs/en/agent/support-plugins.md:
##########
@@ -13,6 +13,7 @@ metrics based on the tracing data.
   * `dubbo`: [Dubbo](https://github.com/apache/dubbo-go) tested v3.0.1 to v3.0.5.
   * `kratosv2`: [Kratos](https://github.com/go-kratos/kratos) tested v2.3.1 to v2.6.2.
   * `microv4`: [Go-Micro](https://github.com/go-micro/go-micro) tested v4.6.0 to v4.10.2.
+  * `grpc`: [gRPC](https://github.com/grpc/grpc-go) tested v1.56.0 to v1.56.2

Review Comment:
   Can you add more version checks? Because the version iteration of grpc is still very frequent.



##########
plugins/grpc/client_unary_interceptor.go:
##########
@@ -0,0 +1,76 @@
+// Licensed to 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. Apache Software Foundation (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.
+
+package grpc
+
+import (
+	"context"
+	"github.com/apache/skywalking-go/plugins/core/operator"
+	"github.com/apache/skywalking-go/plugins/core/tracing"
+	"google.golang.org/grpc/metadata"
+)
+
+type ClientUnaryInterceptor struct {
+}
+
+func (h *ClientUnaryInterceptor) BeforeInvoke(invocation operator.Invocation) error {
+
+	// 获取参数

Review Comment:
   Please delete the Chinese comments. 



##########
plugins/grpc/client_sendmsg_interceptor.go:
##########
@@ -0,0 +1,73 @@
+// Licensed to 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. Apache Software Foundation (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.
+
+package grpc
+
+import (
+	"github.com/apache/skywalking-go/plugins/core/operator"
+	"github.com/apache/skywalking-go/plugins/core/tracing"
+	"google.golang.org/grpc/peer"
+)
+
+type ClientSendMsgInterceptor struct {
+}
+
+func (h *ClientSendMsgInterceptor) BeforeInvoke(invocation operator.Invocation) error {
+
+	cs := invocation.CallerInstance().(*nativeclientStream)
+	ctx := cs.Context()
+	method := cs.callHdr.Method
+	peerKey, ok := peer.FromContext(ctx)
+	remoteAddr := ""
+	if ok {
+		remoteAddr = peerKey.Addr.String()
+	}
+
+	if remoteAddr == "127.0.0.1:11800" {
+		return nil
+	}
+
+	s, err := tracing.CreateLocalSpan(formatOperationName(method, "/client/Request/sendMsg"),

Review Comment:
   I think all the name should have same case rule. You can choose to capitalize the first letter of all words or not. 



##########
plugins/grpc/client_sendmsg_interceptor.go:
##########
@@ -0,0 +1,73 @@
+// Licensed to 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. Apache Software Foundation (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.
+
+package grpc
+
+import (
+	"github.com/apache/skywalking-go/plugins/core/operator"
+	"github.com/apache/skywalking-go/plugins/core/tracing"
+	"google.golang.org/grpc/peer"
+)
+
+type ClientSendMsgInterceptor struct {
+}
+
+func (h *ClientSendMsgInterceptor) BeforeInvoke(invocation operator.Invocation) error {
+
+	cs := invocation.CallerInstance().(*nativeclientStream)
+	ctx := cs.Context()
+	method := cs.callHdr.Method
+	peerKey, ok := peer.FromContext(ctx)
+	remoteAddr := ""
+	if ok {
+		remoteAddr = peerKey.Addr.String()
+	}
+
+	if remoteAddr == "127.0.0.1:11800" {

Review Comment:
   Same here, please update the checking strategy. 



##########
plugins/grpc/client_unary_interceptor.go:
##########
@@ -0,0 +1,76 @@
+// Licensed to 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. Apache Software Foundation (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.
+
+package grpc
+
+import (
+	"context"
+	"github.com/apache/skywalking-go/plugins/core/operator"
+	"github.com/apache/skywalking-go/plugins/core/tracing"
+	"google.golang.org/grpc/metadata"
+)
+
+type ClientUnaryInterceptor struct {
+}
+
+func (h *ClientUnaryInterceptor) BeforeInvoke(invocation operator.Invocation) error {
+
+	// 获取参数
+	ctx := invocation.Args()[0].(context.Context)
+	method := invocation.Args()[1].(string)
+
+	clientconn := invocation.CallerInstance().(*nativeClientConn)
+	remoteAddr := clientconn.Target()
+	if remoteAddr == "127.0.0.1:11800" {

Review Comment:
   Same here, please delete it. 



##########
plugins/grpc/server_unary_interceptor.go:
##########
@@ -0,0 +1,37 @@
+// Licensed to 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. Apache Software Foundation (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.
+
+package grpc
+
+import (
+	"github.com/apache/skywalking-go/plugins/core/operator"
+	"github.com/apache/skywalking-go/plugins/core/tracing"
+)
+
+type ServerUnaryInterceptor struct {
+}
+
+func (h *ServerUnaryInterceptor) BeforeInvoke(invocation operator.Invocation) error {
+	span := tracing.ActiveSpan()
+	span.Tag("RPCType", "Unary")

Review Comment:
   The activate span could be nil? Please add a nil check. 



##########
plugins/grpc/client_recvmsg_interceptor.go:
##########
@@ -0,0 +1,74 @@
+// Licensed to 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. Apache Software Foundation (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.
+
+package grpc
+
+import (
+	"google.golang.org/grpc/peer"
+
+	"github.com/apache/skywalking-go/plugins/core/operator"
+	"github.com/apache/skywalking-go/plugins/core/tracing"
+)
+
+type ClientRecvMsgInterceptor struct {
+}
+
+func (h *ClientRecvMsgInterceptor) BeforeInvoke(invocation operator.Invocation) error {
+	cs := invocation.CallerInstance().(*nativeclientStream)
+	ctx := cs.Context()
+	method := cs.callHdr.Method
+
+	peerKey, ok := peer.FromContext(ctx)
+	remoteAddr := ""
+	if ok {
+		remoteAddr = peerKey.Addr.String()
+	}
+
+	if remoteAddr == "127.0.0.1:11800" {

Review Comment:
   Why you need to check the this address? The grpc address is uncertainty, even send to the SkyWalking backend. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org