Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't compile the actuator module if users don't need it #388

Merged
merged 49 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d8cf081
move proto related code to a different package
seeflood Dec 23, 2021
c5d29d8
extract common code to convert state options
seeflood Dec 27, 2021
3f06deb
Revert "extract common code to convert state options"
seeflood Dec 27, 2021
eeeda33
Dapr SaveState API
seeflood Dec 27, 2021
bd8e69a
nil check
seeflood Dec 27, 2021
22e1766
nil check
seeflood Dec 27, 2021
70e81b0
add tests
seeflood Dec 27, 2021
3081157
add tests
seeflood Dec 27, 2021
e78c926
add tests
seeflood Dec 27, 2021
d6d3c03
add tests
seeflood Dec 27, 2021
c79496a
add tests
seeflood Dec 27, 2021
e675399
add tests
seeflood Dec 27, 2021
d3af1f4
Merge branch 'main' into move_code
seeflood Jan 7, 2022
0c1d985
modify comments
seeflood Jan 14, 2022
ae894c6
fix ut
seeflood Jan 14, 2022
f19a5a2
add test case
seeflood Jan 14, 2022
e474fe2
add comments
seeflood Jan 19, 2022
95154e7
return without name in hello component
seeflood Jan 19, 2022
d88e873
move mock file to a different package
seeflood Jan 19, 2022
4f03f67
remove trace in hello component
seeflood Jan 19, 2022
51486df
upgrade component and spec package
seeflood Jan 24, 2022
5fd2419
modify serviceName
seeflood Jan 25, 2022
ecc164c
fix ut
seeflood Jan 26, 2022
9436fd5
move ut to different files
seeflood Jan 26, 2022
6719f90
modify const in tracing.go
seeflood Jan 30, 2022
1c0757b
add ut
seeflood Jan 31, 2022
a23b07f
doc: Fix wrong link (#378)
seeflood Jan 11, 2022
7eb35e5
feature: support dapr state api (#377)
seeflood Feb 10, 2022
f014696
feature: support dapr state api (#377)
zach030 Jan 13, 2022
db597e5
feat: add sequencer of mongo (#376)
LXPWing Jan 21, 2022
6957cd4
add metric config for layotto (#380)
wenxuwan Jan 26, 2022
80c5716
doc: improve metrics doc (#382)
seeflood Feb 1, 2022
d2f2915
feat: ADD SECRET API (#343)
MentosL Feb 10, 2022
0237f66
fix ut
seeflood Feb 10, 2022
e669153
Merge remote-tracking branch 'upstream/main' into merge_main_into_mov…
seeflood Feb 10, 2022
265aa50
revert trace.md
seeflood Feb 10, 2022
3a0d4e4
fix import
seeflood Feb 10, 2022
a6e3219
fix format issues in trace.md
seeflood Feb 10, 2022
80288c4
modify file names
seeflood Feb 10, 2022
f7c3eaf
split api.go into different files
seeflood Feb 11, 2022
e0f6077
Merge branch 'main' into test_move_code
seeflood Feb 14, 2022
aaf1b16
modify license headers
seeflood Feb 16, 2022
d201ee2
Merge remote-tracking branch 'origin/test_move_code' into test_move_code
seeflood Feb 16, 2022
a70feb5
add a `Range` function for components' actuator
seeflood Feb 16, 2022
fd4058a
DI for actuators
seeflood Feb 16, 2022
17c78e0
Merge remote-tracking branch 'upstream/main' into make_actuator_confi…
seeflood Feb 16, 2022
4fcffd1
add license
seeflood Feb 16, 2022
a332697
fix cr issues
seeflood Feb 17, 2022
642541a
add log
seeflood Feb 17, 2022
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
47 changes: 38 additions & 9 deletions cmd/layotto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"encoding/json"
"fmt"
"github.com/dapr/components-contrib/secretstores"
"github.com/dapr/components-contrib/secretstores/aws/parameterstore"
"github.com/dapr/components-contrib/secretstores/aws/secretmanager"
Expand All @@ -29,6 +28,7 @@ import (
secretstore_env "github.com/dapr/components-contrib/secretstores/local/env"
secretstore_file "github.com/dapr/components-contrib/secretstores/local/file"
"mosn.io/api"
component_actuators "mosn.io/layotto/components/pkg/actuators"
"mosn.io/layotto/diagnostics"
"mosn.io/layotto/pkg/grpc/default_api"
secretstores_loader "mosn.io/layotto/pkg/runtime/secretstores"
Expand Down Expand Up @@ -129,6 +129,7 @@ import (
"github.com/urfave/cli"
"google.golang.org/grpc"
_ "mosn.io/layotto/pkg/filter/network/tcpcopy"
l8_grpc "mosn.io/layotto/pkg/grpc"
"mosn.io/layotto/pkg/runtime"
_ "mosn.io/layotto/pkg/wasm"
"mosn.io/mosn/pkg/featuregate"
Expand Down Expand Up @@ -167,17 +168,35 @@ func init() {
}

func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrpc.RegisteredServer, error) {
var err error
defer func() {
if err != nil {
// fail fast if error occurs during startup.
// The reason we panic in a new goroutine is to prevent mosn from recovering.
go func() {
log.DefaultLogger.Errorf("An error occurred during startup : %v", err)
panic(err)
}()
}
}()
// 1. parse config
cfg, err := runtime.ParseRuntimeConfig(data)
if err != nil {
actuator.GetRuntimeReadinessIndicator().SetUnhealthy(fmt.Sprintf("parse config error.%v", err))
return nil, err
}
// 2. new instance
rt := runtime.NewMosnRuntime(cfg)
// 3. run
server, err := rt.Run(
runtime.WithGrpcOptions(opts...),
// wrap the grpc server with actuator
runtime.WithNewServer(func(apis []l8_grpc.GrpcAPI, opts ...grpc.ServerOption) (mgrpc.RegisteredServer, error) {
server, err := l8_grpc.NewDefaultServer(apis, opts...)
if err != nil {
return nil, err
}
return actuator.NewGrpcServerWithActuator(server)
}),
// register your grpc API here
runtime.WithGrpcAPI(
default_api.NewGrpcAPI,
Expand Down Expand Up @@ -376,11 +395,6 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
return secretstore_env.NewEnvSecretStore(loggerForDaprComp)
}),
))
// 4. check if unhealthy
if err != nil {
actuator.GetRuntimeReadinessIndicator().SetUnhealthy(err.Error())
actuator.GetRuntimeLivenessIndicator().SetUnhealthy(err.Error())
}
return server, err
}

Expand Down Expand Up @@ -417,16 +431,31 @@ var cmdStart = cli.Command{

stm.AppendStartStage(mosn.DefaultStartStage)

stm.AppendAfterStartStage(SetActuatorAfterStart)

stm.Run()

actuator.GetRuntimeReadinessIndicator().SetStarted()
actuator.GetRuntimeLivenessIndicator().SetStarted()
// wait mosn finished
stm.WaitFinish()
return nil
},
}

func SetActuatorAfterStart(m *mosn.Mosn) {
// register component actuator
component_actuators.RangeAllIndicators(
func(name string, v *component_actuators.ComponentsIndicator) bool {
if v != nil {
health.AddLivenessIndicator(name, v.LivenessIndicator)
health.AddReadinessIndicator(name, v.ReadinessIndicator)
}
return true
})
// set started
actuator.GetRuntimeReadinessIndicator().SetStarted()
actuator.GetRuntimeLivenessIndicator().SetStarted()
}

// ExtensionsRegister for register mosn rpc extensions
func ExtensionsRegister(c *cli.Context) {
// 1. tracer driver register
Expand Down
45 changes: 38 additions & 7 deletions cmd/layotto_multiple_api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package main

import (
"encoding/json"
"fmt"
"mosn.io/api"
helloworld_api "mosn.io/layotto/cmd/layotto_multiple_api/helloworld"
component_actuators "mosn.io/layotto/components/pkg/actuators"
l8_grpc "mosn.io/layotto/pkg/grpc"
"mosn.io/layotto/pkg/grpc/dapr"
"mosn.io/layotto/pkg/grpc/default_api"
"os"
Expand Down Expand Up @@ -157,17 +158,35 @@ func init() {
}

func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrpc.RegisteredServer, error) {
var err error
defer func() {
if err != nil {
// fail fast if error occurs during startup.
// The reason we panic in a new goroutine is to prevent mosn from recovering.
go func() {
log.DefaultLogger.Errorf("An error occurred during startup : %v", err)
panic(err)
}()
}
}()
// 1. parse config
cfg, err := runtime.ParseRuntimeConfig(data)
if err != nil {
actuator.GetRuntimeReadinessIndicator().SetUnhealthy(fmt.Sprintf("parse config error.%v", err))
return nil, err
}
// 2. new instance
rt := runtime.NewMosnRuntime(cfg)
// 3. run
server, err := rt.Run(
runtime.WithGrpcOptions(opts...),
// wrap the grpc server with actuator
runtime.WithNewServer(func(apis []l8_grpc.GrpcAPI, opts ...grpc.ServerOption) (mgrpc.RegisteredServer, error) {
server, err := l8_grpc.NewDefaultServer(apis, opts...)
if err != nil {
return nil, err
}
return actuator.NewGrpcServerWithActuator(server)
}),
// register your grpc API here
runtime.WithGrpcAPI(
// default grpc API
Expand Down Expand Up @@ -340,11 +359,6 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
return sequencer_zookeeper.NewZookeeperSequencer(log.DefaultLogger)
}),
))
// 4. check if unhealthy
if err != nil {
actuator.GetRuntimeReadinessIndicator().SetUnhealthy(err.Error())
actuator.GetRuntimeLivenessIndicator().SetUnhealthy(err.Error())
}
return server, err
}

Expand Down Expand Up @@ -380,6 +394,8 @@ var cmdStart = cli.Command{

stm.AppendStartStage(mosn.DefaultStartStage)

stm.AppendAfterStartStage(SetActuatorAfterStart)

stm.Run()

actuator.GetRuntimeReadinessIndicator().SetStarted()
Expand All @@ -390,6 +406,21 @@ var cmdStart = cli.Command{
},
}

func SetActuatorAfterStart(m *mosn.Mosn) {
// register component actuator
component_actuators.RangeAllIndicators(
func(name string, v *component_actuators.ComponentsIndicator) bool {
if v != nil {
health.AddLivenessIndicator(name, v.LivenessIndicator)
health.AddReadinessIndicator(name, v.ReadinessIndicator)
}
return true
})
// set started
actuator.GetRuntimeReadinessIndicator().SetStarted()
actuator.GetRuntimeLivenessIndicator().SetStarted()
}

// ExtensionsRegister for register mosn rpc extensions
func ExtensionsRegister(c *cli.Context) {
// 1. tracer driver register
Expand Down
2 changes: 1 addition & 1 deletion components/configstores/apollo/indicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
readinessIndicator = newHealthIndicator()
livenessIndicator = newHealthIndicator()
indicators := &actuators.ComponentsIndicator{ReadinessIndicator: readinessIndicator, LivenessIndicator: livenessIndicator}
actuators.SetComponentsActuators("apollo", indicators)
actuators.SetComponentsIndicator("apollo", indicators)
}

func newHealthIndicator() *healthIndicator {
Expand Down
1 change: 1 addition & 0 deletions components/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
Expand Down
8 changes: 7 additions & 1 deletion components/pkg/actuators/actutors.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func GetIndicatorWithName(name string) *ComponentsIndicator {
return nil
}

func SetComponentsActuators(name string, indicator *ComponentsIndicator) {
func SetComponentsIndicator(name string, indicator *ComponentsIndicator) {
componentsActutors.Store(name, indicator)
}

func RangeAllIndicators(f func(key string, value *ComponentsIndicator) bool) {
componentsActutors.Range(func(k, v interface{}) bool {
seeflood marked this conversation as resolved.
Show resolved Hide resolved
return f(k.(string), v.(*ComponentsIndicator))
})
}
52 changes: 52 additions & 0 deletions pkg/integrate/actuator/grpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2021 Layotto Authors
*
* Licensed 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 actuator

import (
mgrpc "mosn.io/mosn/pkg/filter/network/grpc"
"net"
)

type GrpcServerWithActuator struct {
srv mgrpc.RegisteredServer
}

func (s *GrpcServerWithActuator) Serve(ln net.Listener) (err error) {
err = s.srv.Serve(ln)
if err != nil {
GetRuntimeReadinessIndicator().SetUnhealthy(err.Error())
GetRuntimeLivenessIndicator().SetUnhealthy(err.Error())
}
return
}
func (s *GrpcServerWithActuator) Stop() {
GetRuntimeReadinessIndicator().SetUnhealthy("shutdown")
GetRuntimeLivenessIndicator().SetUnhealthy("shutdown")
s.srv.Stop()
}

func (s *GrpcServerWithActuator) GracefulStop() {
GetRuntimeReadinessIndicator().SetUnhealthy("shutdown")
GetRuntimeLivenessIndicator().SetUnhealthy("shutdown")
s.srv.GracefulStop()
}

func NewGrpcServerWithActuator(srv mgrpc.RegisteredServer) (mgrpc.RegisteredServer, error) {
return &GrpcServerWithActuator{
srv: srv,
}, nil
}
17 changes: 0 additions & 17 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ import (
"mosn.io/layotto/components/configstores"
"mosn.io/layotto/components/hello"
"mosn.io/layotto/components/lock"
"mosn.io/layotto/components/pkg/actuators"
"mosn.io/layotto/components/pkg/info"
"mosn.io/layotto/components/rpc"
"mosn.io/layotto/components/sequencer"
"mosn.io/layotto/pkg/actuator/health"
"mosn.io/layotto/pkg/grpc"
"mosn.io/layotto/pkg/integrate/actuator"
runtime_lock "mosn.io/layotto/pkg/runtime/lock"
runtime_pubsub "mosn.io/layotto/pkg/runtime/pubsub"
runtime_sequencer "mosn.io/layotto/pkg/runtime/sequencer"
Expand Down Expand Up @@ -200,8 +197,6 @@ func (m *MosnRuntime) Stop() {
if m.srv != nil {
m.srv.Stop()
}
actuator.GetRuntimeReadinessIndicator().SetUnhealthy("shutdown")
actuator.GetRuntimeLivenessIndicator().SetUnhealthy("shutdown")
}

func (m *MosnRuntime) initRuntime(o *runtimeOptions) error {
Expand Down Expand Up @@ -283,12 +278,6 @@ func (m *MosnRuntime) initConfigStores(configStores ...*configstores.StoreFactor
return err
}
m.configStores[name] = c
v := actuators.GetIndicatorWithName(name)
//Now don't force user implement actuator of components
if v != nil {
health.AddLivenessIndicator(name, v.LivenessIndicator)
health.AddReadinessIndicator(name, v.ReadinessIndicator)
}
}
return nil
}
Expand Down Expand Up @@ -383,12 +372,6 @@ func (m *MosnRuntime) initFiles(files ...*file.FileFactory) error {
return err
}
m.files[name] = c
v := actuators.GetIndicatorWithName(name)
//Now don't force user implement actuator of components
if v != nil {
health.AddLivenessIndicator(name, v.LivenessIndicator)
health.AddReadinessIndicator(name, v.ReadinessIndicator)
}
}
return nil
}
Expand Down