Skip to content

Commit 9b5c436

Browse files
committed
fix(service): align service queries and pre-commit checks
1 parent 1c882af commit 9b5c436

67 files changed

Lines changed: 480 additions & 396 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/mesh/v1alpha1/dynamic_config_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
func GetOverridePath(key string) string {
27-
key = strings.Replace(key, "/", "*", -1)
27+
key = strings.ReplaceAll(key, "/", "*")
2828
return key + constants.ConfiguratorRuleDotSuffix
2929
}
3030

pkg/common/util/proto/any.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package proto
2020
import (
2121
"strings"
2222

23-
protov1 "github.com/golang/protobuf/proto"
2423
"github.com/pkg/errors"
2524
"google.golang.org/protobuf/proto"
2625
"google.golang.org/protobuf/reflect/protoreflect"
@@ -39,7 +38,7 @@ func MarshalAnyDeterministic(pb proto.Message) (*anypb.Any, error) {
3938
if err != nil {
4039
return nil, err
4140
}
42-
name := string(protov1.MessageV2(pb).ProtoReflect().Descriptor().FullName())
41+
name := string(pb.ProtoReflect().Descriptor().FullName())
4342
return &anypb.Any{TypeUrl: googleApis + name, Value: bytes}, nil
4443
}
4544

pkg/common/util/proto/proto.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"bytes"
2222
"fmt"
2323

24-
"github.com/golang/protobuf/jsonpb"
25-
protov1 "github.com/golang/protobuf/proto"
24+
jsonpb "github.com/golang/protobuf/jsonpb" //nolint:staticcheck // preserve legacy JSON mapping behavior expected by existing configs
25+
protov1 "github.com/golang/protobuf/proto" //nolint:staticcheck // jsonpb still operates on v1 messages
2626
"google.golang.org/protobuf/proto"
2727
"google.golang.org/protobuf/types/known/structpb"
2828
"sigs.k8s.io/yaml"

pkg/config/app/admin.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,32 +116,32 @@ func (c AdminConfig) PostProcess() error {
116116
}
117117

118118
func (c AdminConfig) Validate() error {
119-
if c.Log == nil {
120-
c.Log = log.DefaultLogConfig()
121-
} else if err := c.Log.Validate(); err != nil {
122-
return bizerror.Wrap(err, bizerror.ConfigError, "log config validation failed")
119+
if c.Log != nil {
120+
if err := c.Log.Validate(); err != nil {
121+
return bizerror.Wrap(err, bizerror.ConfigError, "log config validation failed")
122+
}
123123
}
124-
if c.Store == nil {
125-
c.Store = store.DefaultStoreConfig()
126-
} else if err := c.Store.Validate(); err != nil {
127-
return bizerror.Wrap(err, bizerror.ConfigError, "store config validation failed")
124+
if c.Store != nil {
125+
if err := c.Store.Validate(); err != nil {
126+
return bizerror.Wrap(err, bizerror.ConfigError, "store config validation failed")
127+
}
128128
}
129-
if c.Diagnostics == nil {
130-
c.Diagnostics = diagnostics.DefaultDiagnosticsConfig()
131-
} else if err := c.Diagnostics.Validate(); err != nil {
132-
return bizerror.Wrap(err, bizerror.ConfigError, "diagnostics config validation failed")
129+
if c.Diagnostics != nil {
130+
if err := c.Diagnostics.Validate(); err != nil {
131+
return bizerror.Wrap(err, bizerror.ConfigError, "diagnostics config validation failed")
132+
}
133133
}
134-
if c.Console == nil {
135-
c.Console = console.DefaultConsoleConfig()
136-
} else if err := c.Console.Validate(); err != nil {
137-
return bizerror.Wrap(err, bizerror.ConfigError, "console config validation failed")
134+
if c.Console != nil {
135+
if err := c.Console.Validate(); err != nil {
136+
return bizerror.Wrap(err, bizerror.ConfigError, "console config validation failed")
137+
}
138138
}
139-
if c.Observability == nil {
140-
c.Observability = observability.DefaultObservabilityConfig()
141-
} else if err := c.Observability.Validate(); err != nil {
142-
return bizerror.Wrap(err, bizerror.ConfigError, "observability config validation failed")
139+
if c.Observability != nil {
140+
if err := c.Observability.Validate(); err != nil {
141+
return bizerror.Wrap(err, bizerror.ConfigError, "observability config validation failed")
142+
}
143143
}
144-
if c.Discovery == nil || len(c.Discovery) == 0 {
144+
if len(c.Discovery) == 0 {
145145
return bizerror.New(bizerror.ConfigError, "discover config is needed")
146146
}
147147
for _, d := range c.Discovery {
@@ -155,10 +155,10 @@ func (c AdminConfig) Validate() error {
155155
if len(discoveryIDList) != len(slice.Unique(discoveryIDList)) {
156156
return bizerror.New(bizerror.ConfigError, "discovery id must be unique")
157157
}
158-
if c.Engine == nil {
159-
c.Engine = engine.DefaultResourceEngineConfig()
160-
} else if err := c.Engine.Validate(); err != nil {
161-
return bizerror.Wrap(err, bizerror.ConfigError, "engine config validation failed")
158+
if c.Engine != nil {
159+
if err := c.Engine.Validate(); err != nil {
160+
return bizerror.Wrap(err, bizerror.ConfigError, "engine config validation failed")
161+
}
162162
}
163163
return nil
164164
}

pkg/console/counter/component.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ func (c *managerComponent) initializeCountsFromStore(storeRouter store.Router) e
101101
return fmt.Errorf("failed to initialize application count: %w", err)
102102
}
103103

104-
if err := c.initializeResourceCount(storeRouter, meshresource.ServiceProviderMetadataKind); err != nil {
105-
return fmt.Errorf("failed to initialize service provider metadata count: %w", err)
104+
if err := c.initializeResourceCount(storeRouter, meshresource.ServiceKind); err != nil {
105+
return fmt.Errorf("failed to initialize service count: %w", err)
106106
}
107107

108108
return nil

pkg/console/counter/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func newCounterManager() *counterManager {
7373
}
7474

7575
cm.RegisterSimpleCounter(meshresource.ApplicationKind)
76-
cm.RegisterSimpleCounter(meshresource.ServiceProviderMetadataKind)
76+
cm.RegisterSimpleCounter(meshresource.ServiceKind)
7777
cm.RegisterSimpleCounter(meshresource.InstanceKind)
7878

7979
cm.RegisterDistributionCounter(meshresource.InstanceKind, ProtocolCounter, instanceProtocolKey)

pkg/console/handler/configurator_rule.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func GetConfiguratorWithRuleName(ctx consolectx.Context) gin.HandlerFunc {
7676
if res == nil {
7777
c.JSON(http.StatusOK, model.NewBizErrorResp(
7878
bizerror.New(bizerror.NotFoundError, fmt.Sprintf("%s not found", ruleName))))
79+
return
7980
}
8081
c.JSON(http.StatusOK, model.GenDynamicConfigToResp(res.Spec))
8182
}

pkg/console/handler/observability.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ func GetPrometheus(ctx consolectx.Context) gin.HandlerFunc {
102102
}
103103
resp := ctx.Config().Observability.PrometheusBaseURL.String()
104104
c.JSON(http.StatusOK, model.NewSuccessResp(resp))
105-
return
106105
}
107106
}
108107

pkg/console/handler/overview.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ func ClusterOverview(ctx consolectx.Context) gin.HandlerFunc {
7474

7575
if mesh != "" {
7676
resp.AppCount = counterMgr.CountByMesh(meshresource.ApplicationKind, mesh)
77-
resp.ServiceCount = counterMgr.CountByMesh(meshresource.ServiceProviderMetadataKind, mesh)
77+
resp.ServiceCount = counterMgr.CountByMesh(meshresource.ServiceKind, mesh)
7878
resp.InsCount = counterMgr.CountByMesh(meshresource.InstanceKind, mesh)
7979
resp.Protocols = counterMgr.DistributionByMesh(counter.ProtocolCounter, mesh)
8080
resp.Releases = counterMgr.DistributionByMesh(counter.ReleaseCounter, mesh)
8181
resp.Discoveries = counterMgr.DistributionByMesh(counter.DiscoveryCounter, mesh)
8282
} else {
8383
resp.AppCount = counterMgr.Count(meshresource.ApplicationKind)
84-
resp.ServiceCount = counterMgr.Count(meshresource.ServiceProviderMetadataKind)
84+
resp.ServiceCount = counterMgr.Count(meshresource.ServiceKind)
8585
resp.InsCount = counterMgr.Count(meshresource.InstanceKind)
8686
resp.Protocols = counterMgr.Distribution(counter.ProtocolCounter)
8787
resp.Releases = counterMgr.Distribution(counter.ReleaseCounter)

pkg/console/handler/prometheus.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ func PromQL(ctx consolectx.Context) gin.HandlerFunc {
4747
bizerror.New(bizerror.NetWorkError, err.Error())))
4848
return
4949
}
50-
defer resp.Body.Close()
50+
defer func() {
51+
_ = resp.Body.Close()
52+
}()
5153

5254
body, err := io.ReadAll(resp.Body)
5355
if err != nil {

0 commit comments

Comments
 (0)