@@ -22,6 +22,7 @@ import (
2222 "math"
2323
2424 "github.com/apache/dubbo-admin/pkg/core/events"
25+ "github.com/apache/dubbo-admin/pkg/core/logger"
2526 meshresource "github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
2627 resmodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
2728 "github.com/apache/dubbo-admin/pkg/core/runtime"
@@ -76,7 +77,9 @@ func (c *managerComponent) Start(rt runtime.Runtime, _ <-chan struct{}) error {
7677 return fmt .Errorf ("component %s does not implement store.Router" , runtime .ResourceStore )
7778 }
7879
79- c .initializeCountsFromStore (storeRouter )
80+ if err := c .initializeCountsFromStore (storeRouter ); err != nil {
81+ logger .Warnf ("Failed to initialize counter manager from store: %v" , err )
82+ }
8083
8184 component , err := rt .GetComponent (runtime .EventBus )
8285 if err != nil {
@@ -112,9 +115,7 @@ func (c *managerComponent) initializeResourceCount(storeRouter store.Router, kin
112115 }
113116
114117 allResources := resourceStore .List ()
115-
116- meshCounts := make (map [string ]int64 )
117- meshDistributions := make (map [string ]map [string ]int64 )
118+ cm := c .manager .(* counterManager )
118119
119120 for _ , obj := range allResources {
120121 resource , ok := obj .(resmodel.Resource )
@@ -127,66 +128,29 @@ func (c *managerComponent) initializeResourceCount(storeRouter store.Router, kin
127128 mesh = "default"
128129 }
129130
130- meshCounts [mesh ]++
131+ if counter , exists := cm .simpleCounters [kind ]; exists {
132+ counter .Increment (mesh )
133+ }
131134
132135 if kind == meshresource .InstanceKind {
133136 instance , ok := resource .(* meshresource.InstanceResource )
134137 if ok && instance .Spec != nil {
135138 protocol := instance .Spec .GetProtocol ()
136139 if protocol != "" {
137- if meshDistributions [ mesh ] = = nil {
138- meshDistributions [ mesh ] = make ( map [ string ] int64 )
140+ if cfg := cm . getDistributionConfig ( kind , ProtocolCounter ); cfg ! = nil {
141+ cfg . counter . Increment ( mesh , protocol )
139142 }
140- meshDistributions [mesh ]["protocol:" + protocol ]++
141143 }
142144
143145 releaseVersion := instance .Spec .GetReleaseVersion ()
144146 if releaseVersion != "" {
145- if meshDistributions [ mesh ] = = nil {
146- meshDistributions [ mesh ] = make ( map [ string ] int64 )
147+ if cfg := cm . getDistributionConfig ( kind , ReleaseCounter ); cfg ! = nil {
148+ cfg . counter . Increment ( mesh , releaseVersion )
147149 }
148- meshDistributions [mesh ]["release:" + releaseVersion ]++
149150 }
150151
151- if meshDistributions [mesh ] == nil {
152- meshDistributions [mesh ] = make (map [string ]int64 )
153- }
154- meshDistributions [mesh ]["discovery:" + mesh ]++
155- }
156- }
157- }
158-
159- cm := c .manager .(* counterManager )
160-
161- if counter , exists := cm .simpleCounters [kind ]; exists {
162- for mesh , count := range meshCounts {
163- for i := int64 (0 ); i < count ; i ++ {
164- counter .Increment (mesh )
165- }
166- }
167- }
168-
169- if kind == meshresource .InstanceKind {
170- for mesh , distributions := range meshDistributions {
171- for key , count := range distributions {
172- if len (key ) > 9 && key [:9 ] == "protocol:" {
173- if cfg := cm .getDistributionConfig (kind , ProtocolCounter ); cfg != nil {
174- for i := int64 (0 ); i < count ; i ++ {
175- cfg .counter .Increment (mesh , key [9 :])
176- }
177- }
178- } else if len (key ) > 8 && key [:8 ] == "release:" {
179- if cfg := cm .getDistributionConfig (kind , ReleaseCounter ); cfg != nil {
180- for i := int64 (0 ); i < count ; i ++ {
181- cfg .counter .Increment (mesh , key [8 :])
182- }
183- }
184- } else if len (key ) > 11 && key [:11 ] == "discovery:" {
185- if cfg := cm .getDistributionConfig (kind , DiscoveryCounter ); cfg != nil {
186- for i := int64 (0 ); i < count ; i ++ {
187- cfg .counter .Increment (mesh , key [11 :])
188- }
189- }
152+ if cfg := cm .getDistributionConfig (kind , DiscoveryCounter ); cfg != nil {
153+ cfg .counter .Increment (mesh , mesh )
190154 }
191155 }
192156 }
@@ -198,3 +162,4 @@ func (c *managerComponent) initializeResourceCount(storeRouter store.Router, kin
198162func (c * managerComponent ) CounterManager () CounterManager {
199163 return c .manager
200164}
165+
0 commit comments