You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "marsevilspirit (via GitHub)" <gi...@apache.org> on 2025/05/28 16:33:11 UTC

[PR] refactor: add triple protocol config and option [dubbo-go]

marsevilspirit opened a new pull request, #2900:
URL: https://github.com/apache/dubbo-go/pull/2900

   The purpose of this PR is to reduce the burden on the ProtocolConfig struct by adding TripleConfig, which handles the config and options related only to the Triple Protocol, thereby enhancing logical clarity.
   
   For example, with the current code, if we want to configure the parameters related to the Triple protocol keepalive, how should we write it:
   
   ```go
   	cli, err := client.NewClient(
   		client.WithClientURL("127.0.0.1:20000"),
   		client.WithClientProtocolTriple(),
   		client.WithKeepAliveInterval(10*time.Second),
   		client.WithKeepAliveTimeout(20*time.Second),
   	)
   ```
   
   At first glance, it seems reasonable, but these two options can also be used when I start other protocols, for example:
   
   ```go
   	cli, err := client.NewClient(
   		client.WithClientURL("127.0.0.1:20000"),
   		client.WithClientProtocolDubbo(),
   		client.WithKeepAliveInterval(10*time.Second),
   		client.WithKeepAliveTimeout(20*time.Second),
   	)
   ```
   
   Well, this is unreasonable because **WithKeepAliveInterval** and **WithKeepAliveTimeout** only take effect for the Triple protocol, yet they can be used like this. This creates a learning cost for users, for example, users are not clear that these two options only take effect for the Triple protocol, and when they write other protocols, they mistakenly believe they will take effect, but actually do not achieve the expected result, debugging for a long time only to find out they only apply to the Triple protocol. Therefore, we should enhance the specificity of options and impose restrictions at the API level.
   
   Moreover, the way parameters are passed and the structure above is also a problem. The API above passes parameters and structures like this:
   
   ```go
   // ProtocolConfig is a shared config for all protocols, it is inappropriate to place parameters unique to Triple here,
   // as the number of parameters grows, ProtocolConfig will become increasingly bloated, and we need to find a way to solve this problem.
   type ProtocolConfig struct {
   	...
   	MaxServerSendMsgSize string
   	MaxServerRecvMsgSize string
   	...
   }
   ```
   
   ```go
   		// The same problem, as the number of parameters increases, the URL configuration will become increasingly bloated,
   		// and the parameters in the URL are difficult to track and extract, relying only on the key to extract one by one and judge whether it is valid.
   		ivkURL := common.NewURLWithOptions(
   			...
   			common.WithParamsValue(constant.MaxServerSendMsgSize, protocolConf.MaxServerSendMsgSize),
   			common.WithParamsValue(constant.MaxServerRecvMsgSize, protocolConf.MaxServerRecvMsgSize),
   			...
   		)
   		
   		// Parameters have to be extracted like this, which is too inefficient, and the code duplication rate is too high, leading to complete confusion with many parameters.
   		url.GetParam(constant.MaxServerRecvMsgSize, "")
   		url.GetParam(constant.MaxServerSendMsgSize, "")
   		...
   ```
   
   I want to create a highly unified API for client and server, for example:
   
   ```go
   	[srv/cli], err := [server/client].New[Server/Client](
   		...
   		[server.client].With[Server/Client]Protocol(
   			protocol.With[XXX](),
   			protocol.With[Triple/...](
   				[triple/...].WithXXX(xxx...),
   				...
   			),
   		),
   		...
   	)
   ```
   
   The actual API looks like this:
   
   server:
   
   ```go
   	srv, err := server.NewServer(
   		server.WithServerProtocol(
   			protocol.WithPort(20000),
   			protocol.WithTriple(
   				triple.WithMaxServerRecvMsgSize("30mb"),
   				triple.WithMaxServerSendMsgSize("30mb"),
   			),
   		),
   	)
   ```
   
   client:
   
   ```go
   	cli, err := client.NewClient(
   		client.WithClientURL("127.0.0.1:20000"),
   		client.WithClientProtocol(
   			protocol.WithTriple(
   				triple.WithKeepAliveInterval(30*time.Second),
   				triple.WithKeepAliveTimeout(30*time.Second),
   			),
   		),
   	)
   ```
   
   This way, there will be no misuse of options that do not take effect.
   
   How did I achieve interface unification?
   
   Mainly by defining interfaces:
   
   ```go
   // ClientOption is an option for the Client
   type ClientOption interface {
   	applyToClient(*ClientOptions)
   }
   
   // ServerOption is an option for the Server
   type ServerOption interface {
   	applyToServer(*ServerOptions)
   }
   
   // Option is a general option, meaning both Client and Server can use it
   type Option interface {
   	ClientOption
   	ServerOption
   }
   ```
   
   How to implement shared options for client and server, I will take the Triple Protocol as an example:
   
   ```go
   type tripleOption struct {
   	triOpts triple.Options
   }
   
   // If the Client can call it, implement the applyToClient method
   func (o *tripleOption) applyToClient(config *ClientOptions) {
   	config.ProtocolClient.TripleConfig = o.triOpts.Triple
   }
   
   // If the Server can call it, implement the applyToServer method
   func (o *tripleOption) applyToServer(config *ServerOptions) {
   	config.Protocol.TripleConfig = o.triOpts.Triple
   }
   
   // The Triple Protocol must be a common option for both Server and Client
   func WithTriple(opts ...triple.Option) Option {
   	triSrvOpts := triple.NewOptions(opts...)
   
   	return &tripleOption{
   		triOpts: *triSrvOpts,
   	}
   }
   ```
   
   After processing all options, just apply them collectively to [Server/Client]:
   
   ```go
   func New[Server/Client]Options(opts ...[Server/Client]Option) *[Server/Client]Options {
   	defOpts := default[Server/Client]Options()
   	for _, opt := range opts {
   		// Apply here
   		opt.applyTo[Server/Client](defOpts)
   	}
   
   	if defOpts.ID == "" {
   		if defOpts.Protocol.Name == "" {
   			// should be the same as default value of config.ProtocolConfig.Protocol
   			defOpts.ID = constant.TriProtocol
   		} else {
   			defOpts.ID = defOpts.Protocol.Name
   		}
   	}
   
   	return defOpts
   }
   ```
   
   How did I simplify parameter passing?
   
   I created the TripleConfig struct and made modifications to the ProtocolConfig struct:
   
   ```go
   type TripleConfig struct {
   	// Parameters unique to the triple protocol are placed in this struct
   	KeepAliveInterval string
   	KeepAliveTimeout  string
   	...
   }
   
   type ProtocolConfig struct {
   	...
   	TripleConfig *TripleConfig
   	...
   }
   ```
   
   The method of passing parameters is also very efficient:
   
   ```go
   	// Directly passing the TripleConfig struct
   	ivkURL := common.NewURLWithOptions(
   		...
   		common.WithAttribute(constant.TripleConfigKey, protocolConf.TripleConfig),
   		...
   	)
   	
   	// Extracting is also done directly by extracting the struct
   	// tripleConf contains all the parameters we want
   	var tripleConf *global.TripleConfig
   	tripleConfRaw, ok := url.GetAttribute(constant.TripleConfigKey)
   	if ok {
   		tripleConf = tripleConfRaw.(*global.TripleConfig)
   	}
   ```
   
   Usage of TripleConfig in YAML files:
   
   server:
   
   ```yaml
   # dubbo server yaml configure file
   dubbo:
     registries:
       demoZK:
         protocol: zookeeper
         timeout: 10s
         address: 127.0.0.1:2181
     protocols:
       tripleProtocol:
         name: tri
         port: 20000
         # triple is the tripleConfig
         triple:
           max-server-send-msg-size: 20mb
           max-server-recv-msg-size: 20mb
     provider:
       services:
         GreetTripleServer:
           interface: com.apache.dubbo.sample.Greeter
   ```
   
   client:
   
   ```yaml
   # dubbo client yaml configure file
   dubbo:
     registries:
       demoZK:
         protocol: zookeeper
         timeout: 3s
         address: 127.0.0.1:2181
     consumer:
       references:
         GreetServiceImpl:
   	      # I know this configuration looks a bit strange, but this protocol is for compatibility with the config package
   	      # After solving the config package issue, the protocol-config may be renamed to protocol
   	      # Unifying the use of protocol configuration
   	      # Here, the protocol is a string type, which makes me laugh XD
   	      # For compatibility, we need version 4.0.0 to remove it
           protocol: tri
           protocol-config:
             # triple is the tripleConfig
             triple:
               keep-alive-interval: 10s
               keep-alive-timeout: 20s
           interface: com.apache.dubbo.sample.Greeter
           registry: demoZK
           retries: 3
           timeout: 3000
   
   # The new version should look like this
   dubbo:
     registries:
       demoZK:
         protocol: zookeeper
         timeout: 3s
         address: 127.0.0.1:2181
     consumer:
       references:
         GreetServiceImpl:
   	      # Looks much better, doesn't it?
           protocol:
   	        name: tri
             triple:
               keep-alive-interval: 10s
               keep-alive-timeout: 20s
           interface: com.apache.dubbo.sample.Greeter
           registry: demoZK
           retries: 3
           timeout: 3000
   ```
   
   The benefits brought by this PR:
   
   1. Greatly expands the flexibility of protocol options
   2. Solves the problem of URLs becoming increasingly bloated
   3. Addresses the issue of ProtocolConfig becoming increasingly bloated
   4. Optimizes the usage of APIs related to Triple, further reducing the learning cost for users


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2114169103


