Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
Alanxtl merged PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
sonarqubecloud[bot] commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5762040732 ## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) **Quality Gate passed** Issues  [4 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=ACCEPTED) Measures  [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_coverage&view=list)  [1.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_duplicated_lines_density&view=list) [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
Alanxtl commented on code in PR #3711:
URL: https://github.com/apache/dubbo-go/pull/3711#discussion_r4024717376
##
metadata/definition/types.go:
##
@@ -0,0 +1,561 @@
+/*
+ * 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 definition
+
+import (
+ "errors"
+ "fmt"
+ "reflect"
+ "sort"
+ "strings"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/internal/genericfield"
+)
+
+// maxTypeDepth bounds structural nesting. The visited set already terminates
+// reference cycles, so this only catches pathologically deep composite types
+// (a [][][]...[]T built by code generation, say) before they exhaust the
stack.
+const maxTypeDepth = 64
+
+// unsupportedError marks a type or method the builder refuses to publish.
+//
+// Refusing is deliberate: a schema that silently degrades an unrepresentable
+// type produces requests the provider cannot realize, and the failure surfaces
+// at call time on the Admin side rather than at publish time here. Java has no
+// equivalent problem — erasure yields an incomplete TypeDefinition, but Java
has
+// no chan or func to describe in the first place.
+type unsupportedError struct {
+ subject string
+ reason string
+}
+
+func (e *unsupportedError) Error() string {
+ return fmt.Sprintf("%s is not supported: %s", e.subject, e.reason)
+}
+
+func unsupported(subject, reason string) error {
+ return &unsupportedError{subject: subject, reason: reason}
+}
+
+// IsUnsupported reports whether err marks a type or method the builder
+// deliberately declined to publish, as opposed to an internal failure.
+func IsUnsupported(err error) bool {
+ var target *unsupportedError
+ return errors.As(err, &target)
+}
+
+// blockedNamedTypes are named types the Generalizer or hessian2 codec treats
+// specially, but for which the MCP proposal has not yet defined a JSON wire
+// representation. Expanding them as plain structs would publish their internal
+// layout (time.Time's wall/ext/loc, big.Int's neg/abs) as if it were the
+// contract, which is worse than not publishing the method at all.
+//
+// Named scalars are deliberately absent: time.Duration is an int64 that
+// round-trips as a number like any other, so the scalar branch below handles
it
+// correctly. Only types whose structure would be misrepresented belong here.
+var blockedNamedTypes = map[string]string{
+ "time.Time":"no JSON wire representation is defined for
time.Time yet",
+ "math/big.Int": "no JSON wire representation is defined for
math/big types yet",
+ "math/big.Float": "no JSON wire representation is defined for
math/big types yet",
+ "math/big.Rat": "no JSON wire representation is defined for
math/big types yet",
+ "encoding/json.RawMessage": "raw JSON has no declarable structure",
+}
+
+// Java type names used by the published contract.
+//
+// The definition speaks Java's type vocabulary rather than Go's. That is not a
+// concession to any particular consumer: it is the vocabulary dubbo-go's own
+// generic runtime already uses. filter/generic matches the caller-supplied
+// $invoke types against protocol/dubbo/hessian2.GetJavaName output when it
+// decides whether to unwrap a packed variadic tail, so a Go-spelled contract
+// would describe names that dubbo-go itself does not recognize.
+//
+// Struct names are the exception and stay Go-derived unless the type declares
a
+// Java class name; see resolveStruct.
+const (
+ javaBoolean = "boolean"
+ javaByte= "byte"
+ javaShort = "short"
+ javaInt = "int"
+ javaLong= "long"
+ javaFloat = "float"
+ javaDouble = "double"
+ javaString = "java.lang.String"
+ javaMap = "java.util.Map"
+)
+
+// javaWrappers maps each primitive spelling to its boxed counterpart.
+//
+// Go's T versus *T is exactly Java's primitive versus wrapper distinction, and
+// consumers read nullability off that: a primitive rejects null, a reference
+// type accepts it. Expressing it through the type name means the contract
needs
+// no separate nullability flag, which Provider metadata has
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
Oxidaner commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5651045337 @Alanxtl @AlexStocks DONE -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
sonarqubecloud[bot] commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5535668693 ## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) **Quality Gate passed** Issues  [4 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=ACCEPTED) Measures  [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_coverage&view=list)  [1.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_duplicated_lines_density&view=list) [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
sonarqubecloud[bot] commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5528262575 ## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) **Quality Gate passed** Issues  [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=ACCEPTED) Measures  [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_coverage&view=list)  [1.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_duplicated_lines_density&view=list) [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
AlexStocks commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5525814864 @Oxidaner please fix the file confiction. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
Oxidaner commented on code in PR #3711:
URL: https://github.com/apache/dubbo-go/pull/3711#discussion_r3923915673
##
metadata/definition/definition.go:
##
@@ -0,0 +1,117 @@
+/*
+ * 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 definition builds and publishes interface-level service definitions.
+//
+// A service definition describes the RPC contract of a single exported service
+// interface: its methods, their signatures, and the structure of every type
+// reachable from those signatures. Dubbo Admin consumes these definitions to
+// render service documentation and to build generic-invocation request
schemas.
+//
+// The JSON produced here is wire-compatible with Java's FullServiceDefinition
+// (dubbo-common/.../definition/model/), because Admin deserializes both into
the
+// same ServiceProviderMetadata structure. Nothing in this package imports
Admin
+// code — the compatibility contract is the JSON shape alone, pinned by the
+// golden tests in json_test.go.
+package definition
+
+// ServiceDefinition is the interface-level contract published for one exported
+// service. It mirrors Java's FullServiceDefinition.
+//
+// Java's codeSource field is deliberately omitted: Admin never reads it, and
Go
+// has no equivalent notion of a class file origin.
+type ServiceDefinition struct {
+ // CanonicalName is the service interface name, always taken verbatim
from
+ // the exported URL's Interface(). See BuildFromURL for why this must
not be
+ // re-derived by reflection.
+ CanonicalName string `json:"canonicalName"`
+ // Methods holds one entry per canonical method the builder considers
safe to
+ // expose. This is not the same set as Parameters["methods"]; see
Parameters.
+ Methods []MethodDefinition `json:"methods"`
+ // Parameters carries the full provider URL parameter map, matching
Java's
+ // serviceDefinition.setParameters(url.getParameters()).
+ //
+ // Parameters["methods"] is the runtime method set from the exported
URL and
+ // includes the SwapCaseFirstRune aliases dubbo-go registers for Java
+ // interop. Methods above holds only canonical names. The two
intentionally
+ // differ in size; consumers must not assume they match.
+ Parameters map[string]string `json:"parameters"`
+ // Types holds one entry for every composite type reachable from a
method
+ // signature, including struct, slice, array and map shapes. Pointers
express
+ // nullability and are folded into Java reference/wrapper spellings.
+ Types []TypeDefinition `json:"types"`
+}
+
+// MethodDefinition describes a single RPC method's signature.
+type MethodDefinition struct {
+ // Name is the canonical wire name: the MethodMapper mapping when one
exists,
+ // otherwise the Go exported method name. The SwapCaseFirstRune alias is
+ // never published here even though it is routable at runtime.
+ Name string `json:"name"`
+ // ParameterTypes holds the type expression of each parameter, in order,
+ // excluding the receiver and a leading context.Context.
+ ParameterTypes []string `json:"parameterTypes"`
+ // Parameters pairs each parameter type with a positional name.
+ //
+ // Java's equivalent field is @Deprecated and carries TypeDefinition
elements
+ // with no name at all. Go publishes {name, type} instead because
Admin's
+ // Parameter message has both fields, and Go reflection cannot recover
source
+ // parameter names — so the names here are always generated
(arg0..argN).
+ Parameters []ParameterDefinition `json:"parameters"`
+ // ReturnType is the type expression of the non-error return value, or
+ // VoidReturnType for a method that returns only error.
+ ReturnType string `json:"returnType"`
Review Comment:
ok, i will revise it.
--
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: [email protected]
For queries about this service, please contact
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
Alanxtl commented on code in PR #3711:
URL: https://github.com/apache/dubbo-go/pull/3711#discussion_r3903685061
##
metadata/report/nacos/report.go:
##
@@ -307,6 +308,31 @@ func (n *nacosMetadataReport) ListAppRevisions(application
string) ([]report.App
return result, nil
}
+// PublishServiceDefinition stores one interface-level service definition,
+// implementing report.ServiceDefinitionPublisher.
+//
+// The dataId is byte-compatible with Java's MetadataIdentifier.getUniqueKey,
and
+// the Nacos group is the fixed "dubbo" that Dubbo Admin's watcher searches —
+// deliberately not n.group, which serves the application-level metadata
written
+// by PublishAppMetadata and defaults to DEFAULT_GROUP. See definition.DataID.
+//
+// PublishConfig overwrites in place, so republishing on every provider start
is
+// idempotent: the key is derived only from the service identity, never from
the
+// instance.
+func (n *nacosMetadataReport) PublishServiceDefinition(serviceInterface,
version, group, application, definitionJSON string) error {
+ dataID := definition.DataID(serviceInterface, version, group,
application)
+ if err := n.storeMetadata(vo.ConfigParam{
+ DataId: dataID,
+ Group: definition.MetadataGroup,
+ Content: definitionJSON,
+ }); err != nil {
+ return perrors.WithMessagef(err, "publishing service definition
%s", dataID)
+ }
+ logger.Debugf("[Metadata][Nacos] published service definition,
dataId=%s group=%s",
+ dataID, definition.MetadataGroup)
+ return nil
+}
+
Review Comment:
```go
Group: definition.MetadataGroup // 固定为 "dubbo"
```
该实现没有使用 `n.group`。因此配置 `metadata-report.group=foo` 时,应用级 metadata 在 `foo`,但
service definition 仍发布到 `dubbo`。多个 Nacos group 之间还可能因为相同 DataID 相互覆盖,破坏隔离性。
Java 的 Nacos metadata report 使用配置的 group,参见
[[NacosMetadataReport.java](https://github.com/apache/dubbo/blob/3.3/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java)](https://github.com/apache/dubbo/blob/3.3/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java)。
##
metadata/definition/definition.go:
##
@@ -0,0 +1,117 @@
+/*
+ * 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 definition builds and publishes interface-level service definitions.
+//
+// A service definition describes the RPC contract of a single exported service
+// interface: its methods, their signatures, and the structure of every type
+// reachable from those signatures. Dubbo Admin consumes these definitions to
+// render service documentation and to build generic-invocation request
schemas.
+//
+// The JSON produced here is wire-compatible with Java's FullServiceDefinition
+// (dubbo-common/.../definition/model/), because Admin deserializes both into
the
+// same ServiceProviderMetadata structure. Nothing in this package imports
Admin
+// code — the compatibility contract is the JSON shape alone, pinned by the
+// golden tests in json_test.go.
+package definition
+
+// ServiceDefinition is the interface-level contract published for one exported
+// service. It mirrors Java's FullServiceDefinition.
+//
+// Java's codeSource field is deliberately omitted: Admin never reads it, and
Go
+// has no equivalent notion of a class file origin.
+type ServiceDefinition struct {
+ // CanonicalName is the service interface name, always taken verbatim
from
+ // the exported URL's Interface(). See BuildFromURL for why this must
not be
+ // re-derived by reflection.
+ CanonicalName string `json:"canonicalName"`
+ // Methods holds one entry per canonical method the builder considers
safe to
+ // expose. This is not the same set as Parameters["methods"]; see
Parameters.
+ Methods []MethodDefinition `json:"methods"`
+ // Parameters carries the full provider URL parameter map, matching
Java's
+ // serviceDefinition.setParameters(url.getParameters()).
+ //
+ // Parameters["methods"] is the runtime method set from
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
Oxidaner commented on code in PR #3711:
URL: https://github.com/apache/dubbo-go/pull/3711#discussion_r3895361665
##
metadata/service_definition.go:
##
@@ -0,0 +1,219 @@
+/*
+ * 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 metadata
+
+import (
+ "encoding/json"
+ "sort"
+)
+
+import (
+ "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/metadata/definition"
+ "dubbo.apache.org/dubbo-go/v3/metadata/report"
+)
+
+// PublishServiceDefinitions builds and publishes an interface-level service
+// definition for each exported URL that carries a describable contract, and
+// returns the URLs whose publish failed for a reason worth retrying.
+//
+// No error is returned and nothing here blocks. A provider whose definition
did
+// not reach the metadata center is still a working provider — it is only
+// invisible to Admin's console — so a metadata-center outage must not keep
+// instances out of traffic. Java reaches the same outcome by a different
route:
+// AbstractMetadataReport defaults sync-report to false and hands the write to
an
+// executor, so export never observes the result at all.
+//
+// Only write failures come back. A service that has no describable contract —
+// unregistered, unbuildable, or with no publishable methods — is reported in
the
+// log and dropped, because retrying cannot change any of those.
+//
+// Publishing is idempotent and keyed only by service identity, so calling this
+// on every start, on each cycle-report pass, and on every retry simply
+// overwrites the previous document.
+func PublishServiceDefinitions(urls []*common.URL) []*common.URL {
+ publishers := serviceDefinitionPublishers()
+ if len(publishers) == 0 {
+ return nil
+ }
+
+ var failed []*common.URL
+ for _, u := range dedupeByService(urls) {
+ if !publishServiceDefinition(u, publishers) {
+ failed = append(failed, u)
+ }
+ }
+ return failed
+}
+
+// publishServiceDefinition reports whether the caller should retry.
+//
+// A partial failure across several reports counts as a failure: the retry
+// republishes to all of them, which is harmless because each write overwrites.
+func publishServiceDefinition(u *common.URL, publishers
[]report.ServiceDefinitionPublisher) bool {
+ svc := common.ServiceMap.GetServiceByServiceKey(u.Protocol,
u.ServiceKey())
+ if svc == nil {
+ logger.Warnf("[Metadata][Definition] no registered service for
%s/%s, skipping definition",
+ u.Protocol, u.ServiceKey())
+ return true
+ }
+
+ def, skips, err := definition.BuildFromURL(u, svc.ServiceType())
+ if err != nil {
+ logger.Errorf("[Metadata][Definition] could not build
definition for %s: %v", u.ServiceKey(), err)
+ return true
+ }
+ for _, skip := range skips {
+ logger.Warnf("[Metadata][Definition] method %s.%s is not
published: %s",
+ def.CanonicalName, skip.Name, skip.Reason)
+ }
+ if len(def.Methods) == 0 {
+ logger.Warnf("[Metadata][Definition] %s has no publishable
methods, skipping definition",
+ def.CanonicalName)
+ return true
+ }
+
+ payload, err := json.Marshal(def)
+ if err != nil {
+ logger.Errorf("[Metadata][Definition] could not serialize
definition for %s: %v",
+ def.CanonicalName, err)
+ return true
+ }
+
+ application := u.GetParam(constant.ApplicationKey, "")
+ published := true
+ for _, publisher := range publishers {
+ if err := publisher.PublishServiceDefinition(
+ def.CanonicalName, u.Version(), u.Group(), application,
string(payload),
+ ); err != nil {
+ logger.Errorf("[Metadata][Definition] could not publish
definition for %s: %v",
+ def.CanonicalName,
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
Oxidaner commented on code in PR #3711:
URL: https://github.com/apache/dubbo-go/pull/3711#discussion_r3895363951
##
metadata/options.go:
##
@@ -309,3 +325,12 @@ func WithRegistryId(id string) ReportOption {
opts.registryId = id
}
}
+
+// WithReportDefinition toggles publishing of interface-level service
+// definitions to this report. Definitions are published by default; pass false
+// to opt out. Mirrors Java's MetadataReportConfig.reportDefinition.
+func WithReportDefinition(report bool) ReportOption {
+ return func(opts *ReportOptions) {
+ opts.ReportDefinition = &report
Review Comment:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
sonarqubecloud[bot] commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5479225501 ## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) **Quality Gate passed** Issues  [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=ACCEPTED) Measures  [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_coverage&view=list)  [0.9% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_duplicated_lines_density&view=list) [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
sonarqubecloud[bot] commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5469966258 ## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) **Quality Gate passed** Issues  [2 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=ACCEPTED) Measures  [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_coverage&view=list)  [1.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_duplicated_lines_density&view=list) [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
AlexStocks commented on code in PR #3711:
URL: https://github.com/apache/dubbo-go/pull/3711#discussion_r3885988326
##
metadata/options.go:
##
@@ -309,3 +325,12 @@ func WithRegistryId(id string) ReportOption {
opts.registryId = id
}
}
+
+// WithReportDefinition toggles publishing of interface-level service
+// definitions to this report. Definitions are published by default; pass false
+// to opt out. Mirrors Java's MetadataReportConfig.reportDefinition.
+func WithReportDefinition(report bool) ReportOption {
+ return func(opts *ReportOptions) {
+ opts.ReportDefinition = &report
Review Comment:
[P1] report-definition=false 没有进入真实实例初始化路径
这个 option 只把值写进当前 ReportOptions,但公开入口 dubbo.WithMetadataReport(...) 随后只保存内嵌的
MetadataReportConfig,启动时 initMetadataReport -> reportConfigToReportOptions
又重新构造一份 ReportOptions,却没有复制 ReportDefinition。因此无论 YAML 中配置
metadata-report.report-definition: false,还是调用
dubbo.WithMetadataReport(metadata.WithReportDefinition(false)),这里的值最终都会变回
nil,toUrl 不写开关,而发布端按默认 true 继续上报。我用真实转换函数做了负向探针,返回的 opts.ReportDefinition 确认为
nil。请在 reportConfigToReportOptions 中透传这个三态字段,并补一条从 dubbo.NewInstance/公开
Instance option 到最终 report URL 的回归测试。
##
metadata/service_definition.go:
##
@@ -0,0 +1,219 @@
+/*
+ * 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 metadata
+
+import (
+ "encoding/json"
+ "sort"
+)
+
+import (
+ "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/metadata/definition"
+ "dubbo.apache.org/dubbo-go/v3/metadata/report"
+)
+
+// PublishServiceDefinitions builds and publishes an interface-level service
+// definition for each exported URL that carries a describable contract, and
+// returns the URLs whose publish failed for a reason worth retrying.
+//
+// No error is returned and nothing here blocks. A provider whose definition
did
+// not reach the metadata center is still a working provider — it is only
+// invisible to Admin's console — so a metadata-center outage must not keep
+// instances out of traffic. Java reaches the same outcome by a different
route:
+// AbstractMetadataReport defaults sync-report to false and hands the write to
an
+// executor, so export never observes the result at all.
+//
+// Only write failures come back. A service that has no describable contract —
+// unregistered, unbuildable, or with no publishable methods — is reported in
the
+// log and dropped, because retrying cannot change any of those.
+//
+// Publishing is idempotent and keyed only by service identity, so calling this
+// on every start, on each cycle-report pass, and on every retry simply
+// overwrites the previous document.
+func PublishServiceDefinitions(urls []*common.URL) []*common.URL {
+ publishers := serviceDefinitionPublishers()
+ if len(publishers) == 0 {
+ return nil
+ }
+
+ var failed []*common.URL
+ for _, u := range dedupeByService(urls) {
+ if !publishServiceDefinition(u, publishers) {
+ failed = append(failed, u)
+ }
+ }
+ return failed
+}
+
+// publishServiceDefinition reports whether the caller should retry.
+//
+// A partial failure across several reports counts as a failure: the retry
+// republishes to all of them, which is harmless because each write overwrites.
+func publishServiceDefinition(u *common.URL, publishers
[]report.ServiceDefinitionPublisher) bool {
+ svc := common.ServiceMap.GetServiceByServiceKey(u.Protocol,
u.ServiceKey())
+ if svc == nil {
+ logger.Warnf("[Metadata][Definition] no registered service for
%s/%s, skipping definition",
+ u.Protocol, u.ServiceKey())
+ return true
+ }
+
+ def, skips, err := definition.BuildFromURL(u, svc.ServiceType())
+ if err != nil {
+ logger.Errorf("[Metadata][Definition] could not build
definition for %s: %v", u.ServiceKey(), err)
+ return true
+ }
+ for _, skip := range skips
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
sonarqubecloud[bot] commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5459847760 ## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) **Quality Gate passed** Issues  [2 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=ACCEPTED) Measures  [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_coverage&view=list)  [1.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_duplicated_lines_density&view=list) [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
codecov-commenter commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5456871364 ## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report :x: Patch coverage is `80.25594%` with `108 lines` in your changes missing coverage. Please review. :white_check_mark: Project coverage is 56.55%. Comparing base ([`60d1c2a`](https://app.codecov.io/gh/apache/dubbo-go/commit/60d1c2a949f0ee0da4be3fe09fb79d295491e040?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`bd567cc`](https://app.codecov.io/gh/apache/dubbo-go/commit/bd567cc93f42afd14fd9b5e0b81304cca0dfec62?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)). :warning: Report is 957 commits behind head on develop. | [Files with missing lines](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines | |---|---|---| | [metadata/definition/types.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&filepath=metadata%2Fdefinition%2Ftypes.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWV0YWRhdGEvZGVmaW5pdGlvbi90eXBlcy5nbw==) | 83.15% | [24 Missing and 8 partials :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | | [common/rpc\_service.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&filepath=common%2Frpc_service.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3JwY19zZXJ2aWNlLmdv) | 68.96% | [15 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | | [metadata/service\_definition.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&filepath=metadata%2Fservice_definition.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWV0YWRhdGEvc2VydmljZV9kZWZpbml0aW9uLmdv) | 81.39% | [11 Missing and 5 partials :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | | [...try/servicediscovery/service\_discovery\_registry.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&filepath=registry%2Fservicediscovery%2Fservice_discovery_registry.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cmVnaXN0cnkvc2VydmljZWRpc2NvdmVyeS9zZXJ2aWNlX2Rpc2NvdmVyeV9yZWdpc3RyeS5nbw==) | 81.60% | [10 Missing and 6 partials :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | | [metadata/report/nacos/report.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&filepath=metadata%2Freport%2Fnacos%2Freport.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWV0YWRhdGEvcmVwb3J0L25hY29zL3JlcG9ydC5nbw==) | 0.00% | [11 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | | [metadata/options.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&filepath=metadata%2Foptions.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWV0YWRhdGEvb3B0aW9ucy5nbw==) | 0.00% | [7 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | | [metadata/definition/builder.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&filepath=metadata%2Fdefinition%2Fbuilder.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-bWV0YWRhdGEvZGVmaW5pdGlvbi9idWlsZGVyLmdv) | 94.93% | [2 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3711?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | |
Re: [PR] feat(metadata): publish interface-level service definitions [dubbo-go]
sonarqubecloud[bot] commented on PR #3711: URL: https://github.com/apache/dubbo-go/pull/3711#issuecomment-5456641535 ## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) **Quality Gate passed** Issues  [2 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3711&issueStatuses=ACCEPTED) Measures  [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3711&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_coverage&view=list)  [1.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3711&metric=new_duplicated_lines_density&view=list) [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3711) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
