Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/config/app/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/apache/dubbo-admin/pkg/config/diagnostics"
"github.com/apache/dubbo-admin/pkg/config/discovery"
"github.com/apache/dubbo-admin/pkg/config/engine"
"github.com/apache/dubbo-admin/pkg/config/eventbus"
"github.com/apache/dubbo-admin/pkg/config/log"
"github.com/apache/dubbo-admin/pkg/config/observability"
"github.com/apache/dubbo-admin/pkg/config/store"
Expand All @@ -48,22 +49,26 @@ type AdminConfig struct {
Discovery []*discovery.Config `json:"discovery" yaml:"discovery"`
// Engine configuration
Engine *engine.Config `json:"engine" yaml:"engine"`
// EventBus configuration
EventBus *eventbus.Config `json:"eventBus,omitempty" yaml:"eventBus,omitempty"`
}

var _ = &AdminConfig{}

var DefaultAdminConfig = func() AdminConfig {
eventBusCfg := eventbus.Default()
return AdminConfig{
Log: log.DefaultLogConfig(),
Store: store.DefaultStoreConfig(),
Engine: engine.DefaultResourceEngineConfig(),
Observability: observability.DefaultObservabilityConfig(),
Diagnostics: diagnostics.DefaultDiagnosticsConfig(),
Console: console.DefaultConsoleConfig(),
EventBus: &eventBusCfg,
}
}