##########
options.go:
##########
@@ -378,8 +378,27 @@ func WithMetadataServiceProtocol(protocol string) InstanceOption {
 	}
 }
 
-func WithProtocol(opts ...protocol.Option) InstanceOption {
-	proOpts := protocol.NewOptions(opts...)
+// TODO: deal this fuction
+// this function I want handle the protocol.Option which
+// both server and client can use together.
+// like:
+//
+//	func WithProtocol(opts ...protocol.Option) InstanceOption {
+//		proOpts := protocol.NewOptions(opts...)
+//
+//		log.Warnf("proOpts: %+v", proOpts)
+//
+//		return func(insOpts *InstanceOptions) {
+//			if insOpts.Protocols == nil {
+//				insOpts.Protocols = make(map[string]*global.ProtocolConfig)
+//			}
+//			insOpts.Protocols[proOpts.ID] = proOpts.Protocol
+//		}
+//	}
+//
+// but now only work in server side fot compat old API.

Review Comment:
   fixed



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2919678634

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [35 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900)
   
   


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2113171613


##########
common/constant/default.go:
##########
@@ -28,7 +28,10 @@ const (
 	OverrideProtocol = "override" //compatible with 2.6.x
 	EmptyProtocol    = "empty"
 	RouterProtocol   = "router"
+	DubboProtocol    = "dubbo"

Review Comment:
   I believe that Dubbo and DubboProtocol are different concepts.
   One is the name of our community, and the other is the name of the protocol.
   Using the community's name as the name of the protocol, although the effect is the same, creates a rather strange feeling.
   I have some hesitation about how to handle this aspect, but from my perspective, this is better than before.



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2927185529

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [35 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900)
   
   


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2113178520


##########
global/protocol_client_config.go:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package global
+
+import (
+	"dubbo.apache.org/dubbo-go/v3/common/constant"
+)
+
+// TODO: find a better name replace ProtocolClientConfig

Review Comment:
   ProtocolClientConfig (tentative) is at the same level as the server's ProtocolConfig in terms of configuration. ProtocolClientConfig includes but is not limited to TripleConfig. In the future, this structure will provide more flexible configuration and options for more parameters. TripleConfig is one layer below ProtocolClientConfig. I am considering dividing TripleConfig into two parts: Server and Client, to achieve separation of server and client options at the Triple level. Therefore, calling it TripleClientConfig is not a good choice.
   
   We currently do not support multi-protocol client configuration, or in other words, we are still unsure whether we should support multi-protocol clients, so ClientProtocolsConfig is not being considered for the time being.



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "No-SilverBullet (via GitHub)" <gi...@apache.org>.
No-SilverBullet merged PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2113179330


##########
protocol/options.go:
##########
@@ -27,20 +27,84 @@ import (
 	"dubbo.apache.org/dubbo-go/v3/protocol/triple"
 )
 
-type Options struct {
+type ClientOption interface {
+	applyToClient(*ClientOptions)
+}
+
+type ServerOption interface {
+	applyToServer(*ServerOptions)
+}
+
+type Option interface {
+	ClientOption
+	ServerOption
+}
+
+// WithClientOptions composes multiple ClientOptions into one.
+func WithClientOptions(options ...ClientOption) ClientOption {
+	return &clientOptionsOption{options}
+}
+
+type clientOptionsOption struct {
+	options []ClientOption

Review Comment:
   Oops, it's a typo mistake, I will fix it soon.



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2953988866

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [35 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900)
   
   


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2114169453


##########
protocol/triple/client.go:
##########
@@ -206,6 +197,13 @@ func newClientManager(url *common.URL) (*clientManager, error) {
 		tlsFlag = true
 	}
 
+	cliKeepAliveOpts, keepAliveInterval, keepAliveTimeout, genKeepAliveOptsErr := genKeepAliveOpts(url)
+	if genKeepAliveOptsErr != nil {
+		return nil, genKeepAliveOptsErr

Review Comment:
   fixed.



##########
protocol/triple/client.go:
##########
@@ -282,6 +280,49 @@ func newClientManager(url *common.URL) (*clientManager, error) {
 	}, nil
 }
 
+func genKeepAliveOpts(url *common.URL) ([]tri.ClientOption, time.Duration, time.Duration, error) {
+	var cliKeepAliveOpts []tri.ClientOption
+
+	// set max send and recv msg size
+	maxCallRecvMsgSize := constant.DefaultMaxCallRecvMsgSize
+	if recvMsgSize, err := humanize.ParseBytes(url.GetParam(constant.MaxCallRecvMsgSize, "")); err == nil && recvMsgSize > 0 {
+		maxCallRecvMsgSize = int(recvMsgSize)
+	}
+	cliKeepAliveOpts = append(cliKeepAliveOpts, tri.WithReadMaxBytes(maxCallRecvMsgSize))
+	maxCallSendMsgSize := constant.DefaultMaxCallSendMsgSize
+	if sendMsgSize, err := humanize.ParseBytes(url.GetParam(constant.MaxCallSendMsgSize, "")); err == nil && sendMsgSize > 0 {
+		maxCallSendMsgSize = int(sendMsgSize)
+	}
+	cliKeepAliveOpts = append(cliKeepAliveOpts, tri.WithSendMaxBytes(maxCallSendMsgSize))
+
+	// set keepalive interval and keepalive timeout
+	// Deprecated:use tripleconfig
+	// TODO: remove KeepAliveInterval and KeepAliveInterval in version 4.0.0
+	keepAliveInterval := url.GetParamDuration(constant.KeepAliveInterval, constant.DefaultKeepAliveInterval)
+	keepAliveTimeout := url.GetParamDuration(constant.KeepAliveTimeout, constant.DefaultKeepAliveTimeout)
+
+	tripleConfRaw, ok := url.GetAttribute(constant.TripleConfigKey)
+	if ok {
+		var parseErr error
+		tripleConf := tripleConfRaw.(*global.TripleConfig)
+		// TODO: handle ParseDuration error
+		if tripleConf != nil && tripleConf.KeepAliveInterval != "" {
+			keepAliveInterval, parseErr = time.ParseDuration(tripleConf.KeepAliveInterval)
+			if parseErr != nil {
+				return nil, 0, 0, parseErr
+			}
+		}
+		if tripleConf != nil && tripleConf.KeepAliveTimeout != "" {
+			keepAliveTimeout, parseErr = time.ParseDuration(tripleConf.KeepAliveTimeout)
+			if parseErr != nil {
+				return nil, 0, 0, parseErr
+			}

Review Comment:
   fixed.



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2114170478


##########
protocol/triple/server.go:
##########
@@ -54,18 +55,18 @@ import (
 // provide functionality.
 type Server struct {
 	triServer *tri.Server
-	cfg       *ServerOptions
+	cfg       *global.TripleConfig
 	mu        sync.RWMutex
 	services  map[string]grpc.ServiceInfo
 }
 
 // NewServer creates a new TRIPLE server.
 // triServer would not be initialized since we could not get configurations here.
-func NewServer(opts ...ServerOption) *Server {
-	newSrvOpts := defaultServerOptions()
-	newSrvOpts.init(opts...)
+// NOTE: Now everything changed, we can initialized triServer now.

Review Comment:
   fixed.



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2113404020


##########
protocol/triple/dubbo3_invoker.go:
##########
@@ -97,9 +98,21 @@ func NewDubbo3Invoker(url *common.URL) (*DubboInvoker, error) {
 	}
 	opts = append(opts, triConfig.WithGRPCMaxCallRecvMessageSize(maxCallRecvMsgSize))
 	opts = append(opts, triConfig.WithGRPCMaxCallSendMessageSize(maxCallSendMsgSize))
+
 	// grpc keepalive config
+	// Deprecated:use tripleconfig
+	// TODO: remove KeepAliveInterval and KeepAliveInterval in version 4.0.0
 	keepAliveInterval := url.GetParamDuration(constant.KeepAliveInterval, constant.DefaultKeepAliveInterval)
 	keepAliveTimeout := url.GetParamDuration(constant.KeepAliveTimeout, constant.DefaultKeepAliveTimeout)
+
+	tripleConfRaw, ok := url.GetAttribute(constant.TripleConfigKey)
+	if ok {
+		tripleConf := tripleConfRaw.(*global.TripleConfig)
+		// TODO: handle ParseDuration error
+		keepAliveInterval, _ = time.ParseDuration(tripleConf.KeepAliveInterval)
+		keepAliveTimeout, _ = time.ParseDuration(tripleConf.KeepAliveTimeout)

Review Comment:
   Consider handling the error returned from time.ParseDuration instead of ignoring it, to avoid unintended behavior when a malformed duration is provided.
   ```suggestion
   		// Handle ParseDuration error
   		parsedInterval, err := time.ParseDuration(tripleConf.KeepAliveInterval)
   		if err != nil {
   			logger.Errorf("Failed to parse KeepAliveInterval: %v, using default value %v", err, keepAliveInterval)
   		} else {
   			keepAliveInterval = parsedInterval
   		}
   		parsedTimeout, err := time.ParseDuration(tripleConf.KeepAliveTimeout)
   		if err != nil {
   			logger.Errorf("Failed to parse KeepAliveTimeout: %v, using default value %v", err, keepAliveTimeout)
   		} else {
   			keepAliveTimeout = parsedTimeout
   		}
   ```



##########
protocol/triple/options.go:
##########
@@ -17,30 +17,78 @@
 
 package triple
 
-type ServerOptions struct {
+import (
+	"time"
+)
+
+import (

Review Comment:
   [nitpick] Consider combining the two separate import blocks into a single import statement for improved readability and maintainability.
   ```suggestion
   
   ```



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2919872660

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [35 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900)
   
   


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2114383656


##########
global/triple_config.go:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+package global
+
+// TODO: Should the server and client configurations be separated?

Review Comment:
   I want to implement this change in the next PR, this PR has already done too much.



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2916955620

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [36 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900)
   
   


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "1kasa (via GitHub)" <gi...@apache.org>.
1kasa commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2112806092


##########
global/protocol_client_config.go:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package global
+
+import (
+	"dubbo.apache.org/dubbo-go/v3/common/constant"
+)
+
+// TODO: find a better name replace ProtocolClientConfig

Review Comment:
   If we support multi-protocol client configuration in the future, I think it can be named ClientProtocolsConfig. If we decide to only configure triple protocol, I think TripleClientConfig will do. What do you think? Or do you have any other ideas?



##########
protocol/options.go:
##########
@@ -27,20 +27,84 @@ import (
 	"dubbo.apache.org/dubbo-go/v3/protocol/triple"
 )
 
-type Options struct {
+type ClientOption interface {
+	applyToClient(*ClientOptions)
+}
+
+type ServerOption interface {
+	applyToServer(*ServerOptions)
+}
+
+type Option interface {
+	ClientOption
+	ServerOption
+}
+
+// WithClientOptions composes multiple ClientOptions into one.
+func WithClientOptions(options ...ClientOption) ClientOption {
+	return &clientOptionsOption{options}
+}
+
+type clientOptionsOption struct {
+	options []ClientOption

Review Comment:
   The S in ServerOptionsOption is capitalized, and the c in clientOptionsOption is lowercase. Is there any special purpose for doing this?



##########
common/constant/default.go:
##########
@@ -28,7 +28,10 @@ const (
 	OverrideProtocol = "override" //compatible with 2.6.x
 	EmptyProtocol    = "empty"
 	RouterProtocol   = "router"
+	DubboProtocol    = "dubbo"

Review Comment:
   I think it will cause some trouble.Dubbo And DubboProtocol.



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2114169946


##########
protocol/triple/server.go:
##########
@@ -174,19 +175,46 @@ func (s *Server) RefreshService(invoker base.Invoker, info *common.ServiceInfo)
 }
 
 func getHanOpts(url *common.URL) (hanOpts []tri.HandlerOption) {
+	var tripleConf *global.TripleConfig
+
+	tripleConfRaw, ok := url.GetAttribute(constant.TripleConfigKey)
+	if ok {
+		tripleConf = tripleConfRaw.(*global.TripleConfig)
+	}
+
+	// Deprecated:use TripleConfig
+	// TODO: remove MaxServerSendMsgSize and MaxServerRecvMsgSize when version 4.0.0
 	var err error
 	maxServerRecvMsgSize := constant.DefaultMaxServerRecvMsgSize
 	if recvMsgSize, convertErr := humanize.ParseBytes(url.GetParam(constant.MaxServerRecvMsgSize, "")); convertErr == nil && recvMsgSize != 0 {
 		maxServerRecvMsgSize = int(recvMsgSize)
 	}
 	hanOpts = append(hanOpts, tri.WithReadMaxBytes(maxServerRecvMsgSize))
 
+	if tripleConf != nil && tripleConf.MaxServerRecvMsgSize != "" {
+		logger.Warnf("MaxServerRecvMsgSize: %v", tripleConf.MaxServerRecvMsgSize)
+		if recvMsgSize, convertErr := humanize.ParseBytes(tripleConf.MaxServerRecvMsgSize); convertErr == nil && recvMsgSize != 0 {
+			maxServerRecvMsgSize = int(recvMsgSize)
+		}
+		hanOpts = append(hanOpts, tri.WithReadMaxBytes(maxServerRecvMsgSize))
+	}
+
+	// Deprecated:use TripleConfig

Review Comment:
   fixed.



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "No-SilverBullet (via GitHub)" <gi...@apache.org>.
No-SilverBullet commented on code in PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#discussion_r2113871374


##########
protocol/triple/client.go:
##########
@@ -206,6 +197,13 @@ func newClientManager(url *common.URL) (*clientManager, error) {
 		tlsFlag = true
 	}
 
+	cliKeepAliveOpts, keepAliveInterval, keepAliveTimeout, genKeepAliveOptsErr := genKeepAliveOpts(url)
+	if genKeepAliveOptsErr != nil {
+		return nil, genKeepAliveOptsErr

Review Comment:
   can we add a error log in here



##########
options.go:
##########
@@ -378,8 +378,27 @@ func WithMetadataServiceProtocol(protocol string) InstanceOption {
 	}
 }
 
-func WithProtocol(opts ...protocol.Option) InstanceOption {
-	proOpts := protocol.NewOptions(opts...)
+// TODO: deal this fuction
+// this function I want handle the protocol.Option which
+// both server and client can use together.
+// like:
+//
+//	func WithProtocol(opts ...protocol.Option) InstanceOption {
+//		proOpts := protocol.NewOptions(opts...)
+//
+//		log.Warnf("proOpts: %+v", proOpts)
+//
+//		return func(insOpts *InstanceOptions) {
+//			if insOpts.Protocols == nil {
+//				insOpts.Protocols = make(map[string]*global.ProtocolConfig)
+//			}
+//			insOpts.Protocols[proOpts.ID] = proOpts.Protocol
+//		}
+//	}
+//
+// but now only work in server side fot compat old API.

Review Comment:
   typo fot



##########
global/triple_config.go:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+package global
+
+// TODO: Should the server and client configurations be separated?

Review Comment:
   i think sepatate the client and server may be more clear



##########
protocol/triple/server.go:
##########
@@ -54,18 +55,18 @@ import (
 // provide functionality.
 type Server struct {
 	triServer *tri.Server
-	cfg       *ServerOptions
+	cfg       *global.TripleConfig
 	mu        sync.RWMutex
 	services  map[string]grpc.ServiceInfo
 }
 
 // NewServer creates a new TRIPLE server.
 // triServer would not be initialized since we could not get configurations here.
-func NewServer(opts ...ServerOption) *Server {
-	newSrvOpts := defaultServerOptions()
-	newSrvOpts.init(opts...)
+// NOTE: Now everything changed, we can initialized triServer now.

Review Comment:
   remove the old comment



##########
protocol/triple/client.go:
##########
@@ -282,6 +280,49 @@ func newClientManager(url *common.URL) (*clientManager, error) {
 	}, nil
 }
 
+func genKeepAliveOpts(url *common.URL) ([]tri.ClientOption, time.Duration, time.Duration, error) {
+	var cliKeepAliveOpts []tri.ClientOption
+
+	// set max send and recv msg size
+	maxCallRecvMsgSize := constant.DefaultMaxCallRecvMsgSize
+	if recvMsgSize, err := humanize.ParseBytes(url.GetParam(constant.MaxCallRecvMsgSize, "")); err == nil && recvMsgSize > 0 {
+		maxCallRecvMsgSize = int(recvMsgSize)
+	}
+	cliKeepAliveOpts = append(cliKeepAliveOpts, tri.WithReadMaxBytes(maxCallRecvMsgSize))
+	maxCallSendMsgSize := constant.DefaultMaxCallSendMsgSize
+	if sendMsgSize, err := humanize.ParseBytes(url.GetParam(constant.MaxCallSendMsgSize, "")); err == nil && sendMsgSize > 0 {
+		maxCallSendMsgSize = int(sendMsgSize)
+	}
+	cliKeepAliveOpts = append(cliKeepAliveOpts, tri.WithSendMaxBytes(maxCallSendMsgSize))
+
+	// set keepalive interval and keepalive timeout
+	// Deprecated:use tripleconfig
+	// TODO: remove KeepAliveInterval and KeepAliveInterval in version 4.0.0
+	keepAliveInterval := url.GetParamDuration(constant.KeepAliveInterval, constant.DefaultKeepAliveInterval)
+	keepAliveTimeout := url.GetParamDuration(constant.KeepAliveTimeout, constant.DefaultKeepAliveTimeout)
+
+	tripleConfRaw, ok := url.GetAttribute(constant.TripleConfigKey)
+	if ok {
+		var parseErr error
+		tripleConf := tripleConfRaw.(*global.TripleConfig)
+		// TODO: handle ParseDuration error
+		if tripleConf != nil && tripleConf.KeepAliveInterval != "" {
+			keepAliveInterval, parseErr = time.ParseDuration(tripleConf.KeepAliveInterval)
+			if parseErr != nil {
+				return nil, 0, 0, parseErr
+			}
+		}
+		if tripleConf != nil && tripleConf.KeepAliveTimeout != "" {
+			keepAliveTimeout, parseErr = time.ParseDuration(tripleConf.KeepAliveTimeout)
+			if parseErr != nil {
+				return nil, 0, 0, parseErr
+			}

Review Comment:
   judge  the  if tripleConf != nil  in the begining
   if tripleConf == nil{
    return XXX
   }
   if tripleConf.KeepAliveInterval != ""{
   xxx
   }



##########
protocol/triple/server.go:
##########
@@ -174,19 +175,46 @@ func (s *Server) RefreshService(invoker base.Invoker, info *common.ServiceInfo)
 }
 
 func getHanOpts(url *common.URL) (hanOpts []tri.HandlerOption) {
+	var tripleConf *global.TripleConfig
+
+	tripleConfRaw, ok := url.GetAttribute(constant.TripleConfigKey)
+	if ok {
+		tripleConf = tripleConfRaw.(*global.TripleConfig)
+	}
+
+	// Deprecated:use TripleConfig
+	// TODO: remove MaxServerSendMsgSize and MaxServerRecvMsgSize when version 4.0.0
 	var err error
 	maxServerRecvMsgSize := constant.DefaultMaxServerRecvMsgSize
 	if recvMsgSize, convertErr := humanize.ParseBytes(url.GetParam(constant.MaxServerRecvMsgSize, "")); convertErr == nil && recvMsgSize != 0 {
 		maxServerRecvMsgSize = int(recvMsgSize)
 	}
 	hanOpts = append(hanOpts, tri.WithReadMaxBytes(maxServerRecvMsgSize))
 
+	if tripleConf != nil && tripleConf.MaxServerRecvMsgSize != "" {
+		logger.Warnf("MaxServerRecvMsgSize: %v", tripleConf.MaxServerRecvMsgSize)
+		if recvMsgSize, convertErr := humanize.ParseBytes(tripleConf.MaxServerRecvMsgSize); convertErr == nil && recvMsgSize != 0 {
+			maxServerRecvMsgSize = int(recvMsgSize)
+		}
+		hanOpts = append(hanOpts, tri.WithReadMaxBytes(maxServerRecvMsgSize))
+	}
+
+	// Deprecated:use TripleConfig

Review Comment:
   same here, judge the if tripleConf != nil in the begining



##########
protocol/triple/options.go:
##########
@@ -17,30 +17,78 @@
 
 package triple
 
-type ServerOptions struct {
+import (
+	"time"
+)
+
+import (
+	"dubbo.apache.org/dubbo-go/v3/global"
+)
+
+// TODO: The triple options for the server and client are mixed together now.
+// We need to find a way to separate them later.
+
+type Options struct {
+	Triple *global.TripleConfig
 }
 
-func defaultServerOptions() *ServerOptions {
-	return &ServerOptions{}
+func defaultOptions() *Options {
+	return &Options{Triple: global.DefaultTripleConfig()}
 }
 
-func NewServerOptions(opts ...ServerOption) *ServerOptions {
-	defSrvOpts := defaultServerOptions()
+func NewOptions(opts ...Option) *Options {
+	defSrvOpts := defaultOptions()
 	for _, opt := range opts {
 		opt(defSrvOpts)
 	}
 	return defSrvOpts
 }
 
-func (srvOpts *ServerOptions) init(opts ...ServerOption) {
-	for _, opt := range opts {
-		opt(srvOpts)
+type Option func(*Options)
+
+// WithKeepAlive sets the keep-alive interval and timeout for the Triple protocol.
+// interval: The duration between keep-alive pings.
+// timeout: The duration to wait for a keep-alive response before considering the connection dead.
+// If not set, default interval is 10s, default timeout is 20s.

Review Comment:
   Gooooooooood comment!
   :)



-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2917019295

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [36 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900)
   
   


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2918307638

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [36 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900)
   
   


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "marsevilspirit (via GitHub)" <gi...@apache.org>.
marsevilspirit commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2919516584

   > Overall it's a very clear PR. I wonder if the compatibility with the old config has been verified.
   
   I have done my utmost to ensure compatibility with the old configuration, but there is one aspect that has not been achieved.
   
   @@ -798,13 +805,18 @@
   client/options.go
   ```go
   -func WithClientProtocol(protocol string) ClientOption {
   -       return func(opts *ClientOptions) {
   -               opts.Consumer.Protocol = protocol
   +func WithClientProtocol(opts ...protocol.ClientOption) ClientOption {
   +       proOpts := protocol.NewClientOptions(opts...)
   +
   +       return func(srvOpts *ClientOptions) {
   +               if srvOpts.overallReference.ProtocolClientConfig == nil {
   +                       srvOpts.overallReference.ProtocolClientConfig = new(global.ProtocolClientConfig)
   +               }
   +               srvOpts.overallReference.ProtocolClientConfig = proOpts.ProtocolClient
           }
    }
   ```
   
   This API i changed.
   
   So there is a **breaking change** actually.
   
   But I think no one will use this option, because we have  `WithClientProtocolXXX()` option, we only use `WithClientProtocolXXX()` option in dubbo-go-samples.


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] refactor: add triple protocol config and option [dubbo-go]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2900:
URL: https://github.com/apache/dubbo-go/pull/2900#issuecomment-2919537129

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [35 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2900&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2900&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2900&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2900)
   
   


-- 
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@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org