@@ -182,62 +182,67 @@ func (g *ConfigGRPCServer) Discover(svr apiconfig.PolarisConfigGRPC_DiscoverServ
182182 continue
183183 }
184184
185- var out * apiconfig.ConfigDiscoverResponse
186- var action string
187- startTime := commontime .CurrentMillisecond ()
188- defer func () {
189- plugin .GetStatis ().ReportDiscoverCall (metrics.ClientDiscoverMetric {
190- Action : action ,
191- ClientIP : utils .ParseClientAddress (ctx ),
192- Namespace : in .GetConfigFile ().GetNamespace ().GetValue (),
193- Resource : metrics .ResourceOfConfigFile (in .GetConfigFile ().GetGroup ().GetValue (), in .GetConfigFile ().GetFileName ().GetValue ()),
194- Timestamp : startTime ,
195- CostTime : commontime .CurrentMillisecond () - startTime ,
196- Revision : out .GetRevision (),
197- Success : out .GetCode () > uint32 (apimodel .Code_DataNoChange ),
198- })
199- }()
200-
201- switch in .Type {
202- case apiconfig .ConfigDiscoverRequest_CONFIG_FILE :
203- action = metrics .ActionGetConfigFile
204- version , _ := strconv .ParseUint (in .GetRevision (), 10 , 64 )
205- ret := g .configServer .GetConfigFileWithCache (ctx , & apiconfig.ClientConfigFileInfo {
206- Namespace : in .GetConfigFile ().GetNamespace (),
207- Group : in .GetConfigFile ().GetGroup (),
208- FileName : in .GetConfigFile ().GetFileName (),
209- Version : wrapperspb .UInt64 (version ),
210- PublicKey : in .GetConfigFile ().GetPublicKey (),
211- })
212- out = api .NewConfigDiscoverResponse (apimodel .Code (ret .GetCode ().GetValue ()))
213- out .ConfigFile = ret .GetConfigFile ()
214- out .Type = apiconfig .ConfigDiscoverResponse_CONFIG_FILE
215- out .Revision = strconv .Itoa (int (out .GetConfigFile ().GetVersion ().GetValue ()))
216- case apiconfig .ConfigDiscoverRequest_CONFIG_FILE_Names :
217- action = metrics .ActionListConfigFiles
218- ret := g .configServer .GetConfigFileNamesWithCache (ctx , & apiconfig.ConfigFileGroupRequest {
219- Revision : wrapperspb .String (in .GetRevision ()),
220- ConfigFileGroup : & apiconfig.ConfigFileGroup {
221- Namespace : in .GetConfigFile ().GetNamespace (),
222- Name : in .GetConfigFile ().GetGroup (),
223- },
224- })
225- out = api .NewConfigDiscoverResponse (apimodel .Code (ret .GetCode ().GetValue ()))
226- out .ConfigFileNames = ret .GetConfigFileInfos ()
227- out .Type = apiconfig .ConfigDiscoverResponse_CONFIG_FILE_Names
228- out .Revision = ret .GetRevision ().GetValue ()
229- case apiconfig .ConfigDiscoverRequest_CONFIG_FILE_GROUPS :
230- action = metrics .ActionListConfigGroups
231- req := in .GetConfigFile ()
232- req .Md5 = wrapperspb .String (in .GetRevision ())
233- out = g .configServer .GetConfigGroupsWithCache (ctx , req )
234- out .Type = apiconfig .ConfigDiscoverResponse_CONFIG_FILE_GROUPS
235- default :
236- out = api .NewConfigDiscoverResponse (apimodel .Code_InvalidDiscoverResource )
237- }
238-
185+ out := g .handleDiscoverRequest (ctx , in )
239186 if err := svr .Send (out ); err != nil {
240187 return err
241188 }
242189 }
243190}
191+
192+ func (g * ConfigGRPCServer ) handleDiscoverRequest (ctx context.Context , in * apiconfig.ConfigDiscoverRequest ) * apiconfig.ConfigDiscoverResponse {
193+ var out * apiconfig.ConfigDiscoverResponse
194+ var action string
195+ startTime := commontime .CurrentMillisecond ()
196+ defer func () {
197+ plugin .GetStatis ().ReportDiscoverCall (metrics.ClientDiscoverMetric {
198+ Action : action ,
199+ ClientIP : utils .ParseClientAddress (ctx ),
200+ Namespace : in .GetConfigFile ().GetNamespace ().GetValue (),
201+ Resource : metrics .ResourceOfConfigFile (in .GetConfigFile ().GetGroup ().GetValue (), in .GetConfigFile ().GetFileName ().GetValue ()),
202+ Timestamp : startTime ,
203+ CostTime : commontime .CurrentMillisecond () - startTime ,
204+ Revision : out .GetRevision (),
205+ Success : out .GetCode () > uint32 (apimodel .Code_DataNoChange ),
206+ })
207+ }()
208+
209+ switch in .Type {
210+ case apiconfig .ConfigDiscoverRequest_CONFIG_FILE :
211+ action = metrics .ActionGetConfigFile
212+ version , _ := strconv .ParseUint (in .GetRevision (), 10 , 64 )
213+ ret := g .configServer .GetConfigFileWithCache (ctx , & apiconfig.ClientConfigFileInfo {
214+ Namespace : in .GetConfigFile ().GetNamespace (),
215+ Group : in .GetConfigFile ().GetGroup (),
216+ FileName : in .GetConfigFile ().GetFileName (),
217+ Version : wrapperspb .UInt64 (version ),
218+ PublicKey : in .GetConfigFile ().GetPublicKey (),
219+ })
220+ out = api .NewConfigDiscoverResponse (apimodel .Code (ret .GetCode ().GetValue ()))
221+ out .ConfigFile = ret .GetConfigFile ()
222+ out .Type = apiconfig .ConfigDiscoverResponse_CONFIG_FILE
223+ out .Revision = strconv .Itoa (int (out .GetConfigFile ().GetVersion ().GetValue ()))
224+ case apiconfig .ConfigDiscoverRequest_CONFIG_FILE_Names :
225+ action = metrics .ActionListConfigFiles
226+ ret := g .configServer .GetConfigFileNamesWithCache (ctx , & apiconfig.ConfigFileGroupRequest {
227+ Revision : wrapperspb .String (in .GetRevision ()),
228+ ConfigFileGroup : & apiconfig.ConfigFileGroup {
229+ Namespace : in .GetConfigFile ().GetNamespace (),
230+ Name : in .GetConfigFile ().GetGroup (),
231+ },
232+ })
233+ out = api .NewConfigDiscoverResponse (apimodel .Code (ret .GetCode ().GetValue ()))
234+ out .ConfigFileNames = ret .GetConfigFileInfos ()
235+ out .Type = apiconfig .ConfigDiscoverResponse_CONFIG_FILE_Names
236+ out .Revision = ret .GetRevision ().GetValue ()
237+ case apiconfig .ConfigDiscoverRequest_CONFIG_FILE_GROUPS :
238+ action = metrics .ActionListConfigGroups
239+ req := in .GetConfigFile ()
240+ req .Md5 = wrapperspb .String (in .GetRevision ())
241+ out = g .configServer .GetConfigGroupsWithCache (ctx , req )
242+ out .Type = apiconfig .ConfigDiscoverResponse_CONFIG_FILE_GROUPS
243+ default :
244+ out = api .NewConfigDiscoverResponse (apimodel .Code_InvalidDiscoverResource )
245+ }
246+
247+ return out
248+ }
0 commit comments