func (c AdminConfig) Sanitize() {
func (c *AdminConfig) Sanitize() {
c.Engine.Sanitize()
for _, d := range c.Discovery {
d.Sanitize()
Expand All @@ -75,7 +80,7 @@ func (c AdminConfig) Sanitize() {
c.Log.Sanitize()
}

func (c AdminConfig) PreProcess() error {
func (c *AdminConfig) PreProcess() error {
discoveryPreProcess := func() error {
for _, d := range c.Discovery {
if err := d.PreProcess(); err != nil {
Expand All @@ -95,7 +100,7 @@ func (c AdminConfig) PreProcess() error {
)
}

func (c AdminConfig) PostProcess() error {
func (c *AdminConfig) PostProcess() error {
discoveryPostProcess := func() error {
for _, d := range c.Discovery {
if err := d.PostProcess(); err != nil {
Expand All @@ -115,7 +120,7 @@ func (c AdminConfig) PostProcess() error {
)
}

func (c AdminConfig) Validate() error {
func (c *AdminConfig) Validate() error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: 这里的receiver需要统一
Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这条:Validate() 保持指针接收者,FindDiscovery()/Meshes() 保持值接收者(否则会在 ctx.Config().FindDiscovery(...) 场景触发编译错误:cannot call pointer method on app.AdminConfig)这里就用会修改配置的方法用指针接收者、只读查询方法用值接收者的方式处理

if c.Log == nil {
c.Log = log.DefaultLogConfig()
} else if err := c.Log.Validate(); err != nil {
Expand Down Expand Up @@ -160,6 +165,12 @@ func (c AdminConfig) Validate() error {
} else if err := c.Engine.Validate(); err != nil {
return bizerror.Wrap(err, bizerror.ConfigError, "engine config validation failed")
}
if c.EventBus == nil {
cfg := eventbus.Default()
c.EventBus = &cfg
} else if err := c.EventBus.Validate(); err != nil {
return bizerror.Wrap(err, bizerror.ConfigError, "event bus config validation failed")
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/eventbus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func (c Config) Validate() error {

func Default() Config {
return Config{
BufferSize: 100,
BufferSize: 1024,
}
}
4 changes: 4 additions & 0 deletions pkg/console/counter/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ func (s *counterEventSubscriber) Name() string {
return s.name
}

func (s *counterEventSubscriber) AsyncEnabled() bool {
return false
}

func (s *counterEventSubscriber) ProcessEvent(event events.Event) error {
if s.handler == nil {
return nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/discovery/subscriber/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (s *InstanceEventSubscriber) Name() string {
return "Discovery-" + s.ResourceKind().ToString()
}

func (s *InstanceEventSubscriber) AsyncEnabled() bool {
return true
}

func (s *InstanceEventSubscriber) ProcessEvent(event events.Event) error {
newObj, ok := event.NewObj().(*meshresource.InstanceResource)
if !ok && event.NewObj() != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/discovery/subscriber/nacos_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (n *NacosServiceEventSubscriber) Name() string {
return "Nacos2Discovery-" + n.ResourceKind().ToString()
}

func (n *NacosServiceEventSubscriber) AsyncEnabled() bool {
return true
}

func (n *NacosServiceEventSubscriber) ProcessEvent(event events.Event) error {
newObj, ok := event.NewObj().(*meshresource.NacosServiceResource)
if !ok && event.NewObj() != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/discovery/subscriber/rpc_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (s *RPCInstanceEventSubscriber) ResourceKind() coremodel.ResourceKind {
return meshresource.RPCInstanceKind
}

func (s *RPCInstanceEventSubscriber) AsyncEnabled() bool {
return true
}

func (s *RPCInstanceEventSubscriber) ProcessEvent(event events.Event) error {
newObj, ok := event.NewObj().(*meshresource.RPCInstanceResource)
if !ok && event.NewObj() != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/discovery/subscriber/service_consumer_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (s *ServiceConsumerMetadataEventSubscriber) Name() string {
return "Discovery-" + s.ResourceKind().ToString()
}

func (s *ServiceConsumerMetadataEventSubscriber) AsyncEnabled() bool {
return true
}

func (s *ServiceConsumerMetadataEventSubscriber) ProcessEvent(event events.Event) error {
newObj, ok := event.NewObj().(*meshresource.ServiceConsumerMetadataResource)
if !ok && event.NewObj() != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/discovery/subscriber/service_provider_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (s *ServiceProviderMetadataEventSubscriber) Name() string {
return "Discovery-" + s.ResourceKind().ToString()
}

func (s *ServiceProviderMetadataEventSubscriber) AsyncEnabled() bool {
return true
}

func (s *ServiceProviderMetadataEventSubscriber) ProcessEvent(event events.Event) error {
newObj, ok := event.NewObj().(*meshresource.ServiceProviderMetadataResource)
if !ok && event.NewObj() != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/discovery/subscriber/zk_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (z *ZKConfigEventSubscriber) Name() string {
return "Discovery-" + z.ResourceKind().ToString()
}

func (z *ZKConfigEventSubscriber) AsyncEnabled() bool {
return true
}

func (z *ZKConfigEventSubscriber) ProcessEvent(event events.Event) error {
newObj, ok := event.NewObj().(*meshresource.ZKConfigResource)
if !ok && event.NewObj() != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/discovery/subscriber/zk_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (z *ZKMetadataEventSubscriber) Name() string {
return "Discovery-" + z.ResourceKind().ToString()
}

func (z *ZKMetadataEventSubscriber) AsyncEnabled() bool {
return true
}

func (z *ZKMetadataEventSubscriber) ProcessEvent(event events.Event) error {
newObj, ok := event.NewObj().(*meshresource.ZKMetadataResource)
if !ok && event.NewObj() != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/engine/subscriber/runtime_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (s *RuntimeInstanceEventSubscriber) Name() string {
return "Engine-" + s.ResourceKind().ToString()
}

func (s *RuntimeInstanceEventSubscriber) AsyncEnabled() bool {
return true
}

func (s *RuntimeInstanceEventSubscriber) ProcessEvent(event events.Event) error {
newObj, ok := event.NewObj().(*meshresource.RuntimeInstanceResource)
if !ok && event.NewObj() != nil {
Expand Down
29 changes: 29 additions & 0 deletions pkg/core/events/async.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 events

import "sync/atomic"

type subscriberState struct {
subscriber Subscriber
async bool
ch chan Event
done chan struct{}
closed atomic.Bool
drainerStarted atomic.Bool
}
Loading
Loading