Copilot commented on code in PR #1477:
URL: https://github.com/apache/dubbo-admin/pull/1477#discussion_r3294300858
##########
ui-vue3/src/views/traffic/routingRule/tabs/updateByYAMLView.vue:
##########
@@ -134,14 +143,25 @@ const updateRoutingRule = async () => {
try {
const data = yaml.load(YAMLValue.value)
data.configVersion = 'v3.0'
- const res = await updateConditionRuleAPI(<string>route.params?.ruleName,
data)
+ const res = await updateConditionRuleAPI(route.params?.ruleName as string,
data, {
+ expectedVersionId: currentVersionId.value
+ })
if (res.code === HTTP_STATUS.SUCCESS) {
message.success('update success')
// 延迟 2 秒后再获取数据,确保数据库已更新
await new Promise((resolve) => setTimeout(resolve, 2000))
TAB_STATE.conditionRule = null
await getRoutingRuleDetail()
+ await reloadCurrentVersion()
}
+ } catch (e: any) {
+ notifyRuleVersionError(e, {
+ reload: async () => {
+ TAB_STATE.conditionRule = null
+ await getRoutingRuleDetail()
+ await reloadCurrentVersion()
+ }
+ })
} finally {
Review Comment:
The `catch` block only calls `notifyRuleVersionError(...)` and then swallows
the exception. If the failure is not a VERSION_CONFLICT /
VERSION_LEDGER_PENDING (e.g. YAML parse errors or `yaml.load` returning a
non-object, causing `data.configVersion = ...` to throw), the user may not see
any feedback and the error won’t propagate. Consider rethrowing or falling back
to a generic error message when `notifyRuleVersionError` returns false.
##########
pkg/core/versioning/component.go:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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 versioning
+
+import (
+ "errors"
+ "fmt"
+ "math"
+
+ versioningcfg "github.com/apache/dubbo-admin/pkg/config/versioning"
+ "github.com/apache/dubbo-admin/pkg/core/events"
+ "github.com/apache/dubbo-admin/pkg/core/governor"
+ "github.com/apache/dubbo-admin/pkg/core/logger"
+ "github.com/apache/dubbo-admin/pkg/core/manager"
+ "github.com/apache/dubbo-admin/pkg/core/runtime"
+ "gorm.io/gorm"
+)
+
+const ComponentType runtime.ComponentType = "rule versioning"
+
+func init() {
+ runtime.RegisterComponent(&component{})
+}
+
+type Component interface {
+ runtime.Component
+ Service() Service
+}
+
+type component struct {
+ service Service
+ store Store
+ subscribers []*Subscriber
+}
+
+func (c *component) Type() runtime.ComponentType {
+ return ComponentType
+}
+
+func (c *component) Order() int {
+ return math.MaxInt - 5
+}
+
+func (c *component) RequiredDependencies() []runtime.ComponentType {
+ return []runtime.ComponentType{
+ runtime.EventBus,
+ runtime.ResourceStore,
+ runtime.ResourceManager,
+ }
+}
+
+func (c *component) Init(ctx runtime.BuilderContext) error {
+ cfg := ctx.Config().Versioning
+ if cfg == nil {
+ cfg = versioningcfg.Default()
+ }
+ storeComponent, err := ctx.GetActivatedComponent(runtime.ResourceStore)
+ if err != nil {
+ return err
+ }
+ store := Store(NewMemoryStore())
+ if sc, ok := storeComponent.(interface {
+ GetDB() (*gorm.DB, bool)
+ }); ok {
+ if db, exists := sc.GetDB(); exists {
+ gormStore := NewGormStore(db)
+ if err := gormStore.AutoMigrate(); err != nil {
+ return err
Review Comment:
`AutoMigrate()` is executed as soon as a DB connection is available, even
when `versioning.enabled` is false. This will still create/alter the versioning
tables on startup, which contradicts the feature-flag behavior described in the
PR (disabled-by-default should avoid DB noise). Consider gating the
`AutoMigrate()` call behind `cfg.Enabled` (or an explicit “migrateWhenDisabled”
config) so disabled deployments do not create these tables.
##########
pkg/console/handler/rule_version.go:
##########
@@ -0,0 +1,260 @@
+/*
+ * 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 handler
+
+import (
+ "errors"
+ "net/http"
+ "strconv"
+ "strings"
+
+ "github.com/gin-contrib/sessions"
+ "github.com/gin-gonic/gin"
+
+ "github.com/apache/dubbo-admin/pkg/common/bizerror"
+ consolectx "github.com/apache/dubbo-admin/pkg/console/context"
+ "github.com/apache/dubbo-admin/pkg/console/model"
+ "github.com/apache/dubbo-admin/pkg/console/service"
+ coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
+ "github.com/apache/dubbo-admin/pkg/core/versioning"
+)
+
+type rollbackReq struct {
+ Reason string `json:"reason"`
+ ExpectedVersionID *int64 `json:"expectedVersionId"`
+}
+
+type abandonIntentReq struct {
+ Reason string `json:"reason"`
+}
+
+const maxRuleVersionReasonLength = 1024
+
+func ListRuleVersions(cs consolectx.Context, kind coremodel.ResourceKind)
gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ resp, err := service.ListRuleVersions(cs,
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name:
c.Param("ruleName")})
+ writeVersioningResp(c, resp, err)
+ }
+}
+
+func GetRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind)
gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ id, ok := parseVersionID(c)
+ if !ok {
+ return
+ }
+ resp, err := service.GetRuleVersion(cs,
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name:
c.Param("ruleName")}, id)
+ writeVersioningResp(c, resp, err)
+ }
+}
+
+func DiffRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind)
gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ id, ok := parseVersionID(c)
+ if !ok {
+ return
+ }
+ resp, err := service.DiffRuleVersion(cs,
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name:
c.Param("ruleName")}, id, c.Query("against"))
+ writeVersioningResp(c, resp, err)
+ }
+}
+
+func RollbackRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind)
gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ id, ok := parseVersionID(c)
+ if !ok {
+ return
+ }
+ req := rollbackReq{}
+ if err := c.ShouldBindJSON(&req); err != nil {
+ c.JSON(http.StatusOK,
model.NewBizErrorResp(bizerror.New(bizerror.InvalidArgument, err.Error())))
+ return
+ }
+ if !validateRuleVersionReasonLength(c, req.Reason) {
+ return
+ }
+ resp, err := service.RollbackRuleVersion(cs,
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name:
c.Param("ruleName")}, id, req.Reason, req.ExpectedVersionID, currentUser(c))
+ writeVersioningResp(c, resp, err)
+ }
+}
+
+func RepairRuleVersionIntent(cs consolectx.Context) gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ id, ok := parseIntentID(c)
+ if !ok {
+ return
+ }
+ resp, err := service.RepairRuleVersionIntent(cs, id)
+ writeVersioningResp(c, resp, err)
+ }
+}
+
+func AbandonRuleVersionIntent(cs consolectx.Context) gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ id, ok := parseIntentID(c)
+ if !ok {
+ return
+ }
+ req := abandonIntentReq{}
+ if err := c.ShouldBindJSON(&req); err != nil {
+ c.JSON(http.StatusOK,
model.NewBizErrorResp(bizerror.New(bizerror.InvalidArgument, err.Error())))
Review Comment:
`ShouldBindJSON` failures are returned with HTTP 200 here, while
`writeVersioningResp` maps `InvalidArgument` to HTTP 400. Consider returning
`http.StatusBadRequest` (or delegating to `writeVersioningResp`) for
consistency across the versioning endpoints.
##########
pkg/console/handler/rule_version.go:
##########
@@ -0,0 +1,260 @@
+/*
+ * 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 handler
+
+import (
+ "errors"
+ "net/http"
+ "strconv"
+ "strings"
+
+ "github.com/gin-contrib/sessions"
+ "github.com/gin-gonic/gin"
+
+ "github.com/apache/dubbo-admin/pkg/common/bizerror"
+ consolectx "github.com/apache/dubbo-admin/pkg/console/context"
+ "github.com/apache/dubbo-admin/pkg/console/model"
+ "github.com/apache/dubbo-admin/pkg/console/service"
+ coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
+ "github.com/apache/dubbo-admin/pkg/core/versioning"
+)
+
+type rollbackReq struct {
+ Reason string `json:"reason"`
+ ExpectedVersionID *int64 `json:"expectedVersionId"`
+}
+
+type abandonIntentReq struct {
+ Reason string `json:"reason"`
+}
+
+const maxRuleVersionReasonLength = 1024
+
+func ListRuleVersions(cs consolectx.Context, kind coremodel.ResourceKind)
gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ resp, err := service.ListRuleVersions(cs,
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name:
c.Param("ruleName")})
+ writeVersioningResp(c, resp, err)
+ }
+}
+
+func GetRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind)
gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ id, ok := parseVersionID(c)
+ if !ok {
+ return
+ }
+ resp, err := service.GetRuleVersion(cs,
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name:
c.Param("ruleName")}, id)
+ writeVersioningResp(c, resp, err)
+ }
+}
+
+func DiffRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind)
gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ id, ok := parseVersionID(c)
+ if !ok {
+ return
+ }
+ resp, err := service.DiffRuleVersion(cs,
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name:
c.Param("ruleName")}, id, c.Query("against"))
+ writeVersioningResp(c, resp, err)
+ }
+}
+
+func RollbackRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind)
gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !ensureVersioningEnabled(c, cs) {
+ return
+ }
+ id, ok := parseVersionID(c)
+ if !ok {
+ return
+ }
+ req := rollbackReq{}
+ if err := c.ShouldBindJSON(&req); err != nil {
+ c.JSON(http.StatusOK,
model.NewBizErrorResp(bizerror.New(bizerror.InvalidArgument, err.Error())))
Review Comment:
`ShouldBindJSON` failures are returned with HTTP 200 here, while
`writeVersioningResp` maps `InvalidArgument` to HTTP 400 (and there’s a test
asserting that behavior). For consistency and better client semantics, consider
using `writeVersioningResp` (or `http.StatusBadRequest`) for JSON
binding/validation errors instead of `StatusOK`.
##########
ui-vue3/src/views/traffic/tagRule/tabs/updateByYAMLView.vue:
##########
@@ -138,14 +147,25 @@ const updateTagRule = async () => {
loading.value = true
try {
const data = yaml.load(YAMLValue.value)
- const res = await updateTagRuleAPI(<string>route.params?.ruleName, data)
+ const res = await updateTagRuleAPI(route.params?.ruleName as string, data,
{
+ expectedVersionId: currentVersionId.value
+ })
if (res.code === HTTP_STATUS.SUCCESS) {
message.success('update success')
// 延迟 2 秒后再获取数据,确保数据库已更新
await new Promise((resolve) => setTimeout(resolve, 2000))
TAB_STATE.tagRule = null
await getTagRuleDetail()
+ await reloadCurrentVersion()
}
+ } catch (e: any) {
+ notifyRuleVersionError(e, {
+ reload: async () => {
+ TAB_STATE.tagRule = null
+ await getTagRuleDetail()
+ await reloadCurrentVersion()
+ }
+ })
} finally {
Review Comment:
The `catch` block only calls `notifyRuleVersionError(...)` and then swallows
the exception. If the failure is not a VERSION_CONFLICT /
VERSION_LEDGER_PENDING (e.g. YAML parse errors, `yaml.load` returning
null/undefined, or other runtime errors), the user may get no actionable
feedback and the error won’t propagate to existing error handling. Consider
checking the boolean return value and rethrowing or showing a generic
`message.error` when the error wasn’t handled as a versioning error.
--
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]