Skip to content

Commit

Permalink
use zookeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
day253 committed Oct 26, 2024
1 parent 4f2422e commit 09b6733
Show file tree
Hide file tree
Showing 30 changed files with 62 additions and 62 deletions.
6 changes: 3 additions & 3 deletions boilerplate/cmd/press/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ishumei/krpc/kserver"
"github.com/ishumei/krpc/objects"
"github.com/ishumei/krpc/protocols/arbiter/kitex_gen/com/shumei/service"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"go.uber.org/ratelimit"
)

Expand Down Expand Up @@ -44,11 +44,11 @@ func main() {
}
return []string{}
}(),
Resolver: func() registry_zookeeper.Conf {
Resolver: func() zookeeper.Conf {
if err == nil {
return c.Registry
}
return registry_zookeeper.Conf{
return zookeeper.Conf{
Metabase: *metabase,
TimeoutMs: 10000,
}
Expand Down
4 changes: 2 additions & 2 deletions boilerplate/pkg/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package conf
import (
"github.com/creasty/defaults"
"github.com/ishumei/krpc/conf"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/samber/do"
)

Expand All @@ -29,7 +29,7 @@ type Strategy struct {

type Config struct {
Debug bool
Registry registry_zookeeper.Conf
Registry zookeeper.Conf
Model Model
Strategy Strategy
}
Expand Down
6 changes: 3 additions & 3 deletions boilerplate/pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ishumei/krpc/objects"
"github.com/ishumei/krpc/protocols/arbiter/kitex_gen/com/shumei/service"
"github.com/ishumei/krpc/protocols/arbiter/kitex_gen/com/shumei/service/predictor"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/jncornett/doublebuf"
"github.com/samber/do"
"github.com/samber/lo"
Expand Down Expand Up @@ -107,11 +107,11 @@ func (s *mirrorClients) Predict(ctx context.Context, request *service.PredictReq
}

func MustNew() *mirrorClients {
zkConn := do.MustInvoke[*registry_zookeeper.ZookeeperRegistry](kserver.Injector)
zkConn := do.MustInvoke[*zookeeper.ZookeeperRegistry](kserver.Injector)
sConf := do.MustInvoke[*kserver.FrameConfig](kserver.Injector)
childNodes, _, err := zkConn.Children(sConf.ServiceName)
lo.Must0(err)
localIp, err := registry_zookeeper.GetLocalIp("")
localIp, err := zookeeper.GetLocalIp("")
lo.Must0(err)
localIpPort := fmt.Sprintf("%s:%d", localIp, sConf.Port)
klog.Info("selfIpPort: ", localIpPort)
Expand Down
4 changes: 2 additions & 2 deletions boilerplate/pkg/strategies/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ishumei/krpc/boilerplate/pkg/models"
"github.com/ishumei/krpc/kserver"
"github.com/ishumei/krpc/objects"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/samber/do"
)

Expand All @@ -17,7 +17,7 @@ func Init() error {
if err != nil {
return err
}
zookeeperConn, err := do.Invoke[*registry_zookeeper.ZookeeperResolver](kserver.Injector)
zookeeperConn, err := do.Invoke[*zookeeper.ZookeeperResolver](kserver.Injector)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions kclient/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kclient

import (
"github.com/cloudwego/kitex/pkg/connpool"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/samber/do"
)

Expand Down Expand Up @@ -31,5 +31,5 @@ type ClientConf struct {

type ResolverConf struct {
Hostports []string
Resolver registry_zookeeper.Conf
Resolver zookeeper.Conf
}
8 changes: 4 additions & 4 deletions kclient/kclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cloudwego/kitex/pkg/discovery"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/ishumei/krpc/logging"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/kitex-contrib/obs-opentelemetry/provider"
"github.com/samber/do"
)
Expand Down Expand Up @@ -42,12 +42,12 @@ func MustNewKclient(c *SingleClientConf) *Kclient {
do.Override(Injector, func(i *do.Injector) (discovery.Resolver, error) {
logger, err := do.Invoke[*logging.Logger](logging.Injector)
if err == nil {
return registry_zookeeper.NewZookeeperResolverWithConf(
return zookeeper.NewZookeeperResolverWithConf(
c.ResolverConf.Resolver,
registry_zookeeper.WithLogger(logger),
zookeeper.WithLogger(logger),
)
} else {
return registry_zookeeper.NewZookeeperResolverWithConf(
return zookeeper.NewZookeeperResolverWithConf(
c.ResolverConf.Resolver,
)
}
Expand Down
8 changes: 4 additions & 4 deletions kclient/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/ishumei/krpc/conf"
"github.com/ishumei/krpc/logging"
"github.com/ishumei/krpc/objects"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/samber/do"
)

Expand All @@ -27,12 +27,12 @@ func InjectClientFromMultiClientConf(c *MultiClientConf) {
do.Override(Injector, func(i *do.Injector) (discovery.Resolver, error) {
logger, err := do.Invoke[*logging.Logger](logging.Injector)
if err == nil {
return registry_zookeeper.NewZookeeperResolverWithConf(
return zookeeper.NewZookeeperResolverWithConf(
c.ResolverConf.Resolver,
registry_zookeeper.WithLogger(logger),
zookeeper.WithLogger(logger),
)
} else {
return registry_zookeeper.NewZookeeperResolverWithConf(
return zookeeper.NewZookeeperResolverWithConf(
c.ResolverConf.Resolver,
)
}
Expand Down
6 changes: 3 additions & 3 deletions kserver/arbiter/arbiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/cloudwego/kitex/server"
"github.com/ishumei/krpc/kserver"
"github.com/ishumei/krpc/protocols/arbiter/kitex_gen/com/shumei/service"
arbiterpredictor "github.com/ishumei/krpc/protocols/arbiter/kitex_gen/com/shumei/service/predictor"
"github.com/ishumei/krpc/protocols/arbiter/kitex_gen/com/shumei/service/predictor"
"github.com/samber/do"
)

Expand All @@ -15,10 +15,10 @@ type ArbiterService struct {
func NewArbiterService(i *do.Injector) (*ArbiterService, error) {
opts := do.MustInvoke[*kserver.ServerOptions](kserver.Injector)

predictor := do.MustInvoke[service.Predictor](kserver.Injector)
p := do.MustInvoke[service.Predictor](kserver.Injector)

return &ArbiterService{
Kservice: kserver.MustNewKservice(i, arbiterpredictor.NewServer(predictor, server.WithSuite(opts))),
Kservice: kserver.MustNewKservice(i, predictor.NewServer(p, server.WithSuite(opts))),
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions kserver/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/creasty/defaults"
"github.com/ishumei/krpc/conf"
"github.com/ishumei/krpc/logging"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/samber/do"
)

Expand Down Expand Up @@ -67,7 +67,7 @@ type FrameConfig struct {
Addr string
Port int `default:"8888"`
ServiceName string `default:"server"`
Registry registry_zookeeper.Conf
Registry zookeeper.Conf
Http HttpConfig
OpenTelemetry OpenTelemetry
Sentinel Sentinel
Expand Down
2 changes: 1 addition & 1 deletion kserver/example/audio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ishumei/krpc/kserver"
"github.com/ishumei/krpc/kserver/audio"
re "github.com/ishumei/krpc/protocols/audio/kitex_gen/shumei/strategy/re"
"github.com/ishumei/krpc/protocols/audio/kitex_gen/shumei/strategy/re"
"github.com/samber/do"
)

Expand Down
2 changes: 1 addition & 1 deletion kserver/example/event/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ishumei/krpc/kserver"
"github.com/ishumei/krpc/kserver/event"
re "github.com/ishumei/krpc/protocols/event/kitex_gen/shumei/strategy/re"
"github.com/ishumei/krpc/protocols/event/kitex_gen/shumei/strategy/re"
"github.com/samber/do"
)

Expand Down
2 changes: 1 addition & 1 deletion kserver/example/image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ishumei/krpc/kserver"
"github.com/ishumei/krpc/kserver/image"
re "github.com/ishumei/krpc/protocols/image/kitex_gen/shumei/strategy/re"
"github.com/ishumei/krpc/protocols/image/kitex_gen/shumei/strategy/re"
"github.com/samber/do"
)

Expand Down
2 changes: 1 addition & 1 deletion kserver/example/text/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ishumei/krpc/kserver"
"github.com/ishumei/krpc/kserver/text"
re "github.com/ishumei/krpc/protocols/text/kitex_gen/shumei/strategy/re"
"github.com/ishumei/krpc/protocols/text/kitex_gen/shumei/strategy/re"
"github.com/samber/do"
)

Expand Down
4 changes: 2 additions & 2 deletions kserver/grace.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"syscall"

"github.com/cloudwego/kitex/pkg/klog"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/samber/do"
)

Expand All @@ -26,7 +26,7 @@ func DefaultDeregisterSignal() {
sig := DeregisterSignal()
defer signal.Stop(sig)
for range sig {
err := do.MustInvoke[*registry_zookeeper.ZookeeperRegistry](Injector).Deregister(nil)
err := do.MustInvoke[*zookeeper.ZookeeperRegistry](Injector).Deregister(nil)
klog.Info("deregister service", err)
}
<-sig
Expand Down
10 changes: 5 additions & 5 deletions kserver/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package kserver
import (
"github.com/cloudwego/kitex/pkg/registry"
"github.com/ishumei/krpc/logging"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/samber/do"
)

func init() {
do.Provide(Injector, func(i *do.Injector) (*registry_zookeeper.ZookeeperRegistry, error) {
do.Provide(Injector, func(i *do.Injector) (*zookeeper.ZookeeperRegistry, error) {
f := do.MustInvoke[*FrameConfig](Injector)
c := f.Registry
logger := do.MustInvoke[*logging.Logger](logging.Injector)
return registry_zookeeper.NewZookeeperRegistryWithConf(
return zookeeper.NewZookeeperRegistryWithConf(
c,
f.Addr,
registry_zookeeper.WithLogger(logger),
zookeeper.WithLogger(logger),
)
})
do.Provide(Injector, func(i *do.Injector) (registry.Registry, error) {
return do.Invoke[*registry_zookeeper.ZookeeperRegistry](Injector)
return do.Invoke[*zookeeper.ZookeeperRegistry](Injector)
})
}
10 changes: 5 additions & 5 deletions kserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package kserver
import (
"github.com/cloudwego/kitex/pkg/discovery"
"github.com/ishumei/krpc/logging"
registry_zookeeper "github.com/ishumei/krpc/registry-zookeeper"
"github.com/ishumei/krpc/zookeeper"
"github.com/samber/do"
)

func init() {
do.Provide(Injector, func(i *do.Injector) (*registry_zookeeper.ZookeeperResolver, error) {
do.Provide(Injector, func(i *do.Injector) (*zookeeper.ZookeeperResolver, error) {
c := do.MustInvoke[*FrameConfig](Injector).Registry
logger := do.MustInvoke[*logging.Logger](logging.Injector)
return registry_zookeeper.NewZookeeperResolverWithConf(
return zookeeper.NewZookeeperResolverWithConf(
c,
registry_zookeeper.WithLogger(logger),
zookeeper.WithLogger(logger),
)
})
do.Provide(Injector, func(i *do.Injector) (discovery.Resolver, error) {
return do.Invoke[*registry_zookeeper.ZookeeperResolver](Injector)
return do.Invoke[*zookeeper.ZookeeperResolver](Injector)
})
}
4 changes: 2 additions & 2 deletions kserver/server_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/alibaba/sentinel-golang/api"
"github.com/alibaba/sentinel-golang/core/system"
sentinel "github.com/alibaba/sentinel-golang/pkg/adapters/kitex"
"github.com/alibaba/sentinel-golang/pkg/adapters/kitex"
"github.com/cloudwego/kitex/pkg/registry"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/server"
Expand Down Expand Up @@ -54,7 +54,7 @@ func NewServerOptions(i *do.Injector) (*ServerOptions, error) {
if c.Sentinel.Enabled {
options = append(
options,
server.WithMiddleware(sentinel.SentinelServerMiddleware()),
server.WithMiddleware(kitex.SentinelServerMiddleware()),
)
lo.Must0(api.InitDefault())
_, err := system.LoadRules(c.Sentinel.ToSystemRules())
Expand Down
6 changes: 3 additions & 3 deletions logging/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import (
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func stdoutProvider(ctx context.Context) func() {
provider := sdktrace.NewTracerProvider()
provider := trace.NewTracerProvider()
otel.SetTracerProvider(provider)

exp, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err != nil {
panic(err)
}

bsp := sdktrace.NewBatchSpanProcessor(exp)
bsp := trace.NewBatchSpanProcessor(exp)
provider.RegisterSpanProcessor(bsp)

return func() {
Expand Down
2 changes: 1 addition & 1 deletion registry-zookeeper/conf.go → zookeeper/conf.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry_zookeeper
package zookeeper

const (
DefaultRegistrySeparater = ","
Expand Down
2 changes: 1 addition & 1 deletion registry-zookeeper/const.go → zookeeper/const.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry_zookeeper
package zookeeper

const (
Separator = "/"
Expand Down
2 changes: 1 addition & 1 deletion registry-zookeeper/entity.go → zookeeper/entity.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry_zookeeper
package zookeeper

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry_zookeeper
package zookeeper

import (
"reflect"
Expand Down
Loading

0 comments on commit 09b6733

Please sign in to comment.